Can the UART RX/TX pins be also read as GPIO input pins

Greetings,

We are using the NCS for the development of a new product with a custom board based on the nRF52840 MCU.

First, we would like to use the Serial DFU feature to update the firmware over UART. I have found and will be implementing this guide for that. Please confirm that this is indeed correct.

Second we want to also use the same lines(RX/TX) as GPIOs (inputs) and read their status. What way would you suggest going about this? I have found this suggestion usefull (connecting the TX/RX lines to two other available GPIO pins to also read the level of the TX/RX lines) as we will not be using the UART interface and reading the same lines simultaneously.

What are your thoughts and suggestions on implementing this? Will connecting two other GPIO pins on the RX/TX lines cause issues to the UART even if we do not read the pins while the UART interface is in use?

Thank you very much and I look forward to hearing from you!

Best regards,

Stavros

Parents
  • Hi Stavros, 

    Regarding your questions: 

    1. Correct. If you want to implement DFU update in your application you can follow the guide and integrate SMPSVR into your application. Note that MCUBoot also support recovery mode that you can hold a button and enter DFU mode.(CONFIG_MCUBOOT_SERIAL=y)  This way you don't need to implement anything in the application. 

    2. Currently we have the possibility to dynamically configuration a pin with dynamic pinctrl. However, as far as I know it should only be used before the peripheral has been initialized ,as you can read here . I will need to double check with our team to get back to you. 
    Otherwise you can do what you planning, to connect the pin to two other GPIO pins and then use them as input. 

  • Hi Hung,

    I have an additional question regarding the flashing of the bootloader with no application.

    Is there a guide or sample that explains the usage and how to flash the MCUBoot without an application in serial recovery mode preferably using USB CDC UART in a custom board?

    Thank you.

    Regards

  • Hi Hung,

    Thank you very much for the fast response

    This meant sparkfun_sara_r4 board configuration has select UART_INTERRUPT_DRIVEN =n but UART_MCUMGR (MCUBOOT SMP)is selecting that symbol as y. I'm not very familiar with the sparkfun shield, but you may want to figure out how to change it to select UART_INTERRUPT_DRIVEN =y

    I am not using the sparkfun_sara_r4 , in my configuration I have selected our custom board and have succesfully build and flashed our custom application multiple times and something like this has nver been an issue.

    Is there some configuration option that selects this board or that implicitly affects these configuration options?

    All I did after loading the hello_world sample and flashing it (tested it successfully) on the nRF52840DK is I added a second build configuration using the nRF Connect Extension for VS Code as shown below:

    Is there some other configuration,file or something else I should be paying attention to?

    I have also tryied adding and removing the same items as the nRF52840DK .dts file in the 'chosen' section of the .dts file of our custom board as well as the same uart and button/led nodes and labels with no success either.

    chosen {
    		zephyr,console = &uart0;
    		zephyr,shell-uart = &uart0;
    		zephyr,uart-mcumgr = &uart0;
    		zephyr,bt-mon-uart = &uart0;
    		zephyr,bt-c2h-uart = &uart0;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    		zephyr,code-partition = &slot0_partition;
    	};

    I have also tryied to set UART_INTERRUPT_DRIVEN to 'y' with no success. I just get errors about other dependecies that are necessary for the SMPSVR to work (as shown in the guide).

    Am I missing something?

    As far as I know it should work together with the application UART. But I assume you don't plan to connect more than one UART peers to the nRF52 at the same time ? 

    Thank you for the feedback on this its very helpful! No I do not plan on connecting more than one UART at a time.

    Any feedback on the issues mentioned above would be very helpful!

    Thank you!

    Regards,

    Stavros

  • Hi Stavros, 
    Could you send us your board files and maybe your hello world project so we can test here. 

    You may think of making a dummy board files to test and send us that if you don' want to send your actual board files. 

  • Hi Hung,

    I have sent the hello_world project and included the board file (with dummy names) inside the project folder. Thank you very much!

    serial_dfu_hello_world.rar

  • Hi Stavros, 

    Do you have the custom_board.defconfig ? 

    I believe it's the root cause. I created my own board and got the same issue as you. 
    But if I copied the .defconfig of the DK board it worked for me. 
    It should look like this:

    # Copyright (c) 2022 Nordic Semiconductor ASA
    # SPDX-License-Identifier: Apache-2.0
    
    CONFIG_SOC_SERIES_NRF52X=y
    CONFIG_SOC_NRF52840_QIAA=y
    CONFIG_BOARD_MYBOARD2=y
    
    # Enable MPU
    CONFIG_ARM_MPU=y
    
    # Enable hardware stack protection
    CONFIG_HW_STACK_PROTECTION=y
    
    # Enable RTT
    CONFIG_USE_SEGGER_RTT=y
    
    # enable GPIO
    CONFIG_GPIO=y
    
    # enable uart driver
    CONFIG_SERIAL=y
    
    # enable console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    
    # additional board options
    CONFIG_GPIO_AS_PINRESET=y
    
    CONFIG_PINCTRL=y
    

    I would assume if you dont want to add the config in the board file, you can also add them in the proj.conf. 

  • Hi Hung,

    Thank you very much for your responses they were very helpful and I have the Bootloader & DFU process working for both Serial DFU and OTA using BLE!

    I have some followup questions because the documentation is kind of fragmented and convoluted not really citing a specific way of implementing the DFU process (some use SMP Server and others use DFU-Util).

    I have used the SMP Server method with a custom private key succesfully and my questions are:

    1. Are the FW images generated when building the application (with the SMP Server & MCUBoot
      CONFIG_BOOTLOADER_MCUBOOT) such as app_update.bin & dfu_application.zip encrypted or protected from reverse engineering ( can someone get the source code by using these ) or do I have to enable encryption for the MCUBoot to achieve this? If so how is this done?
    2. I have seen some tickets that use permanent configuration files for the MCUBoot without editing the MCUBoot source files by using a conf file in the child_image directory, but in my project there is no child_image directory thus I cant use a permanent conf file for MCUBoot because I want to add some conf options. How do I make it generate the child_image or alternatively how do I pass permanent configuration options to a child image such as MCUBoot using the VS Code (I have read all the guides and documentation on this and know it can be done by adding arguments to the the west build command but I dont want to do this everytime I want to build my application) Is there a way to specify them in VS Code so that when I press build in the nRF Connect Extension the build command includes those arguments
    3. Is there a better way to have a bootloader and perform DFU (serial & OTA) using something else other than the SMP Server and MCUMgr?
      Thank you very much for your time!
      Best regards,
      Stavros
Reply
  • Hi Hung,

    Thank you very much for your responses they were very helpful and I have the Bootloader & DFU process working for both Serial DFU and OTA using BLE!

    I have some followup questions because the documentation is kind of fragmented and convoluted not really citing a specific way of implementing the DFU process (some use SMP Server and others use DFU-Util).

    I have used the SMP Server method with a custom private key succesfully and my questions are:

    1. Are the FW images generated when building the application (with the SMP Server & MCUBoot
      CONFIG_BOOTLOADER_MCUBOOT) such as app_update.bin & dfu_application.zip encrypted or protected from reverse engineering ( can someone get the source code by using these ) or do I have to enable encryption for the MCUBoot to achieve this? If so how is this done?
    2. I have seen some tickets that use permanent configuration files for the MCUBoot without editing the MCUBoot source files by using a conf file in the child_image directory, but in my project there is no child_image directory thus I cant use a permanent conf file for MCUBoot because I want to add some conf options. How do I make it generate the child_image or alternatively how do I pass permanent configuration options to a child image such as MCUBoot using the VS Code (I have read all the guides and documentation on this and know it can be done by adding arguments to the the west build command but I dont want to do this everytime I want to build my application) Is there a way to specify them in VS Code so that when I press build in the nRF Connect Extension the build command includes those arguments
    3. Is there a better way to have a bootloader and perform DFU (serial & OTA) using something else other than the SMP Server and MCUMgr?
      Thank you very much for your time!
      Best regards,
      Stavros
Children
Related