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

Using nrf_serial_write() to write to UARTE1 prints one character only then hard faults. UARTE0 works fine.

Hi,

We are trying to add serial comms to our project so that two boards can communicate with each other.

The code we have is as follows and works fine (prints to serial).

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart_drv_config,
        RX_PIN_NUMBER, TX_PIN_NUMBER,
        RTS_PIN_NUMBER, CTS_PIN_NUMBER,
        NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
        NRF_UART_BAUDRATE_115200,
        NRFX_UART_DEFAULT_CONFIG_IRQ_PRIORITY);

#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32

NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);

#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);

extern void vApplicationIdleHook(void);
NRF_SERIAL_CONFIG_DEF(serial_config, NRF_SERIAL_MODE_DMA,
        &serial_queues, &serial_buffs, event_callback, vApplicationIdleHook);

NRF_SERIAL_UART_DEF(serial_uart, 0);

void main() {
    ret = nrf_serial_init(&serial_uart, &m_uart_drv_config, &serial_config);
    APP_ERROR_CHECK(ret);
    
    const char hello_msg[] = "Hello, World!";
    ret = nrf_serial_write(&serial_uart, hello_msg, sizeof(hello_msg), NULL, 0);
    APP_ERROR_CHECK(ret);
}

However, we want to use UARTE1 so that UARTE0 can be used by the NRF_LOG functionality.
When we change UARTE0 to UARTE1 we only see one character printed and then we get a hard fault.
We change it on this line:

NRF_SERIAL_UART_DEF(serial_uart, 1);  // Changed from 0 to 1.

We change nothing else and we now get the hard fault. It's difficult to debug as there's no stack trace on the hard fault but it seems to be happening in the serial_tx() function called by the nrf_serial_write() function.

Thank you,

Callum

Parents Reply
  • I also assumed this but I would like to know what is causing the problem and how to fix it.

    I don't really understand why the sdk_config is different for every example so we have to frankenstein multiple configs together and pray that it works. It would be nice if Nordic could provide a global config that contains all the options and we can just turn them on or off as required.

    Using the RTT isn't really an option for us.

Children
Related