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!

Parents
  • 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).

Reply
  • 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).

Children
  • EDIT: I'm just gonna ask, when i posted that snippet of code at the start, did you change the RX and TX pins to reflect your board? I just noticed your output from your build folder has my pins 22 and 23 as TX and RX, is that your pins as well? This would explain why you are no longer seeing anything on UART1.

  • Sorry but I'm missing one thing..  I'm currently building my project with these commands:

    mkdir -p build
    rm -r build/*
      
    west build -b nrf9160_pca10090ns -d build && \
    nrfjprog --eraseall -f nrf91 && \
    nrfjprog --program build/zephyr/merged.hex --sectorerase -r -f nrf91 --verify

    Are you referring to the spm directory in the build folder?  Isn't that generated by west build command?  And rebuilding the spm directory would result in erasing the overlay file, correct?  

    Just in case, I went ahead and reverted the .dts, added the two overlay files, and rebuilt without cleaning the build directory at all.  It appears to be the same behavior and here is my 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 am referring to this when I refer to SPM

    https://github.com/NordicPlayground/fw-nrfconnect-nrf/tree/master/samples/nrf9160/spm

    This is your Secure Partition Manager. It must be rebuilt each time you alter the dts. When you build here, you are building for the secure part of flash. When you build in your projects, you are building for the non-secure region of flash and that's why both need overlays and their own dts files.

    Did you see my last message about making sure your UART pins are configured correctly in your files? Your TX and RX pins are the same as what I originally shared and it's unlikely that they were also your intended pins for UART1 Grinning

  • YES!! Nice catch!  The final solution is changing my .dts files at 

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

    and 

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

    to have this at the end:

    &uart1 {
      status = "ok";
      current-speed = <9600>;
      tx-pin = <1>;
      rx-pin = <0>;
      rts-pin = <14>;
      cts-pin = <15>;
    };

    You are amazing thanks again!!

  • Glad to hear you got it working. Happy coding! Smile

Related