This blog should serve as a guide to adding Micrium OS on a Flex Gecko and get at least one task running on the device.
I will now share with you my experience while going through this exercise.
Getting Started
I decided to perform a clean installation of Simplicity Studio in order to avoid conflicts inflicted by software updates over time. After installing the tool, before even attempting to add anything, I first had to make sure that I had the necessary SDKs. Here's what I installed:
32-bit MCU SDK - 5.7.0
Micrium OS - 5.6.0
Flex SDK - 2.5.0.0
I then mounted a Flex Gecko, EFR32FG12 in my case, onto a Wireless Started Kit Mainboard (BRD4001A). After that, I connected it to the PC using the provided USB cable.
Simplicity Studio recognized a Flex Gecko connected to a WSTK and displayed the link to examples from the Flex SDK (see Figure 1).
Figure 1 - Initial Setup Validation
Loading a Basic Flex SDK Example
As a starting point, I decided to go with the "RAIL: Simple RAIL without HAL" example from the Flex SDK.
You can find this by expanding the list of projects under the "Silicon Labs Flex SDK Examples" link:
Figure 2 - Flex SDK Examples Link
Then find and click the example shown in Figure 3 to add it to your workspace:
Figure 3 - RAIL: Simple RAIL without HAL Example
After the example loads on your workspace, you might get a notice as shown in Figure 4. Just click "OK".
Figure 4 - Auto upgrade notice
You will then be presented with simple_rail_without_hal.isc opened where you can configure RAIL. In my case, I left everything in its default values and simply clicked on "Generate" as shown in Figure 5.
Figure 5 - RAIL Project Configuration
At this point, you should now be set with a basic Flex Gecko example that builds and runs. However, I did find that the default project settings have compiler optimization set to "Optimize for size (-Os)" which will eventually make debugging the project rather difficult. Therefore, I switched optimizations to "None (-O0)".
Figure 6 - Compiler Optimizations
Adding Micrium OS to the Workspace
Now that you have a basic Flex Gecko example that builds and runs, let's go ahead and start adding the Micrium OS source files into the workspace.
First, locate the Micrium OS directory, it should be in:
Now drag and drop the "micrium_os" folder into your project (simple_rail_without_hal) in Simplicity Studio. When doing this, make sure that you have "Copy files and folders" selected before clicking "OK" as shown in Figure 7.
Figure 7 - Adding Micrium OS Folder to Project
You will then have to remove all the unnecessary files that get added with Micrium OS (this was tedious).
Here's how your "micrium_os" folder should end up looking:
Figure 8 - Micrium OS Necessary Files
Finally, the compiler needs to know where to look for the header files so we have to add two compiler include paths to the project settings:
Now that you have Micrium OS as part of your project, let's go ahead and make some minor adjustments to the default Micrium OS configuration.
Open rtos_description.h located in your project under "micrium_os/cfg/"
Replace the contents of the file with one below:
/***************************************************************************//**
* @file
* @brief RTOS Description - Configuration Template File
*******************************************************************************
* # License
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
/********************************************************************************************************
********************************************************************************************************
* MODULE
********************************************************************************************************
*******************************************************************************************************/
#ifndef _RTOS_DESCRIPTION_H_
#define _RTOS_DESCRIPTION_H_
/********************************************************************************************************
********************************************************************************************************
* INCLUDE FILES
********************************************************************************************************
*******************************************************************************************************/
#include <common/include/rtos_opt_def.h>
/********************************************************************************************************
********************************************************************************************************
* ENVIRONMENT DESCRIPTION
********************************************************************************************************
*******************************************************************************************************/
#define RTOS_CPU_SEL RTOS_CPU_SEL_ARM_V7_M
#define RTOS_TOOLCHAIN_SEL RTOS_TOOLCHAIN_GNU
#define RTOS_INT_CONTROLLER_SEL RTOS_INT_CONTROLLER_ARMV7_M
/********************************************************************************************************
********************************************************************************************************
* RTOS MODULES DESCRIPTION
********************************************************************************************************
*******************************************************************************************************/
// ---------------------- KERNEL ----------------------
#define RTOS_MODULE_KERNEL_AVAIL
/********************************************************************************************************
********************************************************************************************************
* MODULE END
********************************************************************************************************
*******************************************************************************************************/
#endif // End of rtos_description.h module include.
Modifying main.c
We'll be making modifications to the default main.c generated by the "RAIL: Simple RAIL without HAL" example.
Micrium OS requires the following include paths in main.c so go ahead and add them as shown below:
#include <cpu/include/cpu.h>
#include <kernel/include/os.h>
#include <common/include/common.h>
#include <common/include/rtos_utils.h>
#include <common/source/kal/kal_priv.h> /* Private file, use should be limited */
We'll be modifying main.c to initialize Micrium OS and create a start task. For that, you'll need to specify a task stack size and a priority. We typically do this by defining them as constants and passing those in the call to OSTaskCreate().
The start task also requires its own Stack and Task Control Block (OS_TCB) as well as its function prototype. Therefore, add the following to main.c:
Here's the body of the StartTask function where the kernel tick gets initialize and as well as the Common module. Note that the function includes an infinite loop at the end with a time delay of 1 second. This is done to yield CPU time to other tasks that are or will eventually run on your system. You can copy and paste the following in your main.c:
You are now set to build and run the project. You can put a breakpoint on the Start Task inside the while loop and notice that you'll be hitting that every second (or as specified by the delay you configure in OSTimeDly()).
Please do understand that this is a very basic guide that resembles more a hack rather than an official solution from Silicon Labs. Hopefully, Micrium OS can be part of the Flex SDK in the future, but in the meantime, this is a start.
I hope this was useful to you. Feel free to post any comments or questions regarding this blog post.
Blog Posts
Micrium OS
Flex Gecko
How to add this os for Mighty Gecko module.@Janos Magasrevy
0
Hi! Thank you for this awesome post! But I have two questions:
1.- I see you have deleted a lot of files regarding I/O and BSP and so on in Micrium OS files, if I need to use those functionalities I should just keep those files, right?
2.- You are using Simple RAIL without HAL, but if I want to use HAL (for example, to shutdown EEPROM*), I could use RAIL with HAL and follow the same steps, right?
* Some components are under Connect (SPI-Flash, Serial, Micrium OS), does it mean that if I select them I need to use Connect? Or are those components not really linked with Connect?
EDIT: This project doesn't work anymore with Flex >= 2.7.1 and Micrium OS >= 5.8.1. I am looking for a solution since I want to use RAIL + RTOS and not Connect + RTOS.
I debugged the MG12 code you attached above, but it can't jump in startTask.
Can you help to porting the code simple_rail_with_hal to MG22 or BG22 (BRD4182A)platform?
Thanks!
0
Hi Wei,
I've attached a clean main.c. I noticed that optimizations were turned on in your project so this probably made it difficult for you to pin-point where the issue was. I noticed 2 things:
The code was getting stuck in that ASSERT when I switched optimizations off. Then I remove this section of code from both tasks since it's not being used.
The second thing that I noticed was that the Common module was being reinitialized in the UserTask.
I turned optimizations back on after cleaning up main.c and I see both tasks running fine now.
I have attempted to follow the guide without success.
I am using the latest available MCU SDK(5.9.6.0), Mircrium OS(5.6.0) Flex(2.7.6). Hardware is an EFR32MG12 and radio boards are actually the same (BRD4001A).
I an wondering why all this, altough I only just came across it I found AN1134: "Dynammic Multiprotocol..." which seemingly uses both BLE and RAIL and includes Mircrioum OS. So what am I missing? can't I take that and hollow out the BLE part? Why do I need to go into all this manual work and file removal?
I am mainly asking this to avoid wasting more houres to get this combination working.
Thank you
0
Hi David,
Have you tried the updated project that I uploaded a few replies back?
0
Hi Janos,
To be honset not sure now is was a while back.
I will have to get back to it as I do need it and report. I assumeyou refer to yout post with "Here's a project on the MG12 using version 2.7 of the SDK:" ?
That being said I am still puzzled regarding possible use of AN1134, was my question not valid?
0
Hi Janos,
To be honset not sure now is was a while back.
I will have to get back to it as I do need it and report. I assumeyou refer to yout post with "Here's a project on the MG12 using version 2.7 of the SDK:" ?
That being said I am still puzzled regarding possible use of AN1134, was my question not valid?
Adding Micrium OS on a Flex Gecko
This blog post has been closed for comments due to it being out-of-date with the latest Gecko SDK and no longer relevant.
------------------------------------------------------------------------------------------------------------------------------------
This blog should serve as a guide to adding Micrium OS on a Flex Gecko and get at least one task running on the device.
I will now share with you my experience while going through this exercise.
Getting Started
I decided to perform a clean installation of Simplicity Studio in order to avoid conflicts inflicted by software updates over time. After installing the tool, before even attempting to add anything, I first had to make sure that I had the necessary SDKs. Here's what I installed:
I then mounted a Flex Gecko, EFR32FG12 in my case, onto a Wireless Started Kit Mainboard (BRD4001A). After that, I connected it to the PC using the provided USB cable.
Simplicity Studio recognized a Flex Gecko connected to a WSTK and displayed the link to examples from the Flex SDK (see Figure 1).
Loading a Basic Flex SDK Example
As a starting point, I decided to go with the "RAIL: Simple RAIL without HAL" example from the Flex SDK.
You can find this by expanding the list of projects under the "Silicon Labs Flex SDK Examples" link:
Then find and click the example shown in Figure 3 to add it to your workspace:
After the example loads on your workspace, you might get a notice as shown in Figure 4. Just click "OK".
You will then be presented with simple_rail_without_hal.isc opened where you can configure RAIL. In my case, I left everything in its default values and simply clicked on "Generate" as shown in Figure 5.
At this point, you should now be set with a basic Flex Gecko example that builds and runs. However, I did find that the default project settings have compiler optimization set to "Optimize for size (-Os)" which will eventually make debugging the project rather difficult. Therefore, I switched optimizations to "None (-O0)".
Adding Micrium OS to the Workspace
Now that you have a basic Flex Gecko example that builds and runs, let's go ahead and start adding the Micrium OS source files into the workspace.
First, locate the Micrium OS directory, it should be in:
Now drag and drop the "micrium_os" folder into your project (simple_rail_without_hal) in Simplicity Studio. When doing this, make sure that you have "Copy files and folders" selected before clicking "OK" as shown in Figure 7.
You will then have to remove all the unnecessary files that get added with Micrium OS (this was tedious).
Here's how your "micrium_os" folder should end up looking:
Finally, the compiler needs to know where to look for the header files so we have to add two compiler include paths to the project settings:
Configuring Micrium OS
Now that you have Micrium OS as part of your project, let's go ahead and make some minor adjustments to the default Micrium OS configuration.
Modifying main.c
We'll be making modifications to the default main.c generated by the "RAIL: Simple RAIL without HAL" example.
Micrium OS requires the following include paths in main.c so go ahead and add them as shown below:
We'll be modifying main.c to initialize Micrium OS and create a start task. For that, you'll need to specify a task stack size and a priority. We typically do this by defining them as constants and passing those in the call to OSTaskCreate().
The start task also requires its own Stack and Task Control Block (OS_TCB) as well as its function prototype. Therefore, add the following to main.c:
Here's the body of the StartTask function where the kernel tick gets initialize and as well as the Common module. Note that the function includes an infinite loop at the end with a time delay of 1 second. This is done to yield CPU time to other tasks that are or will eventually run on your system. You can copy and paste the following in your main.c:
Let's now modify main() to initialize the CPU, the kernel create the Start Task, and start the OS. Here's how main() should end up looking:
Finally, since Micrium OS makes use of an assembly-optimized memory copy function, you must enable it in common_cfg.h
You are now set to build and run the project. You can put a breakpoint on the Start Task inside the while loop and notice that you'll be hitting that every second (or as specified by the delay you configure in OSTimeDly()).
Please do understand that this is a very basic guide that resembles more a hack rather than an official solution from Silicon Labs. Hopefully, Micrium OS can be part of the Flex SDK in the future, but in the meantime, this is a start.
I hope this was useful to you. Feel free to post any comments or questions regarding this blog post.
Hi! Thank you for this awesome post! But I have two questions:
1.- I see you have deleted a lot of files regarding I/O and BSP and so on in Micrium OS files, if I need to use those functionalities I should just keep those files, right?
2.- You are using Simple RAIL without HAL, but if I want to use HAL (for example, to shutdown EEPROM*), I could use RAIL with HAL and follow the same steps, right?
* Some components are under Connect (SPI-Flash, Serial, Micrium OS), does it mean that if I select them I need to use Connect? Or are those components not really linked with Connect?
EDIT: This project doesn't work anymore with Flex >= 2.7.1 and Micrium OS >= 5.8.1. I am looking for a solution since I want to use RAIL + RTOS and not Connect + RTOS.
The previous post is discussed at https://www.silabs.com/community/wireless/proprietary/forum.topic.html/adding_micrium_ostorail-3zmq
Here's a project on the MG12 using version 2.7 of the SDK:
Hi, Janos,
I debugged the MG12 code you attached above, but it can't jump in startTask.
Can you help to porting the code simple_rail_with_hal to MG22 or BG22 (BRD4182A)platform?
Thanks!
Hi Wei,
I've attached a clean main.c. I noticed that optimizations were turned on in your project so this probably made it difficult for you to pin-point where the issue was. I noticed 2 things:
#if (OS_CFG_STAT_TASK_EN == DEF_ENABLED)
// Initialize CPU Usage.
//OSStatTaskCPUUsageInit(&err);
// Check error code.
APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), ;);
#endif
The code was getting stuck in that ASSERT when I switched optimizations off. Then I remove this section of code from both tasks since it's not being used.
The second thing that I noticed was that the Common module was being reinitialized in the UserTask.
I turned optimizations back on after cleaning up main.c and I see both tasks running fine now.
Regards,
Janos
I have attempted to follow the guide without success.
I am using the latest available MCU SDK(5.9.6.0), Mircrium OS(5.6.0) Flex(2.7.6). Hardware is an EFR32MG12 and radio boards are actually the same (BRD4001A).
I an wondering why all this, altough I only just came across it I found AN1134: "Dynammic Multiprotocol..." which seemingly uses both BLE and RAIL and includes Mircrioum OS. So what am I missing? can't I take that and hollow out the BLE part? Why do I need to go into all this manual work and file removal?
I am mainly asking this to avoid wasting more houres to get this combination working.
Thank you
Hi David,
Have you tried the updated project that I uploaded a few replies back?
Hi Janos,
To be honset not sure now is was a while back.
I will have to get back to it as I do need it and report. I assumeyou refer to yout post with "Here's a project on the MG12 using version 2.7 of the SDK:" ?
That being said I am still puzzled regarding possible use of AN1134, was my question not valid?
Hi Janos,
To be honset not sure now is was a while back.
I will have to get back to it as I do need it and report. I assumeyou refer to yout post with "Here's a project on the MG12 using version 2.7 of the SDK:" ?
That being said I am still puzzled regarding possible use of AN1134, was my question not valid?