This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF9160 how to change baud rate of UART1 to 9600?

I'm successfully printing to the UART1 com port at baud rate 115200, but I have a peripheral I plan to connect that requires 9600.  What is the proper way to go about this?  Are there multiple places this needs to be changed or is there one config I can set?

I did try changing the config here:

zephyr\ext\hal\nordic\nrfx_config_nrf9160.h

but it didn't appear to work as I expected

Thank you!

  • Have you tried making an overlay file and adding something like the following?

    As far as I know, the UART baud rate is set here with the value found in current speed. This is placed in an overlay file to tweak values such as pinouts and values. Alternatively you could enter this into your .dts file for UART1 if this is a permanent feature of the device.

    &uart1 {
    	status = "ok";
      current-speed = <115200>;
      tx-pin = <22>;
      rx-pin = <23>;
      rts-pin = <30>;
      cts-pin = <31>;
    };

  • Thank you for the reply!

    adding this to my .dts file didn't work completely, but it did do something.  I no longer see output on the 115200 baud, but I don't see it on 9600 either.  I tried this both with and without the change in 

    zephyr\ext\hal\nordic\nrfx_config_nrf9160.h

    Any other ideas?  Also, I don't have a .overlay file in my current project (based off the aws_fota example).  I see other projects have a configuration directory that contains their .overlay files.  Is is as easy as mimicking those?  Or is that irrelevant since I've added it to my .dts anyway?

    Thanks!

  • If you add it to your .dts then it isn't necessary. .overlays are just files that modify the .dts layout with a new version based on what you put in the overlay.

    Did you remember to delete and rebuild your Secure Partition Manager (SPM) when you made the change, did you also add this change to both the secure .dts and the non-secure .dts?

    When you rebuilt your project with the change I mentioned, could you please post the file /path/to/ncs/nrf/samples/nrf9160/yourproject/build/zephyr/include/generated/generated_dts_board_unfixed.h. Specifically the bottom section that related to UART1.

    e.g.

    /* uart@9000 */
    #define DT_NORDIC_NRF_UARTE_1				1
    #define DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS	0x40009000
    #define DT_NORDIC_NRF_UARTE_40009000_CTS_PIN		31
    #define DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED	115200
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0		9
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY	1
    #define DT_NORDIC_NRF_UARTE_40009000_LABEL		"UART_1"
    #define DT_NORDIC_NRF_UARTE_40009000_RTS_PIN		30
    #define DT_NORDIC_NRF_UARTE_40009000_RX_PIN		23
    #define DT_NORDIC_NRF_UARTE_40009000_SIZE		4096
    #define DT_NORDIC_NRF_UARTE_40009000_TX_PIN		22
    #define DT_NORDIC_NRF_UARTE_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_1_CTS_PIN			DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_CURRENT_SPEED		DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_1_LABEL			DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_1_RTS_PIN			DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_RX_PIN			DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_1_TX_PIN			DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_UART_1_CTS_PIN		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_CURRENT_SPEED	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_UART_1_LABEL		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_UART_1_RTS_PIN		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_RX_PIN		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_UART_1_TX_PIN		DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define UART_1_BASE_ADDRESS __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define UART_1_CTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define UART_1_CURRENT_SPEED __DEPRECATED_MACRO 	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define UART_1_IRQ __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define UART_1_IRQ_PRIORITY __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define UART_1_LABEL __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define UART_1_RTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define UART_1_RX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define UART_1_SIZE __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define UART_1_TX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_TX_PIN

  • I made the change to both:

    ncs/zephyr/boards/arm/nrf9160_pca10090/nrf9160_pca10090ns.dts 

    and 

    ncs/zephyr/boards/arm/nrf9160_pca10090/nrf9160_pca10090.dts 

    and they now look like this:

    / {
    	chosen {
    		zephyr,flash = &flash0;
    		zephyr,sram = &sram0_ns;
    		zephyr,code-partition = &slot0_ns_partition;
    	};
    };
    
    &uart1 {
      status = "ok";
      current-speed = <9600>;
      tx-pin = <22>;
      rx-pin = <23>;
      rts-pin = <30>;
      cts-pin = <31>;
    };

    I'm completely removing everything in the build folder on each new build, including the spm folder.

    My project isn't quite at the path you mentioned, but here is the file at:

    /ncs/nrf/applications/mqtt/build/zephyr/include/generated/generated_dts_board_unfixed.h

    /* uart@9000 */
    #define DT_NORDIC_NRF_UARTE_1				1
    #define DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS	0x40009000
    #define DT_NORDIC_NRF_UARTE_40009000_CTS_PIN		31
    #define DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED	9600
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0		9
    #define DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY	1
    #define DT_NORDIC_NRF_UARTE_40009000_LABEL		"UART_1"
    #define DT_NORDIC_NRF_UARTE_40009000_RTS_PIN		30
    #define DT_NORDIC_NRF_UARTE_40009000_RX_PIN		23
    #define DT_NORDIC_NRF_UARTE_40009000_SIZE		4096
    #define DT_NORDIC_NRF_UARTE_40009000_TX_PIN		22
    #define DT_NORDIC_NRF_UARTE_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_1_CTS_PIN			DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_CURRENT_SPEED		DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_1_IRQ_0_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_1_LABEL			DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_1_RTS_PIN			DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_1_RX_PIN			DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_1_TX_PIN			DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_BASE_ADDRESS		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define DT_NORDIC_NRF_UARTE_UART_1_CTS_PIN		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_CURRENT_SPEED	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define DT_NORDIC_NRF_UARTE_UART_1_IRQ_PRIORITY		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define DT_NORDIC_NRF_UARTE_UART_1_LABEL		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define DT_NORDIC_NRF_UARTE_UART_1_RTS_PIN		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_RX_PIN		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define DT_NORDIC_NRF_UARTE_UART_1_SIZE			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define DT_NORDIC_NRF_UARTE_UART_1_TX_PIN		DT_NORDIC_NRF_UARTE_40009000_TX_PIN
    #define UART_1_BASE_ADDRESS __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_BASE_ADDRESS
    #define UART_1_CTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_CTS_PIN
    #define UART_1_CURRENT_SPEED __DEPRECATED_MACRO 	DT_NORDIC_NRF_UARTE_40009000_CURRENT_SPEED
    #define UART_1_IRQ __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_IRQ_0
    #define UART_1_IRQ_PRIORITY __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_IRQ_0_PRIORITY
    #define UART_1_LABEL __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_LABEL
    #define UART_1_RTS_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RTS_PIN
    #define UART_1_RX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_RX_PIN
    #define UART_1_SIZE __DEPRECATED_MACRO 			DT_NORDIC_NRF_UARTE_40009000_SIZE
    #define UART_1_TX_PIN __DEPRECATED_MACRO 		DT_NORDIC_NRF_UARTE_40009000_TX_PIN

    I'll also mention that I'm using 

    screen /dev/ttyACM2 9600

    and was previously using

    screen /dev/ttyACM2 115200

    Thanks so much for the help!

  • Ok that's strange, your build file clearly states that the speed of UART1 is 9600. I confirmed this with my own custom PCB by changing my overlays to 9600 and my UART0 now runs at 9600 Baud. It should be that simple. My analyser can't detect the baud rate now at 115200 until I go down to 9600 (and it even prints slower Sweat smile)

    Try this, reset the .dts files and add two overlay files, one to spm named nrf9160_pca10090.overlay and the other in your project folder (at the same level as prj.conf) named nrf9160_pca10090ns.overlay.

    In both place this, but tweak it to reflect your UARTs:

    /* Needed to get NRF_UARTE2 and NRF_PWMn defined. */
    &uart0 {
      status = "ok";
    };
    
    &uart1 {
      status = "ok";
      current-speed = <9600>;
      tx-pin = <22>;
      rx-pin = <23>;
      rts-pin = <30>;
      cts-pin = <31>;
    };
    
    &uart2 {
    	status = "ok";
    };
    
    &pwm1 {
    	status = "ok";
    };
    
    &pwm2 {
    	status = "ok";
    };
    
    &pwm3 {
    	status = "ok";
    };
    

    NOTE: the above will clear UART0 unless you define it in the same manner as UART1, leaving anything as 'status= "ok" ' will clear it's configuration.

    Then rebuild both spm and your project folder, remembering to build spm with the secure board and the project with the non-secure board (spm -> -DBOARD=nrf9160_pca10090 | project -> -DBOARD=nrf9160_pca10090ns).

Related