In the previous article(s) I have been writing about using FreeRTOS on PSoC 4 development kits. The other day a friend of mine in Kentucky sent me a note asking about PSoC6, so here it is. PSoC 6. In this article I will write about the first PSoC 6 FreeRTOS example, obviously, the blinking LED. In this article I will also get to show off the Type-C connector on the new CY8CKIT-062-BLE Devkit.
Create PSoC 6 FreeRTOS Project
To get this whole thing going, create a new PSoC 6 project in PSoC Creator. Because the PSoC 6 is still in early release, you will need the secret key to get it going in PSoC6 Creator (which you can find out from the Early Access Program). But, when you know the key, you will get something that we have all been waiting for, the ability to create a PSoC 6 project.
Once you have a new project (which I already renamed 1-LEDBlink) you can look at it in the Workspace Explorer where you will see the normal PSoC things, Schematic, Pins, Analog, etc. So far, so good.
Next I click on then TopDesign.sch, then add a digital output pin. That looks and feels familiar to all of you PSoC people out there.
Next I assign the pin to “P0” on the Pins tab. Wow, that tiny little CSP has a boatload of pins, and yes this chip can do a bunch of things.
Now for some new stuff. I want to have FreeRTOS included in my project. In the PSoC 4 family you need to download it, add paths to your project etc. Read about it here. Instead of doing that, you can edit the “Build Settings” by right clicking on the project.
Then on the build settings menu, pick Peripheral Driver Library (more on this later). On the PDL screen you can click to add “FreeRTOS” and you can pick out the memory management scheme (in this case I picked heap_4).
When you generate application, PSoC Creator will copy FreeRTOS into your project generated source, and give you a default FreeRTOSConfig.h (see it in the Header Files for the CM4)
PSoC Creator gives you a pretty generic FreeRTOSConfig.h file, with some of stuff hooked up (like the clock frequency). This file is copied into your project. Once that is done, you own it, and all of the changes to it.
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
#define configUSE_TICKLESS_IDLE 0
#define configCPU_CLOCK_HZ cy_delayFreqHz
#define configTICK_RATE_HZ 1000u
#define configMAX_PRIORITIES 7
#define configMINIMAL_STACK_SIZE 128
#define configMAX_TASK_NAME_LEN 16
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_MUTEXES 0
#define configUSE_RECURSIVE_MUTEXES 0
#define configUSE_COUNTING_SEMAPHORES 0
#define configQUEUE_REGISTRY_SIZE 10
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 0
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
#define configSUPPORT_DYNAMIC_ALLOCATION 1
#define configTOTAL_HEAP_SIZE 10240
The other thing that Creator does is hookup the necessary interrupt vectors (so that FreeRTOS will run)
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
#define xPortSysTickHandler SysTick_Handler
Now you have a project setup, and template files for everything… including the CM0p. After the chip turns on and the boot sequence is complete, it jumps to the main in the file main_cm0p.c. That default version of that file just turns on the CM4.
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
__enable_irq(); /* Enable global interrupts. */
/* Enable CM4. CY_CORTEX_M4_APPL_ADDR must be updated if CM4 memory layout is changed. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
/* Place your application code here. */
/*  END OF FILE */
Finally, the file main_cm4.c contains your program.
On lines 3-6 I just create a function which locks the MCU if there is a memory allocation failure inside of the FreeRTOS.
Lines 8-17 is a FreeRTOS task to blink the LED. Notice that the old PSoC 4 functions pin_Write() and pin_Read() are now replaced with PDL versions of those functions.
Lastly, lines 23-24 create the LED task and launch the RTOS.
void vApplicationStackOverflowHook(TaskHandle_t *pxTask, signed char *pcTaskName )
void ledTask(void *arg)
__enable_irq(); /* Enable global interrupts. */
xTaskCreate( ledTask, "LED Task",400,0,1,0);
Program PSoC 6 FreeRTOS Project
Now that we have firmware. It is time to program the devkit. One thing that I think is cool is that the devkit is the first (of ours) to have Type-C on the devkit (I wonder if it is the first in the Industry?). We provide a Type-A to Type-C cable so you can keep rolling if you haven’t switched over to Type-C, but as I have a new Mac with only Type-C ,I use a Type-C to Type-C cable.
When you click program, PSoC Creator brings up the window asking you which core is the debug target. In this case it doesn’t matter as you are programming a hex file with both the CM0+ and the CM4 code in it (remember they are shared memory). So, I pick CM4 and let it rip.
In the next several articles I will be switching back and forth between the PSoC 4 & PSoC 6 FreeRTOS projects.
If you have something you are interested in please leave a comment and maybe I’ll build it for you.
FreeRTOS: A PSoC4 FreeRTOS Port
An introduction to making FreeRTOS work on PSoC 4
FreeRTOS PSoC Examples
Using multiple tasks in FreeRTOS
FreeRTOS Queue Example
Using a queue to communicate between tasks
PSoC 6 FreeRTOS - The First Example
Booting FreeRTOS on PSoC 6
FreeRTOS Binary Semaphore
An first example of a binary semaphore
FreeRTOS Binary Semaphore (Part 2)
Removing polling in the UART Task
FreeRTOS Counting Semaphore
An example using a counting semaphore
Reading I2C Sensors with a shared I2C Bus
PSoC FreeRTOS Task Notify
A light weight scheme to replace Semaphores
PSoC FreeRTOS Task Notification Values
A very light weight method to transfer one word of information into a task