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

 

 

 

Parents
  • 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

Reply Children
  • Thanks for your reply.

    In debug mode, it's work. It will be stuck in nrf_queue_reset() of nrf_serial_init() if switch power key on nRF52840 DK.

    run "build and run" command to download *.elf successful. and the log shows 

    "Programming 0.0 KB of .nrf_queue addresses 20005860 — 20005887" 

    and I erase mem and flash hex file by nRF Connect programmer, it shows as below.

    is nrf_queue make stuck when I switch power key on DK? 

  • Tim_lai said:
    "Programming 0.0 KB of .nrf_queue addresses 20005860 — 20005887" 

     This is not an error, programming 27 bytes of code cannot be showed in a single precision number after decimal. That is it must 0.02KB of code, but since it is only showing single precision after the decimal , it is showing 0.0. That does not mean that it is not programming anything.

    The programming with nRF connect is interesting. I have to try that one and will come back to you

  • before I add 

     <ProgramSection alignment="4" keep="Yes" load="Yes" name=".nrf_queue" inputsections="*(.nrf_queue*)" address_symbol="__start_nrf_queue" end_symbol="__stop_nrf_queue" />

    to flash_placement.xml to fix "region `UNPLACED_SECTIONS' overflowed by xx bytes"

    but I put it into wrong place as below

     <!DOCTYPE Linker_Placement_File>
    <Root name="Flash Section Placement">
      <MemorySegment name="FLASH" start="$(FLASH_PH_START)" size="$(FLASH_PH_SIZE)"> 
      ...
       <ProgramSection alignment="4" size="__HEAPSIZE__" load="No" name=".heap" />
        <ProgramSection alignment="8" size="__STACKSIZE__" load="No" place_from_segment_end="Yes" name=".stack"  address_symbol="__StackLimit" end_symbol="__StackTop"/>
        <ProgramSection alignment="8" size="__STACKSIZE_PROCESS__" load="No" name=".stack_process" />
        <ProgramSection alignment="4" keep="Yes" load="Yes" name=".nrf_queue" inputsections="*(.nrf_queue*)" address_symbol="__start_nrf_queue" end_symbol="__stop_nrf_queue" />
      </MemorySegment>
    </Root>

    Now I put it into the right place,

    Its solve my first issue

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

Related