Personal tools

Difference between revisions of "How to create and run the first FreeRTOS application on the VisionSOM-RT"

From SomLabs Wiki

Jump to: navigation, search
(Software)
(Importing project)
(14 intermediate revisions by the same user not shown)
Line 22: Line 22:
 
*Any terminal application, for example [https://www.compuphase.com/software_termite.htm Termite]
 
*Any terminal application, for example [https://www.compuphase.com/software_termite.htm Termite]
  
*The MCUXpresso comes with the Segger drivers, however on some systems a driver update may be required: [https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack]
+
*The MCUXpresso comes with the SEGGER drivers, however on some systems a driver update may be required: [https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack https://www.segger.com/downloads/jlink#J-LinkSoftwareAndDocumentationPack]
  
*SDK – the SDK needs to be generated for the i.MX RT1052 microcontroller and should contain the FreeRTOS system. More information: [https://mcuxpresso.nxp.com/en/welcome https://mcuxpresso.nxp.com/en/welcome https://mcuxpresso.nxp.com/en/welcome https://mcuxpresso.nxp.com/en/welcome]
+
*SDK – the SDK needs to be generated for the i.MX RT1052 microcontroller and should contain the FreeRTOS system. More information: [https://mcuxpresso.nxp.com/en/welcome https://mcuxpresso.nxp.com/en/welcome]
  
 
== Importing the SDK ==
 
== Importing the SDK ==
Line 30: Line 30:
 
The created SDK needs to be imported to the MCUXpresso IDE. We can do it by selecting the import archive option in the Installed SDKs window, or by simple drag-and drop the archive file to this window.
 
The created SDK needs to be imported to the MCUXpresso IDE. We can do it by selecting the import archive option in the Installed SDKs window, or by simple drag-and drop the archive file to this window.
  
PIC sdk1
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_sdk1.png|center|800px]]
  
PIC sdk2
 
  
PIC sdk3
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_sdk2.png|center|800px]]
 +
 
 +
 
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_sdk3.png|center|800px]]
  
 
== Generating a new project ==
 
== Generating a new project ==
Line 41: Line 43:
  
  
PIC project1
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_project1.png|center|800px]]
 +
 
  
 
The project appropriate type is the New C/C++ Project.  
 
The project appropriate type is the New C/C++ Project.  
  
  
PIC project2
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_project2.png|center|400px]]
  
  
Line 52: Line 55:
  
  
PIC project3
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_project3.png|center|800px]]
  
  
 
In the next window we can set the name of the project, select the device package and the required software components and drivers. The project requires the FreeRTOS system and the following drivers:
 
In the next window we can set the name of the project, select the device package and the required software components and drivers. The project requires the FreeRTOS system and the following drivers:
  
 
+
*clock
clock
+
*common
 
+
*gpio
common
+
*iomuxc
 
+
*lpuart
gpio
+
*xip-board
 
+
*xip-device
iomuxc
 
 
 
lpuart
 
 
 
xip-board
 
 
 
xip-device
 
 
 
 
 
  
  
PIC project4
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_project4.png|center|800px]]
  
  
Line 81: Line 75:
  
  
PIC project5
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_project5.png|center|800px]]
  
  
After this step the project files should be created, but before we can compile it two more steps are required for proper QSPI Flash comfiguration. First of all we need to update the sources in the xip directory in order to support the QSPI flash. The updated version for this memory can be found on the NXP Community site in the QSPI_xip.zip archive.
+
After this step the project files should be created, but before we can compile it two more steps are required for proper QSPI Flash configuration. First of all we need to update the sources in the xip directory in order to support the QSPI flash. The updated version for this memory can be found on the NXP Community site in the QSPI_xip.zip archive.
  
  
Line 103: Line 97:
  
  
PIC properties1
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_properties1.png|center|800px]]
 +
 
  
PIC properties2
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_properties2.png|center|500px]]
  
  
Line 111: Line 106:
  
  
PIC build1
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_build1.png|center|800px]]
 
 
  
 
== Configuring SEGGER tools ==
 
== Configuring SEGGER tools ==
  
By default the installed SEGGER drivers support the external HyperFlash memories. In order to program the on-board QSPI Flash, the configuration files should be modified. The changes should be done in the JlinkDevices.xml file which can be found in the directories:
+
By default the installed SEGGER drivers support the external HyperFlash memories. In order to program the on-board QSPI Flash, the configuration files should be modified. The changes should be done in the ''JlinkDevices.xml'' file which can be found in the directories:
  
/opt/SEGGER/Jlink (Linux hosts)
+
''/opt/SEGGER/Jlink'' (Linux hosts)
  
C:\Program Files (x86)\SEGGER\JLink_V640 (Windows hosts – the driver version may be different)
+
''C:\Program Files (x86)\SEGGER\JLink_V640'' (Windows hosts – the driver version may be different)
  
  
 
In this file there is a section with the NXP iMXRT105x microcontroller family configuration, where each of the entries has a Loader value:
 
In this file there is a section with the NXP iMXRT105x microcontroller family configuration, where each of the entries has a Loader value:
  
Devices/NXP/iMXRT105x/NXP_iMXRT105x_HyperFlash.elf  
+
''Devices/NXP/iMXRT105x/NXP_iMXRT105x_HyperFlash.elf''
  
 
This value needs to be changed to:
 
This value needs to be changed to:
  
Devices/NXP/iMXRT105x/NXP_iMXRT105x_QSPI.elf
+
''Devices/NXP/iMXRT105x/NXP_iMXRT105x_QSPI.elf''
 +
 
  
The detailed informations can be found on the SEGGER wiki page for the iMXRT1050 microcontrollers:
+
The detailed information can be found on the SEGGER wiki page for the iMXRT1050 microcontrollers:
  
 
[https://wiki.segger.com/I.MXRT1050 https://wiki.segger.com/I.MXRT1050]
 
[https://wiki.segger.com/I.MXRT1050 https://wiki.segger.com/I.MXRT1050]
Line 137: Line 132:
 
== Running the example code ==
 
== Running the example code ==
  
Now we have everything that s required to program the QSPI Flash memory and run the example. In order to do this we need to select the Debug using SEGGER J-Link probes option from the J-Link menu and choose the detected debug probe.
+
Now we have everything that is required to program the QSPI Flash memory and run the example. In order to do this we need to select the ''Debug'' using SEGGER J-Link probes option from the J-Link menu and choose the detected debug probe.
  
PIC debug1
 
  
PIC debug2
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_debug1.png|center|800px]]
 +
 
 +
 
 +
 
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_debug2.png|center|500px]]
  
  
 
After the programming is done we will see the debug view of the MCUXpresso IDE.
 
After the programming is done we will see the debug view of the MCUXpresso IDE.
  
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_debug3.png|center|800px]]
  
PIC debug3
+
== Configuring the GPIO ==
  
 +
In our example we will use the blue LED (IO10) connected to the GPIO1_IO08 (GPIO_AD_B0_08) pin. We will configure it using the ''Pins configuration tool''.
  
== Configuring the GPIO ==
 
  
In our example we will use the blue LED (IO10) connected to the GPIO1_IO08 (GPIO_AD_B0_08) pin. We will configure it using the Pins configuration tool.
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_pins1.png|center|800px]]
  
PIC pins1
 
  
 +
In the configurator window we can select the proper pin and configure it as the GPIO output with Pull-down. We also need to create a label for it. In this example we will call it LED.
  
In the configurator window we can select the proper pin and configure it ad the GPIO output with Pull-down. We also need to create a label for it. In this example we will call it LED.
 
  
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_pins2.png|center|800px]]
  
PIC pins2
 
  
 +
When the configuration is done, we need to generate the source code using the ''Update project'' option.
  
When the configuration is done, we need to generate the source code using the Update project option.
 
  
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_pins3.png|center|800px]]
  
PIC pins3
 
  
PIC pins4
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_pins4.png|center|500px]]
  
  
After clicking OK, the source code for GPIO configuration will be generated in the board directory in or project.
+
After clicking ''OK'', the source code for GPIO configuration will be generated in the board directory in or project.
  
  
We can do the same with the clock configuration, by opening the clock configuration tool and enabling 24MHz crystal input. This way we will create a default configuration for all clocks in the microcontrollers. The Update project option will generate the source code in the board directory.
+
We can do the same with the clock configuration, by opening the clock configuration tool and enabling 24MHz crystal input. This way we will create a default configuration for all clocks in the microcontroller. The ''Update project'' option will generate the source code in the board directory.
  
  
PIC clocks1
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_clocks1.png|center|800px]]
  
PIC clocks2
 
  
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_clocks2.png|center|800px]]
  
 
== Configuring the LPUART ==
 
== Configuring the LPUART ==
  
 
For the example we also need the LPUART port to communicate with the PC. On the VisionCB-RT-STD Carrier Board two microcontroller pins are connected to the FTDI USB-UART interface – GPIO_AD_B0_12 (LPUART1_TX) and GPIO_AD_B0_13 (LPUART1_RX). We can configure them using the pin configuration tool.
 
For the example we also need the LPUART port to communicate with the PC. On the VisionCB-RT-STD Carrier Board two microcontroller pins are connected to the FTDI USB-UART interface – GPIO_AD_B0_12 (LPUART1_TX) and GPIO_AD_B0_13 (LPUART1_RX). We can configure them using the pin configuration tool.
 
PIC uart1
 
  
  
We will also change the UART_CLK_ROOT clock frequency from 4MHz to 24MHz bu changing its clock source to the OSC_CLK (external crystal oscillator). It will guarantee more accuracy during bit clock generation.
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_uart1.png|center|800px]]
  
  
PIC uart2
+
We will also change the UART_CLK_ROOT clock frequency from 4MHz to 24MHz by changing its clock source to the OSC_CLK (external crystal oscillator). It will guarantee more accuracy during bit clock generation.
  
  
 +
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_uart2.png|center|800px]]
  
  
Now, we need to configure the LPUART1 peripheral. Again, we can do it using the configuration tool for peripherals.
+
Now we need to configure the LPUART1 peripheral. Again we can do it using the configuration tool for peripherals.
  
  
PIC uart3
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_uart3.png|center|800px]]
  
  
Line 206: Line 203:
  
  
PIC uart4
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_uart4.png|center|800px]]
 
 
  
 
== FreeRTOS example ==
 
== FreeRTOS example ==
Line 213: Line 209:
 
Now, when we have prepared the project and created all configurations, we can write a simple FreeRTOS example with two tasks: one for blinking LED and the second one for writing a string to the serial port. The source code of the example looks as follows:
 
Now, when we have prepared the project and created all configurations, we can write a simple FreeRTOS example with two tasks: one for blinking LED and the second one for writing a string to the serial port. The source code of the example looks as follows:
  
<span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;"><stdio.h></span>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"board.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"peripherals.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"pin_mux.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"clock_config.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"MIMXRT1052.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"fsl_gpio.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"fsl_lpuart.h"</span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"FreeRTOS.h"</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''<nowiki>#include</nowiki>'''</span><span style="color:#000000;"> </span><span style="color:#2a00ff;">"task.h"</span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#005032;">TaskHandle_t</span><span style="color:#000000;"> ledTaskHandle;</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#005032;">TaskHandle_t</span><span style="color:#000000;"> uartTaskHandle;</span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;"> </span><span style="color:#000000;">'''ledTask'''</span><span style="color:#000000;">(</span><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;"><nowiki>* param) {</nowiki></span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''const'''</span><span style="color:#000000;"> </span><span style="color:#005032;">TickType_t</span><span style="color:#000000;"> delayMs = 1000 / portTICK_PERIOD_MS;</span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''while'''</span><span style="color:#000000;">(1) {</span></div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;"> GPIO_PinWrite(GPIO1, 8, 1);</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;"> vTaskDelay(delayMs);</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;"> GPIO_PinWrite(GPIO1, 8, 0);</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;"> vTaskDelay(delayMs);</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">}</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">}</div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;"> </span><span style="color:#000000;">'''uartTask'''</span><span style="color:#000000;">(</span><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;"><nowiki>* param) {</nowiki></span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''const'''</span><span style="color:#000000;"> </span><span style="color:#005032;">TickType_t</span><span style="color:#000000;"> delayMs = 1000 / portTICK_PERIOD_MS;</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''char'''</span><span style="color:#000000;"> text[32] = {0};</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#005032;">uint8_t</span><span style="color:#000000;"> i = 0;</span></div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''while'''</span><span style="color:#000000;">(1) {</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">sprintf(text, </span><span style="color:#2a00ff;">"HELLO TASK %d\r\n"</span><span style="color:#000000;">, i++);</span></div>
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;"> LPUART_WriteBlocking(LPUART1, (</span><span style="color:#005032;">uint8_t</span><span style="color:#000000;"><nowiki>*)text, </nowiki></span><span style="color:#642880;">'''strlen'''</span><span style="color:#000000;">(text));</span></div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;"> vTaskDelay(delayMs);</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">}</div>
 
 
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">}</div>
 
 
 
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;"> </span><span style="color:#000000;">'''main'''</span><span style="color:#000000;">(</span><span style="color:#7f0055;">'''void'''</span><span style="color:#000000;">) {</span></div>
 
  
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">BOARD_InitBootPins();</div>
+
<pre>
 +
#include <stdio.h>
 +
#include "board.h"
 +
#include "peripherals.h"
 +
#include "pin_mux.h"
 +
#include "clock_config.h"
 +
#include "MIMXRT1052.h"
 +
#include "fsl_gpio.h"
 +
#include "fsl_lpuart.h"
  
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">BOARD_InitBootClocks();</div>
+
#include "FreeRTOS.h"
 +
#include "task.h"
  
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">BOARD_InitBootPeripherals();</div>
+
TaskHandle_t ledTaskHandle;
 +
TaskHandle_t uartTaskHandle;
  
 +
void ledTask(void* param) {
  
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">xTaskCreate(ledTask, </span><span style="color:#2a00ff;">"LED_TASK"</span><span style="color:#000000;">, 128, NULL, 1, &ledTaskHandle);</span></div>
+
const TickType_t delayMs = 1000 / portTICK_PERIOD_MS;
  
<div style="margin-left:0cm;margin-right:0cm;"><span style="color:#000000;">xTaskCreate(uartTask, </span><span style="color:#2a00ff;">"UART_TASK"</span><span style="color:#000000;">, 128, NULL, 1, &uartTaskHandle);</span></div>
+
while(1) {
 +
    GPIO_PinWrite(GPIO1, 8, 1);
 +
    vTaskDelay(delayMs);
 +
    GPIO_PinWrite(GPIO1, 8, 0);
 +
    vTaskDelay(delayMs);
 +
}
 +
}
  
 +
void uartTask(void* param) {
  
<div style="color:#000000;margin-left:0cm;margin-right:0cm;">vTaskStartScheduler();</div>
+
const TickType_t delayMs = 1000 / portTICK_PERIOD_MS;
 +
char text[32] = {0};
 +
uint8_t i = 0;
  
<div style="color:#000000;">}</div>
+
while(1) {
 +
    sprintf(text, "HELLO TASK %d\r\n", i++);
 +
    LPUART_WriteBlocking(LPUART1, (uint8_t*)text, strlen(text));
 +
    vTaskDelay(delayMs);
 +
}
 +
}
  
 +
void main(void) {
 +
    BOARD_InitBootPins();
 +
    BOARD_InitBootClocks();
 +
    BOARD_InitBootPeripherals();
  
<div style="color:#000000;">It can be copied directly to the main.c file in the project. </div>
+
    xTaskCreate(ledTask,  "LED_TASK",  128, NULL, 1, &ledTaskHandle);
 +
    xTaskCreate(uartTask, "UART_TASK", 128, NULL, 1, &uartTaskHandle);
  
 +
    vTaskStartScheduler();
 +
}
 +
</pre>
  
  
 +
It can be copied directly to the ''main.c'' file in the project.
  
 
== Importing project ==
 
== Importing project ==
  
<div style="color:#000000;">The configured project can be also imported directly to the MCUXpresso IDE. The project archive can be downloaded from this website and imported from the File→Import… menu.</div>
+
The configured project can be also imported directly to the MCUXpresso IDE. The project archive can be downloaded from [http://ftp.somlabs.com/Trainings/Hands-on-FreeRTOS-emWIN-2019/FreeRTOS_demo.zip this website] and imported from the File→Import… menu.
  
  
<div style="color:#000000;">PIC import1</div>
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_import1.png|center|800px]]
  
  
<div style="color:#000000;">In the import wizard we need to chose General→Existing Projects into Workspace.</div>
+
In the import wizard we need to choose General→Existing Projects into Workspace.
  
  
<div style="color:#000000;">PIC import2</div>
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_import2.png|center|500px]]
  
  
<div style="color:#000000;">Then in the next window we can choose the Select archive file option and browse to the downloaded zip archive.</div>
+
Then in the next window we can choose the ''Select archive file'' option and browse to the downloaded zip archive.
  
  
<div style="color:#000000;">PIC import3</div>
+
[[Image:VisionSOM-RT_the_first_FreeRTOS_application_import3.png|center|500px]]
  
  
<div style="color:#000000;">After clicking Finish button the project sources will be copied to the active workspace. The SDK needs to be imported separately in order to compile and run the example.</div>
+
After clicking ''Finish'' button the project sources will be copied to the active workspace. The SDK needs to be imported separately in order to compile and run the example.

Revision as of 22:47, 17 March 2019

How to create and run the first FreeRTOS application on the VisionSOM-RT


This article describes how to create and run first FreeRTOS application on the VisionSOM-RT module with the NXP i.MX RT1052 microcontroller. The application will be executed from the external QSPI Flash memory.


Requirements

Hardware

Software

  • Any terminal application, for example Termite

Importing the SDK

The created SDK needs to be imported to the MCUXpresso IDE. We can do it by selecting the import archive option in the Installed SDKs window, or by simple drag-and drop the archive file to this window.

VisionSOM-RT the first FreeRTOS application sdk1.png


VisionSOM-RT the first FreeRTOS application sdk2.png


VisionSOM-RT the first FreeRTOS application sdk3.png

Generating a new project

The MCUXpresso contains a project creator tool that allows to configure a new project with the software componenst available in the imported SDKs. The project creator is available in the File menu (File→New→Project…).


VisionSOM-RT the first FreeRTOS application project1.png


The project appropriate type is the New C/C++ Project.


VisionSOM-RT the first FreeRTOS application project2.png


Next, a target microcontroller should be selected.


VisionSOM-RT the first FreeRTOS application project3.png


In the next window we can set the name of the project, select the device package and the required software components and drivers. The project requires the FreeRTOS system and the following drivers:

  • clock
  • common
  • gpio
  • iomuxc
  • lpuart
  • xip-board
  • xip-device


VisionSOM-RT the first FreeRTOS application project4.png


In the next window we can configure the C library and the compiler options. This window also contains the available memories, so we need to define the Flash memory (Location 0x60000000, Size 0x1000000, Driver MIMXRT1050_SFDP_QSPI.cfx). The remaining parameters in this window may be configured with their default values.


VisionSOM-RT the first FreeRTOS application project5.png


After this step the project files should be created, but before we can compile it two more steps are required for proper QSPI Flash configuration. First of all we need to update the sources in the xip directory in order to support the QSPI flash. The updated version for this memory can be found on the NXP Community site in the QSPI_xip.zip archive.


The blog post:

https://community.nxp.com/community/mcuxpresso/mcuxpresso-ide/blog/2017/12/07/overview-of-using-the-mimxrt1050-evk-with-mcuxpresso-ide


The direct link to the archive:

https://community.nxp.com/servlet/JiveServlet/download/10894-1-430488/QSPI_xip.zip


We can simply remove all sources from the xip directory and put there the ones from the QSPI_xip.zip archive.


After that we also need to define the BOARD_FLASH_SIZE symbol, that is required in the xip/fsl_flexspi_nor_boot.h file. We can do it directly in the file or by creating a preprocessor symbol in the project configuration (C/C++ Build→Settings→Tool Settings→Preprocessor). The BOARD_FASH_SIZE symbol should be set according to the QSPI Flash size, which in our case is 0x1000000 (16MB).


VisionSOM-RT the first FreeRTOS application properties1.png


VisionSOM-RT the first FreeRTOS application properties2.png


Now we are able to build the project using the Build tool.


VisionSOM-RT the first FreeRTOS application build1.png

Configuring SEGGER tools

By default the installed SEGGER drivers support the external HyperFlash memories. In order to program the on-board QSPI Flash, the configuration files should be modified. The changes should be done in the JlinkDevices.xml file which can be found in the directories:

/opt/SEGGER/Jlink (Linux hosts)

C:\Program Files (x86)\SEGGER\JLink_V640 (Windows hosts – the driver version may be different)


In this file there is a section with the NXP iMXRT105x microcontroller family configuration, where each of the entries has a Loader value:

Devices/NXP/iMXRT105x/NXP_iMXRT105x_HyperFlash.elf

This value needs to be changed to:

Devices/NXP/iMXRT105x/NXP_iMXRT105x_QSPI.elf


The detailed information can be found on the SEGGER wiki page for the iMXRT1050 microcontrollers:

https://wiki.segger.com/I.MXRT1050

Running the example code

Now we have everything that is required to program the QSPI Flash memory and run the example. In order to do this we need to select the Debug using SEGGER J-Link probes option from the J-Link menu and choose the detected debug probe.


VisionSOM-RT the first FreeRTOS application debug1.png


VisionSOM-RT the first FreeRTOS application debug2.png


After the programming is done we will see the debug view of the MCUXpresso IDE.

VisionSOM-RT the first FreeRTOS application debug3.png

Configuring the GPIO

In our example we will use the blue LED (IO10) connected to the GPIO1_IO08 (GPIO_AD_B0_08) pin. We will configure it using the Pins configuration tool.


VisionSOM-RT the first FreeRTOS application pins1.png


In the configurator window we can select the proper pin and configure it as the GPIO output with Pull-down. We also need to create a label for it. In this example we will call it LED.


VisionSOM-RT the first FreeRTOS application pins2.png


When the configuration is done, we need to generate the source code using the Update project option.


VisionSOM-RT the first FreeRTOS application pins3.png


VisionSOM-RT the first FreeRTOS application pins4.png


After clicking OK, the source code for GPIO configuration will be generated in the board directory in or project.


We can do the same with the clock configuration, by opening the clock configuration tool and enabling 24MHz crystal input. This way we will create a default configuration for all clocks in the microcontroller. The Update project option will generate the source code in the board directory.


VisionSOM-RT the first FreeRTOS application clocks1.png


VisionSOM-RT the first FreeRTOS application clocks2.png

Configuring the LPUART

For the example we also need the LPUART port to communicate with the PC. On the VisionCB-RT-STD Carrier Board two microcontroller pins are connected to the FTDI USB-UART interface – GPIO_AD_B0_12 (LPUART1_TX) and GPIO_AD_B0_13 (LPUART1_RX). We can configure them using the pin configuration tool.


VisionSOM-RT the first FreeRTOS application uart1.png


We will also change the UART_CLK_ROOT clock frequency from 4MHz to 24MHz by changing its clock source to the OSC_CLK (external crystal oscillator). It will guarantee more accuracy during bit clock generation.


VisionSOM-RT the first FreeRTOS application uart2.png


Now we need to configure the LPUART1 peripheral. Again we can do it using the configuration tool for peripherals.


VisionSOM-RT the first FreeRTOS application uart3.png


In the configurator window we can select the configured peripherals and change their configuration. In the example we will use the default settings of the serial port (baud rate 115200, 8 data bits, 1 stop bit, no parity). The update option will generate the source code for us.


VisionSOM-RT the first FreeRTOS application uart4.png

FreeRTOS example

Now, when we have prepared the project and created all configurations, we can write a simple FreeRTOS example with two tasks: one for blinking LED and the second one for writing a string to the serial port. The source code of the example looks as follows:


#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MIMXRT1052.h"
#include "fsl_gpio.h"
#include "fsl_lpuart.h"

#include "FreeRTOS.h"
#include "task.h"

TaskHandle_t ledTaskHandle;
TaskHandle_t uartTaskHandle;

void ledTask(void* param) {

	const TickType_t delayMs = 1000 / portTICK_PERIOD_MS;

	while(1) {
	    GPIO_PinWrite(GPIO1, 8, 1);
	    vTaskDelay(delayMs);
	    GPIO_PinWrite(GPIO1, 8, 0);
	    vTaskDelay(delayMs);
	}
}

void uartTask(void* param) {

	const TickType_t delayMs = 1000 / portTICK_PERIOD_MS;
	char text[32] = {0};
	uint8_t i = 0;

	while(1) {
	    sprintf(text, "HELLO TASK %d\r\n", i++);
	    LPUART_WriteBlocking(LPUART1, (uint8_t*)text, strlen(text));
	    vTaskDelay(delayMs);
	}
}

void main(void) {
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();

    xTaskCreate(ledTask,  "LED_TASK",  128, NULL, 1, &ledTaskHandle);
    xTaskCreate(uartTask, "UART_TASK", 128, NULL, 1, &uartTaskHandle);

    vTaskStartScheduler();
}


It can be copied directly to the main.c file in the project.

Importing project

The configured project can be also imported directly to the MCUXpresso IDE. The project archive can be downloaded from this website and imported from the File→Import… menu.


VisionSOM-RT the first FreeRTOS application import1.png


In the import wizard we need to choose General→Existing Projects into Workspace.


VisionSOM-RT the first FreeRTOS application import2.png


Then in the next window we can choose the Select archive file option and browse to the downloaded zip archive.


VisionSOM-RT the first FreeRTOS application import3.png


After clicking Finish button the project sources will be copied to the active workspace. The SDK needs to be imported separately in order to compile and run the example.

NXP Partner ST Partner Renesas Partner