Silicon Labs
|
Silicon Labs Community Silicon Labs Community
  • Products
    1. 8-bit MCU
    2. 32-bit MCU
    3. Bluetooth
    4. Proprietary
    5. Wi-Fi
    6. Zigbee & Thread
    7. Z-Wave
    8. Interface
    9. Isolation
    10. Power
    11. Sensors
    12. Timing
  • Development Tools
    1. Simplicity Studio
    2. Third Party Tools
  • Expert's Corner
    1. Announcements
    2. Blog
    3. General Interest
    4. Projects
How to Buy
English
  • English
  • 简体中文
  • 日本語
//
Community // Blog

This discussion and its replies are closed

Adding Micrium OS on a Flex Gecko

06/159/2018 | 10:05 PM
Janos Magasrevy
Employee

Level 5


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:

  • 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:

C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v2.5\platform\micrium_os

 

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:

"${workspace_loc:/${ProjName}/micrium_os}"
"${workspace_loc:/${ProjName}/micrium_os/cfg}"
Figure 9 - Micrium OS Compiler Include Paths

 

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.

  1. Open rtos_description.h located in your project under "micrium_os/cfg/"
  2. 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:

#define  START_TASK_PRIO              21u
#define  START_TASK_STK_SIZE         512u
                                                                
static  CPU_STK  StartTaskStk[START_TASK_STK_SIZE];  /* Start Task Stack. */
static  OS_TCB   StartTaskTCB;                       /* Start Task TCB.   */

static  void  StartTask (void  *p_arg);

 

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:

static  void  StartTask (void  *p_arg)
{
  RTOS_ERR    err;
  CPU_INT32U  cpu_freq;
  CPU_INT32U  cnts;

  // Prevent compiler warning.
  PP_UNUSED_PARAM(p_arg);                                     

  // Determine SysTick reference freq.
  cpu_freq =  SystemCoreClockGet();
  // Cal. SysTick counts between two OS tick interrupts.
  cnts     = (cpu_freq / (CPU_INT32U)KAL_TickRateGet());

  // Init uC/OS periodic time src (SysTick).
  OS_CPU_SysTickInit(cnts);

#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

#ifdef CPU_CFG_INT_DIS_MEAS_EN
  // Initialize interrupts disabled measurement.
  CPU_IntDisMeasMaxCurReset();
#endif

  // Call common module initialization example.
  Common_Init(&err);
  APP_RTOS_ASSERT_CRITICAL(err.Code == RTOS_ERR_NONE, ;);

  while (DEF_ON) {
	  // Delay Start Task execution for 1000 OS Ticks from now.
      OSTimeDly(1000, OS_OPT_TIME_DLY, &err);
      // Check error code.
      APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), ;);
  }
}

 

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:

int main(void)
{
  RTOS_ERR  err;

  CHIP_Init();
  initRadio();

  CPU_Init();

  // Initialize the Kernel.
  OSInit(&err);
  // Check error code.
  APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), 1);

  // Create the Start Task.
  OSTaskCreate(&StartTaskTCB,
               "Start Task",
                StartTask,
                DEF_NULL,
                START_TASK_PRIO,
               &StartTaskStk[0],
               (START_TASK_STK_SIZE / 10u),
                START_TASK_STK_SIZE,
                0u,
                0u,
                DEF_NULL,
               (OS_OPT_TASK_STK_CLR),
               &err);
  // Check error code.
  APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), 1);

  // Start the kernel.
  OSStart(&err);
  // Check error code.
  APP_RTOS_ASSERT_DBG((RTOS_ERR_CODE_GET(err) == RTOS_ERR_NONE), 1);

  return (1);
}

Finally, since Micrium OS makes use of an assembly-optimized memory copy function, you must enable it in common_cfg.h

#define  LIB_MEM_CFG_MEM_COPY_OPTIMIZE_ASM_EN    DEF_ENABLED

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
  • Divyesh Tilava

    Level 3


    Replied Jun 25 2019, 12:09 PM
    How to add this os for Mighty Gecko module.@Janos Magasrevy
    0
  • Roger Nicolas Alegret

    Level 4


    Replied Apr 14 2020, 1:31 PM

    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.

    0
  • tanagy
    Employee

    Level 7


    Replied Apr 20 2020, 3:04 PM

    The previous post is discussed at https://www.silabs.com/community/wireless/proprietary/forum.topic.html/adding_micrium_ostorail-3zmq

     

    0
  • Janos Magasrevy
    Employee

    Level 5


    Replied Apr 20 2020, 8:21 PM

    Here's a project on the MG12 using version 2.7 of the SDK:

     

    simple_rail_without_hal.sls
    0
  • Wei Zhao
    Employee

    Level 3


    Replied Jun 23 2020, 5:52 AM

    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!

    0
  • Janos Magasrevy
    Employee

    Level 5


    Replied Jun 25 2020, 5:37 PM

    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

     

    clean_main.c
    0
  • david Artzy

    Level 3


    Replied Jul 28 2020, 10:09 AM

    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
  • Janos Magasrevy
    Employee

    Level 5


    Replied Aug 07 2020, 3:01 PM

    Hi David,

    Have you tried the updated project that I uploaded a few replies back?

    0
  • david Artzy

    Level 3


    Replied Aug 24 2020, 10:26 AM

    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
  • david Artzy

    Level 3


    Replied Aug 24 2020, 10:26 AM

    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
  • 1
  • 2
Next

Tags

  • Wireless
  • High Performance Jitter Attenuators
  • EFR32FG22 Series 2 SoCs
  • EFR32MG21 Series 2 SoCs
  • Security
  • Bluegiga Legacy Modules
  • Zigbee SDK
  • ZigBee and Thread
  • EFR32BG13 Series 1 Modules
  • Internet Infrastructure
  • Sensors
  • Wireless Xpress BGX13
  • Blue Gecko Bluetooth Low Energy SoCs
  • Z-Wave
  • Micrium OS
  • Blog Posts
  • Low Jitter Clock Generators
  • Bluetooth Classic
  • Makers
  • Flex SDK
  • Tips and Tricks
  • timing
  • Smart Cities
  • Smart Homes
  • IoT Heroes
  • Reviews
  • RAIL
  • Simplicity Studio
  • Tiny Gecko
  • EFR32MG22 Series 2 SoCs
  • Mighty Gecko SoCs
  • Timing
  • Temperature Sensors
  • Blue Gecko Bluetooth Low Energy Modules
  • Ultra Low Jitter Clock Generators
  • General Purpose Clock Generators
  • EFR32BG22 Series 2 SoCs
  • Industry 4.0
  • Giant Gecko
  • 32-bit MCUs
  • Bluetooth Low Energy
  • 32-bit MCU SDK
  • Gecko
  • Microcontrollers
  • Jitter Attenuators
  • EFR32BG21 Series 2 SoCs
  • News and Events
  • Industrial Automation
  • Wi-Fi
  • Bluetooth SDK
  • Community Spotlight
  • Clock Generators
  • Biometric Sensors
  • General Purpose Jitter Attenuators
  • Giant Gecko S1
  • WF200
  • Flex Gecko
  • Internet of Things
  • 8-bit MCUs
  • Wireless Jitter Attenuators
  • Isolation
  • Powered Devices
  • Power

Top Authors

  • Avatar image Siliconlabs
  • Avatar image Jackie Padgett
  • Avatar image Nari Shin
  • Avatar image lynchtron
  • Avatar image deirdrewalsh
  • Avatar image Lance Looper
  • Avatar image lethawicker

Archives

  • 2016 January
  • 2016 February
  • 2016 March
  • 2016 April
  • 2016 May
  • 2016 June
  • 2016 July
  • 2016 August
  • 2016 September
  • 2016 October
  • 2016 November
  • 2016 December
  • 2017 January
  • 2017 February
  • 2017 March
  • 2017 April
  • 2017 May
  • 2017 June
  • 2017 July
  • 2017 August
  • 2017 September
  • 2017 October
  • 2017 November
  • 2017 December
  • 2018 January
  • 2018 February
  • 2018 March
  • 2018 April
  • 2018 May
  • 2018 June
  • 2018 July
  • 2018 August
  • 2018 September
  • 2018 October
  • 2018 November
  • 2018 December
  • 2019 January
  • 2019 February
  • 2019 March
  • 2019 April
  • 2019 May
  • 2019 June
  • 2019 July
  • 2019 August
  • 2019 September
  • 2019 October
  • 2019 November
  • 2019 December
  • 2020 January
  • 2020 February
  • 2020 March
  • 2020 April
  • 2020 May
  • 2020 June
  • 2020 July
  • 2020 August
  • 2020 September
  • 2020 October
  • 2020 November
  • 2020 December
  • 2021 January
Silicon Labs
Stay Connected With Us
Plug into the latest on Silicon Labs products, including product releases and resources, documentation updates, PCN notifications, upcoming events, and more.
  • About Us
  • Careers
  • Community
  • Contact Us
  • Corporate Responsibility
  • Privacy and Terms
  • Press Room
  • Investor Relations
  • Site Feedback
  • Cookies
Copyright © Silicon Laboratories. All rights reserved.
粤ICP备15107361号
Also of Interest:
  • Bring Your IoT Designs to Life with Smart,...
  • IoT Hero CoreTigo Drives New Wireless Standard...
  • A Guide to IoT Protocols at Works With...