Quality RTOS & Embedded Software

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


Loading

IAR 78K0R port: random reboots

Posted by justdanpo on March 5, 2015

I've just fixed a bug very hard to find. IAR 78K0R port uses configMEMORYMODE to detect if ES register should be saved/restored on a context switch. The problem occurs when a project has near data model and far code model with a code placed in several 64K pages. As data model is near, configMEMORYMODE should be set to 0. But a function exit code generated by IAR uses far data pointers. These pointers are used to retrieve how much function arguments should be removed from a stack. When some task goes to a background inside a function exit code and another task or interrupt handler changes ES register, stack pointer of the first task becomes invalid. To fix this issue portSAVECONTEXT and portRESTORECONTEXT in addition to configMEMORY_MODE should check the code model. But I'd rather always save ES register even when both code and data models are near.


IAR 78K0R port: random reboots

Posted by rtel on March 5, 2015

Thanks for taking the time to report this. I would be grateful if you could attach the updated port layer file so we can ensure we understand the fix correctly.

Regards.


IAR 78K0R port: random reboots

Posted by justdanpo on March 6, 2015

FreeRTOSSourceportableIAR78K0RISR_Support.h

portSAVE_CONTEXT macro

Original code:

~~~~~~

if configMEMORY_MODE == 1
MOV       A, CS                 ; Save CS register.
XCH       A, X
MOV       A, ES                 ; Save ES register.
PUSH      AX
else
MOV       A, CS                 ; Save CS register.
PUSH      AX
endif

~~~~~~

For those who count each instruction cycle:

~~~~~

if defined(FAR_MODEL) || (configMEMORY_MODE == 1)
MOV       A, CS                 ; Save CS register.
XCH       A, X
MOV       A, ES                 ; Save ES register.
PUSH      AX
else
MOV       A, CS                 ; Save CS register.
PUSH      AX
endif

~~~~~

__FARMODEL_ is a macro defined in assembler preprocessor options (just like __NEARMODEL_ in original demo project FreeRTOSDemoNEC78K0RIAR). Also the condition (configMEMORYMODE == 1) may be replaced by defined(_FARDATAMODEL__).

The code I use at this moment:

~~~~~ MOV A, CS ; Save CS register. XCH A, X MOV A, ES ; Save ES register. PUSH AX ~~~~~

I don't care about 2 extra instructions for each save/restore context. Also some of my projects, which use NEAR code and data models, use far pointers (to access flash memory for example) so conditional compilation may also cause a bug.

portRESTORE_CONTEXT macro should be changed by the same way.


IAR 78K0R port: random reboots

Posted by justdanpo on October 1, 2015

OK, here is the file

Attachments

ISR_Support.h (5397 bytes)


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


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

Latest News

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

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

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


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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