Question
fp issue: vstm/vldm all 32 fp registers at once
Posted on August 12, 2016 at 01:09
A few details: both code and data caches are enabled. 216MHz SysClk. Timer ISR schedules a task every millisecond. SCB.SHCSR=1<<18 to enable use of usage fault ISR for the fp trap handler. All ISR’s mentioned are set to the absolute minimum priority as is the SVC used for task entry to the task scheduler.
In my own selected tasks have access to all floating point registers. I elected to not provide fp access to ISR’s. Every time any task is scheduled floating point access is disabled:mov32 r0,baseSCB+CPACR<
br
>
movs r1,#0<
br
>
str r1,[r0] ;disable fp<
br
>
Then when a task attempts to use floating point the code traps. After a sanity check fp access is enabled. The trap handler checks if the current fp registers “belong�? to the task. If not, the existing fp context is copied to the proper task’s fp save area:
vmrs r0,FPSCR<
br
>
stm r5!,{r0}<
br
>
vstm r5!,{s0-s31}<
br
>
Then the trap handler restores the saved fp registers for the task that initially caused the trap:
ldm r5!,{r0}<
br
>
vldm r5!,{s0-s31}<
br
>
vmsr FPSCR,r0<
br
>
This code
works on STM32F4 parts. It
fails on the STM32F746 DISCOVERY board. The crash entered the fp trap handler with an error flag indicating an attempt to execute an instruction that makes illegal use of the EPSR. Possibly a bad EXC_RETURN?
I suspected that the
32-word vstm/vldmmight be a problem. For debug I changed the vstm/vldm to store/load only s0-s3.
That worked in that it did not crash. But my RTOS needs to save and restore all fp registers.
I’m software so this has to be a hardware problem. Is this a known deficiency? (It’s not in the latest STM32F74xxx STM32F75xxx Errata sheet. Ditto ARM’s errata.) Is there a workaround?
#stm32f7-floating-point