Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


MSP430 IAR Compiler - FreeRTOS issue

Posted by ammamon on March 11, 2011
I have written an rtc module for MSP430 device which captures date/time every one minute. This module uses freertos queue for sending the date/time event to another task. Though the time date-time details are captured every one minute, one or more of the details (either year, month, hour or ..) are getting corrupted depending upon whether the code optimization is set or not and whether the event object (ui_queue_event variable in the code below into which RTC time details are loaded ) is declared static or local in the interrupt function.

Actually there are 4 test cases.
1. Optimization set to none and time receiving event object declared local.
2. Optimization set to a value and time receiving event object declared local.
3. Optimization set to none and time receiving event object declared static.
4. Optimization set to a value and time receiving event object declared static.

The time data is corrupted consistently for each of the above 4 cases. In one case, it may be year corruption, in another case it may be hour corruption and so on. All the time details may be consistently correct for one of the cases. The pattern of corruption remained the same as long as the code is IAR compiled on a particular system. But if I compile the code in another system, the pattern of corruption for the above 4 cases differs. I tried compiling the code on 3 different systems running version of IAR MSP430 compiler.

Another point is the I am getting the "second" always as zero even when if I set it to a value during initialization of RTC module.

Can this be a stack problem? I am not getting any stack overflow error messages while debugging. Or is FreeRTOS creating problems here? Please help.

I am listing below the rtc code and the test code.

RTC Module code

#include "rtc.h"
#include "FreeRTOS.h"
#include "queue.h"

extern xQueueHandle ui_queue;

void rtc_set_date(rtc_date_struct_t *new_date)
RTCYEAR = new_date->year;
RTCDOW = new_date->dow;
RTCMON = new_date->month;
RTCDAY = new_date->dom;
RTCHOUR = new_date->hour;
RTCMIN = new_date->min;
RTCSEC = new_date->sec;
__enable_interrupt(); /* Sets GIE in status register */

#pragma vector=RTC_VECTOR
__interrupt void handle_rtc_interrupt(void)
ui_event_struct_t ui_queue_event;
case 2U: /* RTC Ready Event */
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

ui_queue_event.event_type = UI_QUEUE_EVENT_ONE_MIN_RTC;
ui_queue_event.year = RTCYEAR;
ui_queue_event.month = RTCMON;
ui_queue_event.dom = RTCDAY;
ui_queue_event.dow = RTCDOW;
ui_queue_event.hour = RTCHOUR;
ui_queue_event.minute = RTCMIN;
ui_queue_event.sec = RTCSEC;
xQueueSendFromISR(ui_queue, (void *) &ui_queue_event, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
case 4U: /* RTC Minute Interval Event */
RTCCTL01 |= RTCRDYIE; /* Enable Ready Flag Interrupt */
__no_operation(); /* For debugger */
RTCIV &= 0x00U;

Test Code:

#include "msp430F5419.h"
#include "global.h"
#include "rtc.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"

xQueueHandle ui_queue;
static void event_listener_ui_task (void * params);
static void ui_client_requests_task(void * params);

int16_t main(void)
ui_queue = xQueueCreate( 10, sizeof(ui_event_struct_t) );
xTaskCreate (ui_client_requests_task, (const signed portCHAR * const) "UI Client Requests Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
xTaskCreate (event_listener_ui_task, (const signed portCHAR * const) "Event Listener UI Task", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
return 0;


static void ui_client_requests_task( void * pvParameters )
static rtc_date_struct_t date;
date.year = 2011U;
date.month = 2U;
date.dom = 8U;
date.dow = 2U;
date.hour = 11U;
date.min = 16U;
date.sec = 30U;
while (1==1)
//infinite loop

static void event_listener_ui_task( void * pvParameters)
static ui_event_struct_t ui_queue_event;
while( 1==1)
portBASE_TYPE receive_status = xQueueReceive(ui_queue, &ui_queue_event, portMAX_DELAY);
assert(pdPASS == receive_status);
assert(ui_queue_event.event_type == UI_QUEUE_EVENT_ONE_MIN_RTC);
printf("%i,", ui_queue_event.year);
printf("%i,", ui_queue_event.dom);
printf("%i,", ui_queue_event.dow);
assert(ui_queue_event.year == 2011U);
assert(ui_queue_event.month == 2U);
assert(ui_queue_event.dom == 8U);
assert(ui_queue_event.dow == 2U);
printf("%i,", ui_queue_event.hour);
printf("%i,", ui_queue_event.minute);
printf("%i\n", ui_queue_event.sec);


RE: MSP430 IAR Compiler - FreeRTOS issue

Posted by Dave on March 11, 2011
Which MSP430 port are you using? The brand new MSP430X port, the old MSP430 port, or a third party one?

I don't know much about this one, but the thing that sticks out in your code is the manipulation of the interrupt enable bits in the interrupt itself. That is probably dangerous for a port that does not support nesting. In fact doing it that way would be dangerous for a port that does support nesting. Have you tried removing the disable and enable calls from the interrupt handler, all of them? The disable probably does nothing anyway, and the enables are the dangerous ones.

RE: MSP430 IAR Compiler - FreeRTOS issue

Posted by Dave on March 11, 2011
Also, check you have stack overflow checking switched on.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.0 is available for immediate download. MIT licensed, and including RISC-V and ARMv8-M (Cortex-M33) demos.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner