8. Your First DA1459x Application – FreeRTOS_Retarget

8.1. Introduction

The following sections explain how the user can build, program and run a simple software application called freertos_retarget on the DEVKIT-PRO development board using the Smartbond™ DA1459x SDK.

This application is basic 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.

Warning

The various projects in the Renesas SDK come default with the BLE security disabled. During the development phase of a project, this helps debugging a custom application and making a wireless connection to the device. For a production version Renesas is strongly advising to enable the security settings on the available BLE services. More information regarding the security can be found in the UM-B-160-DA1459x Software Platform Reference, Chapter 5.1.3.

8.2. Software Architecture

When the application starts running the first thing that is executed is the Reset_Handler, which is located in startup > DA1459x > GCC > exception_handlers.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 system clock and the low power clock and sets the clock dividers for AHB and APB buses. Then the retarget function is initialized which leads to initialization of the UART peripheral. This includes setting up the fifo mode, dma, baudrate and enabling the communication power domain and the UART peripheral.

Main routine continues with wakeup configuration. It sets xtal as the clock that is used in wake up and wake up mode to normal 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 OS_TASK_FUNCTION(prvTemplateTask, 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. */
                 xNextWakeTime += mainCOUNTER_FREQUENCY_MS;
                 OS_DELAY_UNTIL(xNextWakeTime);
                 test_counter++;

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

The software as provided in the Smartbond™ DA1459x SDK – once up and running - interacts with a host PC and sends the character ‘#’ via the serial UART interface every 1 sec. This can be verified by setting up a terminal application (see Section 6.3.3 for the procedure).

8.3. Software Build

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

8.3.1. Import a project

  1. On the e²studio Welcome page, click File (1.1) and then Import (1.2). (It’s possible that the Welcome page is not shown but instead the IDE (C/C++) is shown. Also click on File on the top bar).

'Import 1'

Figure 21 Initial Welcome Screen

  1. In the pop-up window double click General (2.1) and double click on Dialog SDK Project (2.2)

'Import 2'

Figure 22 Import SDK project

  1. In the pop-up window, click Browse and select your workspace directory.

'Import 3'

Figure 23 Select SDK Folder

  1. The final step is to select the preferred project(s) to import.

  2. Select the desired projects (freertos_retarget and python_scripts) by clicking on the respective tick boxes. Click Next.

Note

The python scripts are included to assist with configuring and erasing the eFLASH, programming custom data, programming secure boot etc.

'Import 4'

Figure 24 Project Selection

  1. Most certainly a pop-up window will appear to select a target device.

    1. Click on the 3 dots … (6.1) and

    2. Select DA14592 as target device (6.2).

    3. Be sure to select Toolchain version 7.

    4. Click OK and Finish in the respective windows.

'Import 5'

Figure 25 Target Selection

Note

At this stage, you can also choose the DA14594 as the target device.

Now you are ready to start working with the project.

8.3.2. Build the project to run from embedded Flash (eFLASH)

  1. This will be the normal development flow which has 2 steps: build the code and then run it in the debugger, which will automatically program it into eFLASH (if it’s not already programmed).

  2. Select the active build configuration by clicking Project > Build Configuration > Set Active and choose the DA14592-00-Debug-eFLASH… configuration.

../_images/build_configuration.png

Figure 26 Set Active configuration

  1. Build the project by pressing the Project > Build Project (CTRL+B) button as shown in Figure 27.

../_images/compile_eflash.png

Figure 27 Build FreeRTOS Retarget in Debug eFLASH configuration

  1. The next step is to write the binary file to the embedded flash (eFLASH). This is done by running the debugger. Click on the bug icon and choose Debug Configurations

../_images/debug_configuration.png

Figure 28 Debug Configurations

  1. The Debug Configurations window will pop-up. Choose the freertos_retarget DA14592-00-Debug-eFLASH and press Debug

../_images/debug_configuration_2.png

Figure 29 Freertos_retarget Debug Configuration

A window will pop-up indicating the progress of the eFLASH writing.

../_images/program_eflash.png

Figure 30 Program eFLASH

  1. The debug session will start and execution will pause at main. Hit F8 to resume. Open a serial terminal (115200, 8N1) and check if a # is printed every second.

Note

In some cases the execution will NOT pause at main, but in another function. In this case, please stop the debugger (Ctrl+F2), press the reset button on the DA1459x daughterboard and restart the debugger.