pblase wrote on Thursday, November 22, 2018:
Working on an Atmel ATSAMC21N-XPRO demo board (ATSAMC21N18A processor), using Atmel Studio with the GNU tools, FreeRTOS rev 10.0.0 as per the Atmel START web utility. The main program is written in C++, with the files copied over from a separate project created by the START utility (which uses ASF 4 and only works with C; however all files have the proper
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
surrounding them and compile fine. I’ve had similar code running before, without FreeRTOS, and it seems to work fine.
In the main program file, there’s the instantiation of a class
Heartbeat_LED_task_t Heartbeat_LED_timer;
In the .map file, this ends up right below the FreeRTOS stuff:
.bss 0x200004d0 0x20 ProElec_R2_ATSAMC21N.o
0x200004d0 ErrorInfo
0x200004d4 retval
0x200004d8 Heartbeat_LED_timer <===
.bss 0x200004f0 0x968 thirdparty/RTOS/freertos/FreeRTOSV10.0.0/Source/portable/MemMang/heap_1.o
.bss 0x20000e58 0xec thirdparty/RTOS/freertos/FreeRTOSV10.0.0/Source/tasks.o
0x20000e58 pxCurrentTCB
.bss 0x20000f44 0x3c thirdparty/RTOS/freertos/FreeRTOSV10.0.0/Source/timers.o
So far so good.
The task that uses Heartbeat_LED_timer executes its loop once every 10th second and then uses
vTaskDelayUntil(&xLastWakeTime, pdMS_TO_TICKS(HEARTBEAT_LOOP_ms)); //tenth second
to delay until the next .1 second mark.
While the program is sleeping, between calls, the FreeRTOS steps on it; pretty much any time that FreeRTOS uses a local variable, it ends up located inside of the above variables.
For instance, I used the data-change breakpoint to trace it and found:
Line 2016 of tasks.c is
UBaseType_t uxPendedCounts = uxPendedTicks; /* Non-volatile copy. */
which is in xTaskResumeAll(void).
When this executes, uxPendedCounts is located in the middle of Heartbeat_LED_timer!
Looking at the disassembly, uxPendedCounts is found at R7 + 4
(" 000063FC str r3, [r7, #4]")
Sure enough, R7 is pointing right to the middle of Heartbeat_LED_timer. R7 is set somehow in the setup for xTaskResumeAll().
( put a screenshot in the attached .zip file)
Obviously there’s a setting wrong somewhere, but I have no clue what it could be.