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

Baremetal UART TXD blocked due to HWFC regardless MACRO definition

Well, it is one of my explorations in NRF51822. I am working on a bare-metal UART demo, so far there are no output from TXD.

Configuration

  • MDK5 + STLINK/V2, with optional OpenOCD in Windows/Linux
  • nRF51822 breakout with pitch converter.
  • c:\nRF5_SDK_12.3.0\examples\peripheral\blinky\pca10028\blank\arm5_no_packs\blinky_pca10028.uprojx
  • c:\nRF5_SDK_12.3.0\examples\peripheral\uart\pca10028\blank\arm5_no_packs\uart_pca10028.uprojx

Since I found the silkscreen of converter is wrong, I used blinky demo to make sure the positions of P08/P09/P10/P11, which are used for RTS/TXD/CTS/RXD.

#define RX_PIN_NUMBER  11
#define TX_PIN_NUMBER  9
#define CTS_PIN_NUMBER 10
#define RTS_PIN_NUMBER 8
#define HWFC           false

Actually HWFC is disabled, since I don't wanna blocked by accident or hardware issue.

And I load the uart demo code, slightly changed the main loop, since its localtest are depending on RXD for TXD. I just want to make sure the TXD work first.

while (true)
{
uint8_t res;
    const char demo[] = "UUUUUUUUUU";
    for(int i=0; i<10; i++){
    res = app_uart_put(demo[i]);
}
}

The reason why I want to print out U, because U stands for 0x55, which is easy to identify on OSC to read out the baudrate.

However, there is nothing available from TXD, anyway.

I enabled Peripherals|UART in MDK debugger window. Then I noticed CONFIG = 0x00000001, which means HWFC is enabled.

Then I add a derivates as following:

#define RX_PIN_NUMBER  11
#define TX_PIN_NUMBER  9
#define CTS_PIN_NUMBER 10
#define RTS_PIN_NUMBER 8
#define HWFC           false
#warning "HWFC is false"	

Rebuild the source code, and HWFC is confirmed is false. But abviously, HWFC is enabled anyway.

Then I disable HWFC in CONFIG, OOPS, everything comes out from TXD !

OK, I can wire CTS/RTS to nRF, but it seems HWFC is enabled regardless the macro definitions anyway.

  • I found it.

    const app_uart_comm_params_t comm_params =
      {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          APP_UART_FLOW_CONTROL_ENABLED,
          false,
          UART_BAUDRATE_BAUDRATE_Baud115200
      };
    

    The struct variable enabled FLOW_CONTROL as true, while HWFC is useless. We have to disable it as following code.

    const app_uart_comm_params_t comm_params =
      {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          APP_UART_FLOW_CONTROL_DISABLED,//APP_UART_FLOW_CONTROL_ENABLED,
          false,
          UART_BAUDRATE_BAUDRATE_Baud115200
      };
    

    We can not replace it with HWFC, since in the stuct, it is a enum, not a macro.

    typedef struct
    {
        uint32_t                rx_pin_no;    /**< RX pin number. */
        uint32_t                tx_pin_no;    /**< TX pin number. */
        uint32_t                rts_pin_no;   /**< RTS pin number, only used if flow control is enabled. */
        uint32_t                cts_pin_no;   /**< CTS pin number, only used if flow control is enabled. */
        app_uart_flow_control_t flow_control; /**< Flow control setting, if flow control is used, the system will use low power UART mode, based on CTS signal. */
        bool                    use_parity;   /**< Even parity if TRUE, no parity if FALSE. */
        uint32_t                baud_rate;    /**< Baud rate configuration. */
    } app_uart_comm_params_t;
    
Related