NRF522832 FreeRTOS can't start.

Hi everyone:

I developed an application based on freertos, but when I download it, I found it can not start, but when I use the RTT to connect my device, It worked.

The commend is

nrfutil settings generate --family NRF52 --application app.hex --application-version 0 --bootloader-version 0 --bl-settings-version 2 settings.hex
nrfjprog --eraseall -f NRF52
nrfjprog --program mbr_nrf52_2.4.1_mbr.hex --verify -f NRF52
nrfjprog --program nrf52832_xxaa_mbr.hex --verify -f NRF52
nrfjprog --program app.hex --verify -f NRF52
nrfjprog --program settings.hex --verify -f NRF52
nrfjprog --reset -f NRF52

SDK is 17.1.0.

Best regards,

Lurn.

Parents
  • Hello,

    I don't know what you have programmed using these commands. Did you program two MBRs? 

    What HW are you running on? Is it a DK or a custom board?

    Best regards,

    Edvin

  • Sorry, the command is following, and I also try use keil to download.

    nrfjprog --eraseall -f NRF52
    nrfjprog --program mbr_nrf52_2.4.1_mbr.hex --verify -f NRF52
    nrfjprog --program app.hex --verify -f NRF52
    nrfjprog --reset -f NRF52

    After building, I downloaded flash_ Mbr first, and then download the application.

    The HW is custom board.

    BR

    Lurn

  • Ok, can you please send me a strip down version, or at least an application that replicates the issue that you are seeing?  You can use one of the examples in the SDK as a starting point. 

    Ok, but it might take some time. I can share a part of my code now, but application will take some time.

    It looks like a bit of a mess, because I delete some another tasks things.

    8823735.sdk_config.h

    /**
     * Copyright (c) 2015 - 2021, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup blinky_example_main main.c
     * @{
     * @ingroup blinky_example_freertos
     *
     * @brief Blinky FreeRTOS Example Application main file.
     *
     * This file contains the source code for a sample application using FreeRTOS to blink LEDs.
     *
     */
    
    #include <stdbool.h>
    #include <stdint.h>
    
    #include "FreeRTOS.h"
    #include "task.h"
    #include "timers.h"
    #include "bsp.h"
    #include "nordic_common.h"
    #include "nrf_drv_clock.h"
    #include "sdk_errors.h"
    #include "app_error.h"
    #include "thread.h"
    #include "nrf_power.h"
    #include "nrf_pwr_mgmt.h"
    #include "nrf_delay.h"
    
    
    #if LEDS_NUMBER <= 2
    #error "Board is not equipped with enough amount of LEDs"
    #endif
    
    #define TASK_DELAY        200           /**< Task delay. Delays a LED0 task for 200 ms */
    #define TIMER_PERIOD      1000          /**< Timer period. LED1 timer will expire after 1000 ms */
    
    #define BOOTLOADER_DFU_GPREGRET_MASK            (0xF8)      /**< Mask for GPGPREGRET bits used for the magic pattern written to GPREGRET register to signal between main app and DFU. */
    #define BOOTLOADER_DFU_GPREGRET                 (0xB0)      /**< Magic pattern written to GPREGRET register to signal between main app and DFU. The 3 lower bits are assumed to be used for signalling purposes.*/
    #define BOOTLOADER_DFU_START_BIT_MASK           (0x01)      /**< Bit mask to signal from main application to enter DFU mode using a buttonless service. */
    #define BOOTLOADER_DFU_START    (BOOTLOADER_DFU_GPREGRET | BOOTLOADER_DFU_START_BIT_MASK)      /**< Magic number to signal that bootloader should enter DFU mode because of signal from Buttonless DFU in main app.*/
    
    
    static void clocks_start( void )
    {
        NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_HFCLKSTART = 1;
    
        while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
    }
    
    #if 1
    static void enter_dfu(void)
    {
        uint8_t old_gpregret = nrf_power_gpregret_get();
        SEGGER_RTT_printf(0, "get the old_gpregret = %d", old_gpregret);
        uint8_t new_gpregret = old_gpregret & BOOTLOADER_DFU_START;
        SEGGER_RTT_printf(0, "new_gpregret = %d", new_gpregret);
        uint8_t temp = 0;
    
        nrf_power_gpregret_set(BOOTLOADER_DFU_START);
        while((temp & BOOTLOADER_DFU_START) != BOOTLOADER_DFU_START)
        {
            temp = nrf_power_gpregret_get();
            SEGGER_RTT_printf(0, "temp = %d", temp);
        }
        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);
        SEGGER_RTT_printf(0, "nrf_pwr_mgmt_shutdown NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU and system reset.");
        NVIC_SystemReset();
    }
    #endif
    
    int main(void)
    {
        ret_code_t err_code;
        SEGGER_RTT_printf(0, "Start application.");
        /* Initialize clock driver for better time accuracy in FREERTOS */
        err_code = nrf_drv_clock_init();
        APP_ERROR_CHECK(err_code);
        clocks_start();
        /* Configure LED-pins as outputs */
        bsp_board_init(BSP_INIT_LEDS);
    
        // enter_dfu();
    
        thread_main();
    
        /* Activate deep sleep mode */
        SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
    
        /* Start FreeRTOS scheduler. */
        vTaskStartScheduler();
    
        while (true)
        {
            /* FreeRTOS should not be here... FreeRTOS goes back to the start of stack
             * in vTaskStartScheduler function. */
        }
    }
    
    /**
     *@}
     **/
    
    /* FreeRTOS hearder */
    #include "thread.h"
    #include "uart.h"
    #include "nrf_delay.h"
    
    /**************************** task handler ********************************/
    /* 
     * create task handler
     * if operate self , value can be NULL。
     * 
     */
    // static TaskHandle_t AppTaskCreate_Handle;
    
    TaskHandle_t RunTimeStats_Task_Handle;
    TaskHandle_t Uart_Task_Handle;
    
    /********************************** core handler *********************************/
    /*
     * sem,queue,event,timer...
     * 
     */
    
    
    /******************************* Global variable ************************************/
    /*
     * Global variable
     */
    
    /******************************* Macro Define ***************************************/
    /*
     * Macro Define
     */
    /*
    ****************************************************************************
    *                              task name
    *****************************************************************************
    */
    #define RunTimeStatsTaskName                             "RunTimeStatsTask"
    #define Uart_TaskName                                    "Uart_Task"
    
    /*
    ****************************************************************************
    *                               size
    *****************************************************************************
    */
    #define RunTimeStatsTaskSize                                      ( 128 )
    #define Uart_TaskSize                                             ( 1024 )
    
    /*
    ****************************************************************************
    *                               prio
    *****************************************************************************
    */
    /*
    MAX prio in FreeRTOS
    
    #define configMAX_PRIORITIES                                                      ( 7 )
    */
    
    #define RunTimeStatsTaskPrio                                      ( 3 )
    #define Uart_TaskPrio                                             ( 5 )
    
    /*
    *****************************************************************************
    *                              handler
    *****************************************************************************
    */
    
    extern TaskHandle_t RunTimeStats_Task_Handle;                        // Run state
    extern TaskHandle_t Uart_Task_Handle;                                // Uart
    
    /*
    *************************************************************************
    *                             Funtion
    *************************************************************************
    
     /**********************************************************************
      * @ Fun  : RunTimeStatsTask
      * @ param   :   
      * @ retval  : null
      ********************************************************************/
    
    void RunTimeStatsTask(void)
    {
        while(1)
        {
            int val;
            SEGGER_RTT_printf(0, "TaskName\t\t\t\tPrio\t\t\t\tStackSize");
            val = uxTaskGetStackHighWaterMark(Uart_Task_Handle);
            SEGGER_RTT_printf(0, "%s\t\t\t\t%d\t\t\t\t%d", Uart_TaskName, Uart_TaskPrio, val);
            vTaskDelay(10000);
        }
    }
    
    /**********************************************************************
      * @ Fun  : Uart_task test
      * @ param   :   
      * @ retval  : null
      ********************************************************************/
    void Uart_Task(void* parameter)
    {
        uart_init();
    
        while(1)
        {
            uart_main();
            vTaskDelay(2);
        }
    }
    
    /*****************************************************************
      * @brief  HardWare_init
      * @param  null
      * @retval null
      * @note   init all hardware
      ****************************************************************/
    void HardWare_init(void)
    {
    
    }
    
    /*****************************************************************
      * @brief  main
      * @param  null
      * @retval null
      * @note   thread manager main
      ****************************************************************/
    int thread_main(void)
    {
        BaseType_t xReturn = pdPASS;
        int size = 0;
    
        HardWare_init();
    
        taskENTER_CRITICAL();
    
        xReturn = xTaskCreate((TaskFunction_t )Uart_Task,                 // enter fun
                            (const char*    )Uart_TaskName,               // name
                            (uint16_t       )Uart_TaskSize,               // size
                            (void*          )NULL,                        // enter param
                            (UBaseType_t    )Uart_TaskPrio,               // prio
                            (TaskHandle_t*  )&Uart_Task_Handle);          // task handle 
    
        SEGGER_RTT_printf(0, " xTaskCreate Uart_Task = %d\r\n", xReturn);
        if(pdPASS == xReturn)
            SEGGER_RTT_printf(0, "Uart_Task Create Done!\r\n");
    
        size = xPortGetFreeHeapSize();
        SEGGER_RTT_printf(0, "heap size = %d\r\n", size);
    
        taskEXIT_CRITICAL();
        if(pdPASS != xReturn)
            return -1;
        return pdPASS;
    }
    
    
    /**
     * Copyright (c) 2014 - 2021, Nordic Semiconductor ASA
     *
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without modification,
     * are permitted provided that the following conditions are met:
     *
     * 1. Redistributions of source code must retain the above copyright notice, this
     *    list of conditions and the following disclaimer.
     *
     * 2. Redistributions in binary form, except as embedded into a Nordic
     *    Semiconductor ASA integrated circuit in a product or a software update for
     *    such product, must reproduce the above copyright notice, this list of
     *    conditions and the following disclaimer in the documentation and/or other
     *    materials provided with the distribution.
     *
     * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
     *    contributors may be used to endorse or promote products derived from this
     *    software without specific prior written permission.
     *
     * 4. This software, with or without modification, must only be used with a
     *    Nordic Semiconductor ASA integrated circuit.
     *
     * 5. Any software provided in binary form under this license must not be reverse
     *    engineered, decompiled, modified and/or disassembled.
     *
     * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
     * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
     * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     */
    /** @file
     * @defgroup uart_example_main main.c
     * @{
     * @ingroup uart_example
     * @brief UART Example Application main file.
     *
     * This file contains the source code for a sample application using UART.
     *
     */
    
    #include "thread.h"
    
    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf.h"
    #include "bsp.h"
    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif
    #include "uart.h"
    #include "nrf_drv_clock.h"
    #include "esb.h"
    #include "pairing_cmd.h"
    
    
    #define UART_PRINTF( ... )  SEGGER_RTT_printf(0, __VA_ARGS__)
    
    
    uint32_t app_timer_cnt_get(void)
    {
        return xTaskGetTickCount();
    }
    
    uint32_t app_timer_cnt_diff_compute(uint32_t ticks_to,
                                        uint32_t ticks_from)
    {
        return ((ticks_to - ticks_from) & RTC_COUNTER_COUNTER_Msk);
    }
    
    uint8_t data_array[UART_RX_BUF_SIZE];
    static uint8_t index = 0;
    static uint8_t flag = 0;
    
    #include "nrf_libuarte_async.h"
    #include <bsp.h>
    #include "nrf_queue.h"
    
    NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);
    
    static uint8_t text[] = "UART example started.\r\n Loopback:\r\n";
    static uint8_t text_size = sizeof(text);
    static volatile bool m_loopback_phase;
    
    typedef struct {
        uint8_t * p_data;
        uint32_t length;
    } buffer_t;
    
    NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);
    
    void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
    {
        nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
        ret_code_t ret;
    
        switch (p_evt->type)
        {
            case NRF_LIBUARTE_ASYNC_EVT_ERROR:
                bsp_board_led_invert(0);
                break;
            case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                ret = nrf_libuarte_async_tx(p_libuarte,p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                buffer_t buf = {
                    .p_data = p_evt->data.rxtx.p_data,
                    .length = p_evt->data.rxtx.length,
                };
                if (ret == NRF_ERROR_BUSY)
                {
    
                    ret = nrf_queue_push(&m_buf_queue, &buf);
                    APP_ERROR_CHECK(ret);
                }
                else
                {
                    APP_ERROR_CHECK(ret);
                }
                m_loopback_phase = true;
                uart_cmd_set(buf.p_data, buf.length);
                // memcpy(data_array, buf.p_data, buf.length);
                // flag = 1;
                break;
            case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                if (m_loopback_phase)
                {
                    nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                    if (!nrf_queue_is_empty(&m_buf_queue))
                    {
                        buffer_t buf;
                        ret = nrf_queue_pop(&m_buf_queue, &buf);
                        APP_ERROR_CHECK(ret);
                        UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                    }
                }
                break;
            default:
                break;
        }
    }
    
    void uart_init()
    {
        uint8_t err_code;
        nrf_libuarte_async_config_t nrf_libuarte_async_config = {
                .tx_pin     = TX_PIN_NUMBER,
                .rx_pin     = RX_PIN_NUMBER,
                .baudrate   = NRF_UARTE_BAUDRATE_921600,
                .parity     = NRF_UARTE_PARITY_EXCLUDED,
                .hwfc       = NRF_UARTE_HWFC_DISABLED,
                .timeout_us = 0,
                .int_prio   = APP_IRQ_PRIORITY_HIGH,
                .pullup_rx  = 1
        };
    
        err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
        UART_PRINTF("nrf_libuarte_async_init err_code = %d.", err_code);
        APP_ERROR_CHECK(err_code);
    
        nrf_libuarte_async_enable(&libuarte);
    
        // err_code = nrf_libuarte_async_tx(&libuarte, text, text_size);
        // UART_PRINTF("nrf_libuarte_async_tx err_code = %d.", err_code);
        // APP_ERROR_CHECK(err_code);
    }
    
    #endif
    
    /**
     * @brief Function for main application entry.
     */
    void uart_main(void)
    {
    	#if 0
        while (flag)
        {
            UART_PRINTF("data_array = %s", data_array);
            memset(&data_array, 0, UART_RX_BUF_SIZE);
            flag = 0;
        }
    	#endif
    }
    
    /** @} */
    

    earch your application's sdk_config.h for "LF_SRC".

    yes, they all set to 1, after set it to 0, threads aren't started too.

    ..RC_CTIV should be set to 16
    ...RC_TEMP_CTIV should be set to 2
    ...CLOCK_LF_ACCURACY should be set to 1

    Sorry, I didn't have the occurrences like you said...

    BR,

    Lurn

  • you can see the application in examples/peripheral/blinky_freertos/pca10040/blank/arm5_no_packs.

    I removed a lot of things that were not related to UART. So, maybe it looks like a bit of a mess.
    BR,
    Lurn
  • Please zip a project that I can unzip that will compile where I can recreate the issue.

  • EDIT:

    DON'T change the port.c file. Only change the RAM start and RAM size:

    BR,

    Edvin

Reply Children
Related