9. Your First DA1469x Application – FreeRTOS_Retarget

9.1. Introduction

The following sections explain how the user can build, program and run a simple software application called Freertos_retarget on the ProDK development board using the SmartSnippets™ DA1469x SDK.

This application is a basis for creating your own applications with FreeRTOS support. It is a pre-defined project template called freertos_retarget which is located at <sdk_root_directory>\projects\dk_apps\templates.

The application is first described, then step by step instructions are given to build and run it.

9.2. Software Architecture

In order to be familiar with building and executing freertos_retarget project is better to run it in debug mode first. This is the easiest setup and does not need any Flash programming prior to executing the binary.

When the application starts running the first thing that is executed is the Reset_Handler, which is located in startup > startup_ARMCM0.s. This is followed by setting IRQ priorities and initializing variables.

Next, code execution continues with the main subroutine in file main.c. Here, the main routine creates the task SysInit and starts the RTOS scheduler. From now on the RTOS scheduler is running and it will start the first task which is SysInit.

The SysInit first initializes the clock and the low power clock and sets the clock dividers for AHB and APB buses. Then retarget is initialized which leads to initialization of the UART one peripheral. This includes setting up the fifo mode, dma, baudrate and enabling the communication power domain and the UART one peripheral.

Main routine continues with wakeup configuration. It sets xtal as the clock that is used in wake up and wake up mode to fast wake up.

Last thing done before SysInit task exits is to create another task prvTemplateTask which is the main application task running until the program gets stopped. The function code implementing this main task is as follows:

Code 1 The main task in SysInit() the prvTemplateTask()
static void prvTemplateTask( void *pvParameters )
{
    OS_TICK_TIME xNextWakeTime;
    static uint32_t test_counter=0;

    /* Initialise xNextWakeTime - this only needs to be done once. */
    xNextWakeTime = OS_GET_TICK_COUNT();

    for ( ;; ) {
        /* Place this task in the blocked state until it is time to run again.
        The block time is specified in ticks, the constant used converts ticks
        to ms.  While in the Blocked state this task will not consume any CPU
        time. */
        vTaskDelayUntil( &xNextWakeTime, mainCOUNTER_FREQUENCY_MS );
        test_counter++;

        if (test_counter % (1000 / OS_TICKS_2_MS(mainCOUNTER_FREQUENCY_MS)) == 0) {
            printf("#");
            fflush(stdout);
        }
    }
}

The software as provided in the SmartSnippets™ DA1469x SDK – once up and running - interacts with a host PC and sends the character ‘#’ via the serial UART interface every 1sec. This can be verified by setting up a terminal application (see Section 6.3.3 for the procedure, with the only difference that now the baud rate must be set to 115200).

9.3. Software Build

This section describes all the steps required to import, build and run this first project.

  1. In the SmartSnippets™ Studio welcome page click on the IDE icon from the Tools tab as shown in Figure 36.

../_images/snippets-welcome.jpg

Figure 36 SmartSnippets™ Studio welcome page

  1. Import the template project freertos_retarget from: <sdk_root_directory>\projects\dk_apps\templates\freertos_retarget into the selected workspace. Press the browse button highlighted in the Resources tab (reference 1) and navigate to the folder which contains the specific project as shown in Figure 37.

../_images/project-import.jpg

Figure 37 Project import

  1. In the same way import the python_scripts project from:

    <sdk_root_directory>\utilities\python_scripts

9.3.1. Build the project to run from RAM

The first build to try is a RAM build. This is the simplest one as there is no need to write the code to external QSPI Flash, the debugger will load it directly into RAM from where it can be run. This is not the normal method of development.

Build the project with the Build button and select Debug RAM configuration DA1469x-00-Debug-RAM as shown in Figure 38.

../_images/compile_ram1.jpg

Figure 38 Build FreeRTOS Retarget in Debug RAM configuration

Once the Debug RAM binary is built, the next step is to start the Debugger using Run > Debug Configurations > SmartBond “SmartSnippets DA1469x SDK via J-Link GDB Server > RAM as shown in Figure 39. As this is a RAM build the debugger will download the binary file via J-Link debugger into the system RAM. To enable this the system RAM is mapped to address 0 by the debugger.

../_images/RAM_debug1.jpg

Figure 39 Start Debug in RAM mode

9.3.2. Build the project to run from QSPI Flash

  1. This will be the normal development flow which has three steps: build the code, write it to QSPI Flash and then run it in the debugger.

  2. Build the project pressing the build button and select the Debug QSPI configuration DA1469x-00-Debug-QSPI as shown in Figure 40.

../_images/compile_qspi1.jpg

Figure 40 Build FreeRTOS Retarget in Debug QSPI configuration

The next step is to write the binary file to QSPI Flash. This is done by using a script selected from the External Tool button. In Figure 41 select program_qspi_jtag to program the QSPI Flash memory. (The external tools may not be populated at first use. To populate the External Tool button, press the External Tools Configuration… button to manually add the menu items.)

Alternatively, use Run > External Tools > program_qspi_jtag.

../_images/program_qspi1.jpg

Figure 41 Write FreeRTOS Retarget to QSPI Flash

Finally start the debugger using Run >Debug configurations > Smartbond “SmartSnippets DA1469x SDK” > QSPI and click ‘Debug’ as shown in Figure 42. This will start the debug perspective in SmartSnippets™ and load the symbols for the current project into the debugger.

../_images/QSPI_debug1.jpg

Figure 42 Start Debug in QSPI mode

9.4. Configure SmartSnippets™ to write to Flash

In order to write an image to Flash a configuration must be done first. Press in Figure 41 the program_qspi_config to access configuration menu. Alternatively, use Run > External Tools > program_qspi_config. This will open the window Figure 43 with a summary of the current QSPI configuration and supported device.

../_images/config_summary1.jpg

Figure 43 Configuration Summary

Press change to apply a new configuration. The first question has to do with the Product Id Select DA1469x-00 product family.

../_images/select_chip1.png

Figure 44 Select Product ID

Next you will be asked about the Flash configuration. For Pro DK of the DA1469x family select MX25U3235F.

../_images/select_flash1.png

Figure 45 Select Flash configuration

Finally, you will be asked to insert an address about Active FW image address and Update FW image address. Please keep in both entries the default value 0x2000.

9.5. Running the project in the Debugger

  1. Now that the binary has been loaded to memory (either RAM by debugger or QSPI by script) and the debugger has the symbols for the project loaded it is possible to run project in the debugger.

  2. Start execution of the FreeRTOS retarget project by selecting Resume inside the SmartSnippets™ Run menu or by hitting the play icon as indicated in Figure 46.

../_images/execute.jpg

Figure 46 Executing the FreeRTOS retarget project in SmartSnippets™

  1. The correct functionality of the FreeRTOS retarget project can be checked by noticing in the host PC that target sends the character ‘#’ via the serial UART interface every 1sec.