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

blinky_freertos example adds Serial UART but nrf_serial_init() fail

SDK version: nRF5_SDK_15.3.0

Platform: nRF52840 DK

SoftDevice: s140

--

Hi All,

I use blinky_freertos example to add nrf_serial lib to send/receive AT command by UART port.

It's work when I press "build and run" on SES IDE, 

bit if I switch the power key on nRF52840DK, it's didn't work.

I try to trace to find that nrf_serial_init() call nrf_queue_reset() and the nrf_queue_reset() can not return.

I don't know why.

NRF_SERIAL_UART_DEF(serial1_uarte, 1);

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uarte1_drv_config,
                      ARDUINO_0_PIN, ARDUINO_1_PIN,
                      RTS_PIN_NUMBER, CTS_PIN_NUMBER,
                      NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
                      NRF_UART_BAUDRATE_115200,
                      UART_DEFAULT_CONFIG_IRQ_PRIORITY);

NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_DMA,
                      &serial1_queues, &serial1_buffs, NULL, sleep_handler);

static void uart_init(void)
{
    uint32_t err_code;
    const app_uart_comm_params_t comm_params =
    {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          UART_HWFC,
          false,
#if defined (UART_PRESENT)
          NRF_UART_BAUDRATE_115200
#else
          NRF_UARTE_BAUDRATE_115200
#endif
      };

      APP_UART_FIFO_INIT(&comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOWEST,
                         err_code);

    APP_ERROR_CHECK(err_code);
}


int main(void)
{
    ret_code_t err_code;
    ret_code_t ret;
    uart_init();

    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    ret = nrf_drv_power_init(NULL);
    APP_ERROR_CHECK(ret);
    

    nrf_drv_clock_lfclk_request(NULL);
    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

    bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
 
    ret = nrf_serial_init(&serial1_uarte, &m_uarte1_drv_config, &serial1_config);
    APP_ERROR_CHECK(ret);

    xMutex = xSemaphoreCreateMutex();
 
    at_setting(_AT, 3000);
    at_setting(_QICSGP, 200);
    at_setting(_QIACT_1, 2000);
    at_setting(_QIACT_IP, 2000);
 
    // MQTT AT Command
    at_setting(_QMTCFG_VER_0, 300);
    at_setting(_QMTOPEN_0, 5000);
    at_setting(_QMTCONN_0, 3000);
 
    if( xMutex != NULL )
    {
      UNUSED_VARIABLE(xTaskCreate(mqtt_sub_task_function, "SUB", configMINIMAL_STACK_SIZE + 200, NULL, 3, &mqtt_sub_task_handle));
      UNUSED_VARIABLE(xTaskCreate(mqtt_pub_task_function, "PUB", configMINIMAL_STACK_SIZE + 200, NULL, 3, &mqtt_pub_task_handle));

      // Activate deep sleep mode 
      SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
      vTaskStartScheduler();
    }
    while (true)
    {
        // FreeRTOS should not be here... FreeRTOS goes back to the start of stack
        // in vTaskStartScheduler function. 
    }
    
}

BTW, this example I use app_timer(RTC1) and FreeRTOS timer(RTC2)

Thanks.

Tim

 

 

 

  • Hi Tim,

     

    It's work when I press "build and run" on SES IDE, 

    bit if I switch the power key on nRF52840DK, it's didn't work.

    Do you mean, that it works normally in debugger mode, but does not work in non-debugger mode? If so, that is very strange and I would like to get your project to reproduce that myself here.

     

    I try to trace to find that nrf_serial_init() call nrf_queue_reset() and the nrf_queue_reset() can not return.

    How did you come to this conclusion without debugger connecting? using logs or any other method?

  • Thanks for your reply.

    I added GPIO/LED to nrf_serial_init() function,

    like that: When I turn off and then turn on nRF52840DK, the LED1 can not TURN ON

        if (p_serial->p_ctx->p_config->p_queues)
        {  
            nrf_queue_reset(p_serial->p_ctx->p_config->p_queues->p_txq);
            bsp_board_led_on(BSP_BOARD_LED_1);
            nrf_queue_reset(p_serial->p_ctx->p_config->p_queues->p_rxq);
        }

    Here's my code:

    https://drive.google.com/file/d/1mDeM1CD8Hyn1fCdzbWLjB2zhDWnP7Xl6/view

    Thank you

  • Hi Tim,

    1. in portmacro_cmsis.h, you should change #define portNRF_RTC_REG        to NRF_RTC2
    2. I do not understand you need to change the RTC instance here. If you project is dependent on using app_timers, then you could include app_timer_freertos.c instead of app_timer,c and use RTC1 instance for both portNRF_RTC_REG and xPortSysTickHandler. app_timer_freertos.c have same API like app_timer.c but instead of RTC1 it uses internal FreeRTOS timers.
  • Thanks for your reply.

    1. I have set the portNRF_RTC_REG to NRF_RTC2, but same situation.

    (I referred to the document below)

    diff --git a/examples/ble_peripheral/ble_app_hrs_freertos/config/ble_app_hrs_freertos_pca10040_s132/FreeRTOSConfig.h                    b/examples/ble_peripheral/ble_app_hrs_freertos/config/ble_app_hrs_freertos_pca10040_s132/FreeRTOSConfig.h
    index 20e948f..bd31017 100644
    --- a/examples/ble_peripheral/ble_app_hrs_freertos/config/ble_app_hrs_freertos_pca10040_s132/FreeRTOSConfig.h
    +++ b/examples/ble_peripheral/ble_app_hrs_freertos/config/ble_app_hrs_freertos_pca10040_s132/FreeRTOSConfig.h
    @@ -200,7 +200,7 @@ standard names - or at least those used in the unmodified vector table. */
         #define xPortSysTickHandler     SysTick_Handler
     #elif (configTICK_SOURCE == FREERTOS_USE_RTC)
         #define configSYSTICK_CLOCK_HZ  ( 32768UL )
    -    #define xPortSysTickHandler     RTC1_IRQHandler
    +    #define xPortSysTickHandler     RTC2_IRQHandler
     #else
         #error  Unsupported configTICK_SOURCE value
     #endif
    diff --git a/external/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h b/external/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h
    index 54a7ab8..237a6e7 100644
    --- a/external/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h
    +++ b/external/freertos/portable/CMSIS/nrf52/portmacro_cmsis.h
    @@ -118,9 +118,9 @@ typedef unsigned long UBaseType_t;
     #define portBYTE_ALIGNMENT          8
     
     /* RTC register */
    -#define portNRF_RTC_REG        NRF_RTC1
    +#define portNRF_RTC_REG        NRF_RTC2
     /* IRQn used by the selected RTC */
    -#define portNRF_RTC_IRQn       RTC1_IRQn
    +#define portNRF_RTC_IRQn       RTC2_IRQn
     /* Constants required to manipulate the NVIC. */
     #define portNRF_RTC_PRESCALER  ( (uint32_t) (ROUNDED_DIV(configSYSTICK_CLOCK_HZ, configTICK_RATE_HZ) - 1) )
     /* Maximum RTC ticks */
    

  • I did the exact same changes you did and the code is not stuck anywhere

Related