Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 8, 2015

At the end of xPortStartScheduler(), the portRestoreContext is botching the stack frame for the first task to run. Somehow it is pulling a bad value for the CP0 Status register off the stack and corrupting several important bits including the CU1 fpu coprocessor enable bit. I don't observe any other problems with the first task; it starts up well and continues on to several other tasks, seemingly without a hitch. It does seem, though, if I restore the Status register manually after corruption, that it gets corrupted again at each call of portRestoreContext.

Here's what's at the ( UBaseType_t * ) pxCurrentTCB: a nice address = 0x80004F2C. The contents of this is, according to the memory view, is 0xA5A5A5A5. I know, not a valid value. The saved stack pointer, just before the call to portRestoreContext, is a different kind of invalid, I think:

uxSavedTaskStackPointer = *( UBaseType_t * ) pxCurrentTCB = 0x00000000 !

I don't know why this doesn't come up as the value 0xA5A5A5A5 that the memory view shows. But neither value seems valid as a stack pointer.

Any ideas as to the cause of this?

I've raised the configMAXSYSCALLINTERRUPTPRIORITY and configMAXPRIORITIES to relatively high levels. I'm trying to see whether any FreeRTOS API gets called before xPortStartScheduler(). Any other diagnostics?

Setup: the latest FreeRTOS v 8.x.x, shipping with MHC 1.06 for PIC32MZ EF family processors.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 8, 2015

Observations:

I do notice that OSALMUTEXCreate() is called by some third party code that I'm integrating into the project before xPortStartScheduler() is called. OSALUSERTOS is defined as 1. I don't think this is a problem. Or do I need to rewrite it to use a FreeRTOS semaphore or mutex?

I also see that when the first task is actually called, it is NOT the highest priority task.

Problem?


portRestoreContext clobbers PIC32MZ EF Status register

Posted by rtel on September 8, 2015

The EF parts are not supported yet - but will be soon.

Regards.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 8, 2015

Further observations:

I eliminated everything nonessential. At main(), I create a system task, then start the scheduler. That's all. The Status Register comes back corrupted after portRestoreContext, to the system task.

Must be a configuration setting somewhere.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by rtel on September 8, 2015

Please see my reply to your original post. EF parts are not supported yet, but will be soon.

Regards.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 8, 2015

Oh my.

No wonder. The Harmony release notes make no mention of this. I'll have to put out a word on the Harmony forum.

Any idea of how soon the EF parts will be supported?


portRestoreContext clobbers PIC32MZ EF Status register

Posted by rtel on September 8, 2015

The work is already in progress, but I'm afraid I can't put a date on it yet.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 8, 2015

Thanks, just saw it, responded, and put out a note on the Microchip Harmony forum.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by iberoxarxa on September 17, 2015

From Iberoxarxa we got the first results with Lua 5.3.1 running on FreeRTOS on PIC32MZ2048EFH064. MZ ports have been modified to achieve this:

  • CP0 status is initialized in pxPortInitialiseStack. portINITIALSR is invalid for this silicon, because it sets CU1 to 0 disabling the FPU. It is mandatory to apply 0x20000000 mask to portINITIALSR for enabling FPU.

  • FPU registers are 64 bit wide. There are 32 registers ($f0 to $f31). This registers must saved and restore in portSAVECONTEXT, portRESTORECONTEXT and vPortYieldISR. For this use sdc1 / ldc1 MIPS instruction. Be careful with that, so sdc1 / ldc1 requires a 8 word alignment stack. Changes in pxPortInitialiseStack are required for this.

  • FPU has 4 control registers. Register FCSR must be saved / restored in portSAVECONTEXT, portRESTORECONTEXT and vPortYieldISR.

Doing this our project: FreeRTOS + Lua 5.3.1 + Lwip runs.

Attached you have the modified port files. Probably all is not fine with our work. More tests are needed. We hope that this modifications will be useful for FreeRTOS team.

You must put "#define configUSE_FPU 1" in your FreeRTOSConfig.h file.

Attachments

ef-parts.zip (17085 bytes)

portRestoreContext clobbers PIC32MZ EF Status register

Posted by iberoxarxa on September 17, 2015

isr stack must be 8 byte alignment. This is done putting this in port.c:

if( configUSE_FPU == 1 )

const StackTypet * const xISRStackTop = &( xISRStack[ configISRSTACK_SIZE - 8 ] );

else

const StackTypet * const xISRStackTop = &( xISRStack[ configISRSTACK_SIZE - 7 ] );

endif

With this (and previous post) FreeRTOS inour project is stable. 3 hours running, responding to ping, and executing Lua scripts without any problem.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by tlafleur on September 17, 2015

Also, will you be posting your LUA project core?

~~ _/) ~~~~ _/) ~~~~ _/) ~~~~ _/) ~~

On Sep 17, 2015, at 6:20 AM, Jaume Olivé Petrus iberoxarxa@users.sf.net wrote:

isr stack must be 8 byte alignment. This is done putting this in port.c:

if( configUSE_FPU == 1 )

const StackTypet * const xISRStackTop = &( xISRStack[ configISRSTACK_SIZE - 8 ] );

else

const StackTypet * const xISRStackTop = &( xISRStack[ configISRSTACK_SIZE - 7 ] );

endif

With this (and previous post) FreeRTOS inour project is stable. 3 hours running, responding to ping, and executing Lua scripts without any problem.

portRestoreContext clobbers PIC32MZ EF Status register

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/


portRestoreContext clobbers PIC32MZ EF Status register

Posted by tlafleur on September 17, 2015

You may want to consider using the pre define macro to wrap you changes

define _PIC32FEATURE_SET "EF"

i~~ _/) ~~~~ _/) ~~~~ _/) ~~~~ _/) ~~i

Tom Lafleur (858) 759-9692

On Sep 17, 2015, at 2:26 AM, Jaume Olivé Petrus iberoxarxa@users.sf.net wrote:

From Iberoxarxa we got the first results with Lua 5.3.1 running on FreeRTOS on PIC32MZ2048EFH064. MZ ports have been modified to achieve this:

CP0 status is initialized in pxPortInitialiseStack. portINITIALSR is invalid for this silicon, because it sets CU1 to 0 disabling the FPU. It is mandatory to apply 0x20000000 mask to portINITIALSR for enabling FPU.

FPU registers are 64 bit wide. There are 32 registers ($f0 to $f31). This registers must saved and restore in portSAVECONTEXT, portRESTORECONTEXT and vPortYieldISR. For this use sdc1 / ldc1 MIPS instruction. Be careful with that, so sdc1 / ldc1 requires a 8 word alignment stack. Changes in pxPortInitialiseStack are required for this.

FPU has 4 control registers. Register FCSR must be saved / restored in portSAVECONTEXT, portRESTORECONTEXT and vPortYieldISR.

Doing this our project: FreeRTOS + Lua 5.3.1 + Lwip runs.

Attached you have the modified port files. Probably all is not fine with our work. More tests are needed. We hope that this modifications will be useful for FreeRTOS team.

You must put "#define configUSE_FPU 1" in your FreeRTOSConfig.h file.

Attachments:

ef-parts.zip (17.1 kB; application/zip) portRestoreContext clobbers PIC32MZ EF Status register

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/


portRestoreContext clobbers PIC32MZ EF Status register

Posted by iberoxarxa on September 17, 2015

Project will be release to general public before December 31, 2015.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by pbjork on September 21, 2015

I have been informed by Microchip staff that PIC32MZ EF support for FreeRTOS should be included in the next MHC Harmony release, 1.0.7. Not sure of the release date nor that RTEL concurs, however.


portRestoreContext clobbers PIC32MZ EF Status register

Posted by rtel on September 21, 2015

Yes - concur with that. Hopefully we will be able to provide it as a separate download prior to that.

Regards.


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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists