logo
CODEMBIT
Reliable software engineering partner
Home Blog Tools

Getting started with embOS and MSP430

By Toni Akkala, 14th of August, 2022
img

Overview

embOS RTOS from Segger has been under development since 1992 and states to be “the preferred RTOS choice for engineers in the embedded market.” (https://www.segger.com/products/rtos/embos/). It is optimized for the low memory usage with the support for virtually any core and compiler for faster time to market. I was already familiar with this RTOS but wanted to try it out with the MSP430 microcontroller (MCU) I used with FreeRTOS.

I downloaded a trial version of embOS for MSP430 and Code Composer Studio (CCS) from Segger. When using up to three tasks, there are no limitations in the trial version. Otherwise it has some execution time limit. The RTOS comes with a sample project for the MSP430F5659 MCU. This is quite similar than my MSP430FR5739 but it has much more memory, both ROM and RAM. Anyway, it should be quite trivial to port this project to my MCU.

Implementation

OS_StartLEDBlink application is used to flash LEDs from the tasks by using Board Support Package (BSP). I noticed that even though the demo has two tasks for flashing the LED, only the other one will flash the LED because BSP controls the LED port only if index is 0. And the other task was passing index 1 to BSP. So this might be a bug in the demo for this board. I modified the demo so that the other task is used to set the LED on and the other to off. Inter-Process Communication (IPC) is handled using task events. Each task will wait in turn until the other task sends a signal to indicate that it is time to proceed execution. Here is the implementation for these tasks:

static void SetTask(void) { OS_TASK_EVENT event; while (1) { event = OS_WaitEvent(1); if (event & 1) { BSP_SetLED(0); OS_Delay(500); OS_SignalEvent(1, &ClearTaskTCB); } } } static void ClearTask(void) { OS_TASK_EVENT event; OS_SignalEvent(1, &SetTaskTCB); while (1) { event = OS_WaitEvent(1); if (event & 1) { BSP_ClrLED(0); OS_Delay(500); OS_SignalEvent(1, &SetTaskTCB); } } }

Besides these modifications to the main, only RTOSInit_MSP430F5659.c file needed modifications. I renamed RTOSInit_MSP430F5659.c for the new MCU and fixed sources to include correct header file for my MCU. I also removed embosview settings from RTOSInit as I am not going to use that now. I used the same clock system initialization as with other demos for this MCU and changed the RTOS tick timer settings based on the clock system setup. Here is the code:

WDTCTL = WDTPW + WDTHOLD; /* Stop watchdog timer */ OS_IncDI(); /* Ensure, interrupts are disabled */ /* Write CS password before accessing other registers */ CSCTL0_H = 0xA5; /* 20 MHz clock, DCPRSEL=1, DCOFSEL=1 */ CSCTL1 = 0x0082u; /* Select DCO clock for ACLK, MCLK and SMCLK */ CSCTL2 = 0x0333u; /* No clock dividers for MCLK and SMCLK. Divide ACLK by 32 = 625 kHz */ CSCTL3 = 0x0500u; /* Reset CS password to prevent further access */ CSCTL0_H = 0x00u; /* Ensure the timer is stopped. */ TA0CTL = 0; /* Run the timer of the ACLK. */ TA0CTL = TASSEL_1; /* Set the compare match value according to the tick rate we want. */ TA0CCR0 = 625 - 1; /* Enable the interrupts. */ TA0CCTL0 = CCIE; /* Up mode. */ TA0CTL |= MC_1;

Building

Finally, MCU type was changed in build settings and old linker file was removed. After this, I could build the project without problems:

Build results

Debugging

Here is the view while debugging with the MSP-FET debugger. When using three embOS tasks, I was using almost all available RAM memory, that is over 900 bytes:

Debugging the code

Of course, this was using the default stack size from the demo. CPU & Compiler specifics for Texas Instruments MSP430 CPUs using TI Code Composer document (UM01056) specifies that the minimum task stack size is around 30 bytes but 128 bytes is recommended. Knowing that the integer data type int is 16 bits, it was obvious that this demo was consuming extra memory, twice as much as it should. I changed the task stack array size to 64 for both tasks.

/* Task stacks */ static OS_STACKPTR short SetTaskStack[64], ClearTaskStack[64];

After these changes, the compilation was using only 667 bytes. That is even less than I had with the FreeRTOS in the other posts.

Conclusion

I was surprised how easy it was to port existing demo application to other MCU. With embOS, you don’t need to see the trouble of porting context switch stuff and such to other MCU like you have to do with FreeRTOS. But of course, you need to pay something if you like to use this RTOS without limitations.

References: