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.
  • Hi Nugurr,

    I try to include app_timer_freertos.c instead of app_timer.c, and use RTC1.

    but when I call nrf_serial_read(): 

    int at_setting(char *cmd, uint32_t timeout)
    {
     // printf("cmd:%s\r\n", cmd);
        xSemaphoreTake( xMutex, portMAX_DELAY);
    
        ret_code_t ret;
        int cont = 0;
        char ac[256];
        char c;
        int value;
    
        memset(ac, 0, sizeof(ac));
        nrf_serial_write(&serial1_uarte, cmd, strlen(cmd), NULL, NRF_SERIAL_MAX_TIMEOUT);
        (void)nrf_serial_flush(&serial1_uarte, 0);
        do
        {   
          ret = nrf_serial_read(&serial1_uarte, &c, sizeof(c), NULL, timeout);
          if (ret != NRF_SUCCESS)
          {
            continue;
          }   
          ac[cont] = c;
          cont++;
        }while(ret == NRF_SUCCESS);
    
        xSemaphoreGive( xMutex );
    
        printf("%s\r\n", &ac);
    
       // xSemaphoreGive( xMutex );
    
        return value;
    }
    
    
    at_setting(_AT, 3000);
    i

    In nrf_serial_read() call timeout_setup() to create timer (call app_timer_create())

    but the app_timer_create() return errorcode = 8 (Invalid state, operation disallowed in this state)

    what kind of setting parameter I loss?

    Thanks.

Reply
  • Hi Nugurr,

    I try to include app_timer_freertos.c instead of app_timer.c, and use RTC1.

    but when I call nrf_serial_read(): 

    int at_setting(char *cmd, uint32_t timeout)
    {
     // printf("cmd:%s\r\n", cmd);
        xSemaphoreTake( xMutex, portMAX_DELAY);
    
        ret_code_t ret;
        int cont = 0;
        char ac[256];
        char c;
        int value;
    
        memset(ac, 0, sizeof(ac));
        nrf_serial_write(&serial1_uarte, cmd, strlen(cmd), NULL, NRF_SERIAL_MAX_TIMEOUT);
        (void)nrf_serial_flush(&serial1_uarte, 0);
        do
        {   
          ret = nrf_serial_read(&serial1_uarte, &c, sizeof(c), NULL, timeout);
          if (ret != NRF_SUCCESS)
          {
            continue;
          }   
          ac[cont] = c;
          cont++;
        }while(ret == NRF_SUCCESS);
    
        xSemaphoreGive( xMutex );
    
        printf("%s\r\n", &ac);
    
       // xSemaphoreGive( xMutex );
    
        return value;
    }
    
    
    at_setting(_AT, 3000);
    i

    In nrf_serial_read() call timeout_setup() to create timer (call app_timer_create())

    but the app_timer_create() return errorcode = 8 (Invalid state, operation disallowed in this state)

    what kind of setting parameter I loss?

    Thanks.

Children
Related