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

UART NO_MEMORY error

My UART is going into a NO_MEMORY error after trying to transmit a single byte. When i try and put the second letter on the transmit buffer, it gives err_code = 4. I tried to use the example but when i compiled and uploaded the example project it just doesn't work either. Not sure if because i am working with a custom board. On the debugger i can see it is cycling through the string as it should as i see it transmit 'H' and the next letter i try and transmit is 'e'. but it goes into error mode.

Also as a side note I am trying to update the fds sample file which also has a CLI implementation. I am trying to remove that to see if it works. There really needs to be a document of necessary imports into the sdk_config.h file of what you need for each aspect. Maybe there is and I haven't found it. Like you want to use UART then you need to include these declarations for the libraries to work.

#define     RX_BUF_SIZE     		128   /**< Size of desired RX buffer, must be a power of 2 or ZERO (No FIFO). */
#define     TX_BUF_SIZE     		128   /**< Size of desired TX buffer, must be a power of 2 or ZERO (No FIFO) */

const app_uart_comm_params_t comm_params =
{
    .rx_pin_no  = RX_PIN,       //RX_PIN = P0.06
    .tx_pin_no  = TX_PIN,       //TX_PIN = P0.08
    .rts_pin_no = -1,
    .cts_pin_no = -1,
    //Below values are defined in ser_config.h common for application and connectivity
    .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
    .use_parity   = false,
    .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud9600
};

void uart_init(void){
    uint32_t err_code;
    uid[0] = (char)0;

    nrf_gpio_cfg_input(RX_PIN, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_output(TX_PIN);

    APP_UART_FIFO_INIT(&comm_params, 
                        RX_BUF_SIZE,
                        TX_BUF_SIZE,
                        uart_evt_callback,
                        UART_IRQ_PRIORITY,
                        err_code);

    APP_ERROR_CHECK(err_code);
}

void uart_putstring(const uint8_t * str)
{
    uint32_t err_code;
    
    uint8_t len = strlen((char *) str);

    for (int i = 0; i < len; i++)
    {
        err_code = app_uart_put(str[i]);
        APP_ERROR_CHECK(err_code);
        nrf_delay_us(1250);
    }
}

void uart_test(void){
    uart_putstring("Hello World");
}

int main(void){
    uart_init();
    
    while(true){
        uart_test();
        nrf_delay_ms(1000);
    }
}

  • The app_uart_put() function only sends one byte at the time, so you should wait for the last transfer to complete before you send the next byte. Take a look at e.g. the ble app uart example (nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral\ble_app_uart) and use the same approach when sending data:

    for (int i = 0; i < len; i++)
    {
        do
        {
            err_code = app_uart_put(str[i]);
            if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
            {
                NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                APP_ERROR_CHECK(err_code);
            }
        } while (err_code == NRF_ERROR_BUSY);
    }

    Best regards,

    Simon

Related