S32 SDK
FreeRTOS

Demo application showing the integration of FreeRTOS and S32 SDK

Application description


The purpose of this demo application is to show you how to use the FreeRTOS with the S32 SDK for the S32K148 MCU.

This project defines a very simple demo that creates two tasks, one queue, and one timer. It also demonstrates how Cortex-M4 interrupts can interact with FreeRTOS tasks/timers.

This simple demo project runs 'stand alone' (without the rest of the tower system) on the Freedom Board or Validation Board, which is populated with a S32K148 Cortex-M4 microcontroller.

The idle hook function: The idle hook function demonstrates how to query the amount of FreeRTOS heap space that is remaining (see vApplicationIdleHook() defined in this file).

The main() Function: main() creates one software timer, one queue, and two tasks. It then starts the scheduler.

The Queue Send Task: The queue send task is implemented by the prvQueueSendTask() function in this file. prvQueueSendTask() sits in a loop that causes it to repeatedly block for 200 milliseconds, before sending the value 100 to the queue that was created within main(). Once the value is sent, the task loops back around to block for another 200 milliseconds.

The Queue Receive Task: The queue receive task is implemented by the prvQueueReceiveTask() function in this file. prvQueueReceiveTask() sits in a loop that causes it to repeatedly attempt to read data from the queue that was created within main(). When data is received, the task checks the value of the data, and if the value equals the expected 100, toggles the green LED. The 'block time' parameter passed to the queue receive function specifies that the task should be held in the Blocked state indefinitely to wait for data to be available on the queue. The queue receive task will only leave the Blocked state when the queue send task writes to the queue. As the queue send task writes to the queue every 200 milliseconds, the queue receive task leaves the Blocked state every 200 milliseconds, and therefore toggles the blue LED every 200 milliseconds.

The LED Software Timer and the Button Interrupt: The user button BTN1 is configured to generate an interrupt each time it is pressed. The interrupt service routine switches the red LED on, and resets the LED software timer. The LED timer has a 5000 millisecond (5 second) period, and uses a callback function that is defined to just turn the LED off again. Therefore, pressing the user button will turn the LED on, and the LED will remain on until a full five seconds pass without the button being pressed.

Prerequisites


The run the example you will need to have the following items:

  • 1 S32K148 board
  • 1 Power Adapter 12V (if the board cannot be powered from the USB port)
  • 2 Dupont male to male cable
  • 1 Personal Computer
  • 1 Jlink Lite Debugger (optional, users can use Open SDA)

Boards supported


The following boards are supported by this application:

  • S32K148EVB-Q100
  • S32K148-MB

Hardware Wiring


The following connections must be done to for this example application to work:

PIN FUNCTION S32K148EVB-Q100 S32K148-MB
RED_LED (PTD15) RGB_RED - wired on the board J12.17 - J11.31
GREEN_LED (PTD16) RGB_GREEN - wired on the board J12.16 - J11.30
BTN (PTC13) BTN1 - wired on the board BTN3 - wired on the board

How to run


1. Importing the project into the workspace

After opening S32 Design Studio, go to File -> New S32DS Project From... and select freertos_s32k148. Then click on Finish.
The project should now be copied into you current workspace.

2. Generating the Processor Expert configuration

First go to Project Explorer View in S32 DS and select the current project(freertos_s32k148). Then go to Project and click on Generate Processor Expert Code
Wait for the code generation to be completed before continuing to the next step.

3. Building the project

Select the configuration to be built FLASH (Debug_FLASH) or RAM (Debug_RAM) by left clicking on the downward arrow corresponding to the build button(. Wait for the build action to be completed before continuing to the next step.

4. Running the project

Go to Run and select Debug Configurations. There will be four debug configurations for this project:

Configuration Name Description
freertos_s32k148 Debug_RAM Jlink Debug the RAM configuration using Segger Jlink debuggers
freertos_s32k148 Debug_FLASH Jlink Debug the FLASH configuration using Segger Jlink debuggers
freertos_s32k148 Debug_RAM PEMicro Debug the RAM configuration using PEMicro debuggers
freertos_s32k148 Debug_FLASH PEMicro Debug the FLASH configuration using PEMicro debuggers


Select the desired debug configuration and click on Launch. Now the perspective will change to the Debug Perspective.
Use the controls to control the program flow.

Note
For more detailed information related to S32 Design Studio usage please consult the available documentation.