k1mgy wrote on Wednesday, November 08, 2017:
Version 8.0.0
ATSAMG55 J19 (taget: G55 xPlained)
Atmel Studio 7
Description:
App consists of 6 xTaskCreate() tasks. One task - CmdProc - polls a touch screen (SPI). Another - TouchPa - processes result of touch screen touch result value (button control on LCD).
TheTouchPa process takes about 10 seconds to complete. It includes starting up a fan through GPIO, and reading ADC. The process then enables an ADC timer event that runs for (n) seconds according to the utilTim process (which keeps track of elapsed seconds, like a stopwatch).
First time through, everything works fine. Second time TouchPa triggers a hard fault.
Before starting I see the following results in the task monitor:
--- task ## 8Monitor R 0 179 1
IDLE R 0 78 7
TouchPa B 1 226 2
ScreenU B 2 176 4
CmdProc B 3 218 5
Tmr Svc B 2 44 8
utilTim S 0 245 6
adc_con S 4 245 3
After the process completes, I see the following results in the task monitor:
--- task ## 8Monitor R 0 57 1
IDLE R 0 78 7
CmdProc B 3 97 5
ScreenU B 2 97 4
TouchPa B 1 62 2
Tmr Svc B 2 44 8
adc_con S 4 228 3
utilTim S 0 183 6
If I then kick off the process for a second time, my hard fault handler is hit.
[Hard fault handler - all numbers in hex]
R0 = 20000f00
R1 = 20000b60
R2 = 200045f8
R3 = 200045f8
R12 = a5a5a5a5
LR [R14] = 0 subroutine call return address
PC [R15] = 0 program counter
PSR = 4000000e
BFAR = e000ed38
CFSR = 20000
HFSR = 40000000
DFSR = 0
AFSR = 0
SCB_SHCSR = 400
The PC of 0 is interesting…
I note that some tasks show a reduction in available stack space after they run for the first time. Namely:
--- task ## 8Monitor R 0 57 1
IDLE R 0 78 7
TouchPa B 1 226 2 **62 2**
ScreenU B 2 174 4 **97 4**
CmdProc B 3 218 5 **97 5**
Tmr Svc B 2 44 8
utilTim S 0 245 6 **183 6**
adc_con S 4 245 3 **228 3**
I’m not doing any mallocs in my code. I suspect the crash is occurring because the TouchPa process runs out of stack.
The original setting is:
#define TOUCHPARSE_TASK_PRIORITY ( configMAX_PRIORITIES - 4 )
#define TOUCHPARSE_STACK_SIZE (1024/sizeof(portSTACK_TYPE))
I increased the stack size to
#define TOUCHPARSE_TASK_PRIORITY ( configMAX_PRIORITIES - 4 )
#define TOUCHPARSE_STACK_SIZE (2048/sizeof(portSTACK_TYPE))
…and now the process runs a second time. However I get another crash with the system in an idle (polling the touch screen) state.
Questions:
- I have no idea what a safe low-water mark is for stack remaining. Given the numbers above, any suggestions?
- Is #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 15000 ) ) sufficient?
- Is there a way to determine what actually triggers the fault? With a PC of 0, it seems hopeless. I thought the vApplicationMallocFailedHook or vApplicationStackOverflowHook would trigger. They don’t.