Stack destroyed after return from long vTaskDelay

Hi
I’m struggling with some problem. after return from vTaskDelay task stack is destroyed. I wrapped vTaskDelay and check sp (cortex R5). What I see is that SP is not(!) between between pxStack and pxTopOfStack as I would expect. Task defined as static task.
Need some fresh idea?


Thanks

pxTopOfStack is updated at the time of context switch. So this may not be a problem. Can you check if SP is between pxStack and (pxStack + stack_size_in_bytes)? Are you facing any problem?

Hi
Good idea! as far as I can see stack size/depth is not stored in tcb. I added it to tcb.
I my goal it to figure out where stack corruption takes place before and during sleep. I have to do it in vTaskDelay wrapper, because any modification to application code changes whole picture.
I’ll keep you posted.
Rasty

be aware, though, that the corruption of your sp may be a symptom of something that happens at a completly different place in the system (for example, something overtrampling memory that ends right before a sytem data structure whose corruption causes what you see as a side effect). If you can pinpoint a faulty write to a specific memory address as the culprit, your best strategy is a hardware breakpoint on that location.

As I said before, this may not be the case of SP corruption. Would you please describe the problem you are trying to solve? As @RAc mentioned, data breakpoints are very useful when trying to catch memory corruptions.

Hi
thanks for suggestions.
it is bit more complicated.
due to optimization , vtaskdelay inserted between preparing of argument (constant) in register and call itself
ld r10, constant_path – argument for fopen
vtaskdelay(const)
fopen(constant_path_in_r10)

sometimes r10 gets garbage in fopen.

hardware watchpoint does not help becase only register is corrupted , not memory.
i use trace.

i’ll keep you posted and add disassemble in the next reply.
thanks
rasty

OK.
I managed to put a break point and catch corrupted data (with fopen wrapper and simple if). What I see that after return from vTaskDelay register R7 is does not carry expected data. It is not direct memory corruption , because R9 is loaded from constant, before call to vTaskDelay.
I rule out instruction memory corruption - I checked opcodes, they match disassembly.


I cannot upload full instrcution trace because of account limitation.
Any fresh idea would be approciated.

Thanks
Rasty

97390,End of trace, Entered debug state when halting debug-mode is enabled,UNKNOWN,??:0
97389,0x8028763C,0x8A000007,97388,__wrap_fopen,newlib_locks.c:332
97388,0x80287638,0xE3730219,97387,__wrap_fopen,newlib_locks.c:332
97387,0x80287634,0xE51B3010,97386,__wrap_fopen,newlib_locks.c:332
97386,0x80287630,0xE50B1014,97385,__wrap_fopen,newlib_locks.c:331
97385,0x8028762C,0xE50B0010,97384,__wrap_fopen,newlib_locks.c:331
97384,0x80287628,0xE24DD010,97383,__wrap_fopen,newlib_locks.c:331
97383,0x80287624,0xE28DB004,97382,__wrap_fopen,newlib_locks.c:331
97382,0x80287620,0xE92D4800,97381,__wrap_fopen,newlib_locks.c:331
97381,0x80213850,0xEB01CF72,97380,cStatistics::SaveStatisticsTask(void*),Statistics.cpp:276
97380,0x8021384C,0xE1A00007,97379,cStatistics::SaveStatisticsTask(void*),Statistics.cpp:276
97379,0x80213848,0xE1A0100A,97378,cStatistics::SaveStatisticsTask(void*),Statistics.cpp:276
97378,0x70107AFE,0x0000BD30,97377,vTaskDelay,tasks.c:2479
97377,0x70107AFC,0x0000B003,97376,vTaskDelay,tasks.c:2479
97376,0x70100214,0xF8BD0A00,97375,HwiP_svc_handler,portASM.S:149
97375,0x70100210,0xE8BD5FFF,97374,HwiP_svc_handler,portASM.S:149
97374,0x7010020C,0xF57FF01F,97373,HwiP_svc_handler,portASM.S:149
97373,0x70100208,0x1EE10A10,97372,HwiP_svc_handler,portASM.S:149
97372,0x70100204,0x1CBD0B20,97371,HwiP_svc_handler,portASM.S:149
97371,0x70100200,0x149D0004,97370,HwiP_svc_handler,portASM.S:149
97370,0x701001FC,0xE3510000,97369,HwiP_svc_handler,portASM.S:149
97369,0x701001F8,0xE5801000,97368,HwiP_svc_handler,portASM.S:149
97368,0x701001F4,0xE49D1004,97367,HwiP_svc_handler,portASM.S:149
97367,0x701001F0,0xE59F0150,97366,HwiP_svc_handler,portASM.S:149
97366,0x701001EC,0xE591D000,97365,HwiP_svc_handler,portASM.S:149
97365,0x701001E8,0xE5901000,97364,HwiP_svc_handler,portASM.S:149
97364,0x701001E4,0xE59F0158,97363,HwiP_svc_handler,portASM.S:149
97363,0x70106250,0xE8BD8FF0,97362,vTaskSwitchContext,tasks.c:5140
97362,0x7010624E,0x0000B005,97361,vTaskSwitchContext,tasks.c:5140
97361,0x7010624A,0xF8CA3000,97360,vTaskSwitchContext,tasks.c:5126
97360,0x70106246,0xF8D33088,97359,vTaskSwitchContext,tasks.c:5126
97359,0x70106242,0xF8D93000,97358,vTaskSwitchContext,tasks.c:5126
97358,0x7010623E,0xF8D93000,97357,vTaskSwitchContext,tasks.c:5121
97357,0x7010623A,0xF8CB4000,97356,vTaskSwitchContext,tasks.c:5115
97356,0x70106236,0xF8C93000,97355,vTaskSwitchContext,tasks.c:5115
97355,0x70106234,0x000068DB,97354,vTaskSwitchContext,tasks.c:5115
97354,0x70106232,0x00006053,97353,vTaskSwitchContext,tasks.c:5115
97353,0x70106230,0x000068D3,97352,vTaskSwitchContext,tasks.c:5115
97352,0x7010622E,0x0000BF04,97351,vTaskSwitchContext,tasks.c:5115
97351,0x7010622C,0x000042B3,97350,vTaskSwitchContext,tasks.c:5115
97350,0x7010622A,0x00006053,97349,vTaskSwitchContext,tasks.c:5115
97349,0x70106228,0x0000685B,97348,vTaskSwitchContext,tasks.c:5115
97348,0x70106226,0x00006853,97347,vTaskSwitchContext,tasks.c:5115
97347,0x70106224,0x00003608,97346,vTaskSwitchContext,tasks.c:5115
97346,0x70106222,0x00004616,97345,vTaskSwitchContext,tasks.c:5115
97345,0x7010621E,0xEB060283,97344,vTaskSwitchContext,tasks.c:5115
97344,0x7010621C,0x00004423,97343,vTaskSwitchContext,tasks.c:5115
97343,0x70106218,0xF8DD900C,97342,vTaskSwitchContext,tasks.c:5115
97342,0x70106216,0x000000A3,97341,vTaskSwitchContext,tasks.c:5115
97341,0x70106214,0x0000464E,97340,vTaskSwitchContext,tasks.c:5115
97340,0x70106212,0x0000D0F2,97339,vTaskSwitchContext,tasks.c:5115
97339,0x70106210,0x00002B00,97338,vTaskSwitchContext,tasks.c:5115
97338,0x7010620C,0xF8553D14,97337,vTaskSwitchContext,tasks.c:5115
97337,0x802F068A,0x00004770,97336,_DebugP_assert,DebugP_log.c:92
97336,0x802F0688,0x0000B100,97335,_DebugP_assert,DebugP_log.c:92
97335,0x7015991C,0xE51FF004,97334,___DebugP_assert_from_arm,:?
97334,0x70106208,0xF053EB88,97333,vTaskSwitchContext,tasks.c:5115
97333,0x70106206,0x00003C01,97332,vTaskSwitchContext,tasks.c:5115
97332,0x70106204,0x00009600,97331,vTaskSwitchContext,tasks.c:5115
97331,0x70106202,0x00004639,97330,vTaskSwitchContext,tasks.c:5115
97330,0x70106200,0x00004642,97329,vTaskSwitchContext,tasks.c:5115
97329,0x701061FE,0x00004620,97328,vTaskSwitchContext,tasks.c:5115
97328,0x701061FA,0xF24133FB,97327,vTaskSwitchContext,tasks.c:5115
97327,0x70106212,0x0000D0F2,97326,vTaskSwitchContext,tasks.c:5115
97326,0x70106210,0x00002B00,97325,vTaskSwitchContext,tasks.c:5115
97325,0x7010620C,0xF8553D14,97324,vTaskSwitchContext,tasks.c:5115
97324,0x802F068A,0x00004770,97323,_DebugP_assert,DebugP_log.c:92
97323,0x802F0688,0x0000B100,97322,_DebugP_assert,DebugP_log.c:92
97322,0x7015991C,0xE51FF004,97321,___DebugP_assert_from_arm,:?
97321,0x70106208,0xF053EB88,97320,vTaskSwitchContext,tasks.c:5115
97320,0x70106206,0x00003C01,97319,vTaskSwitchContext,tasks.c:5115
97319,0x70106204,0x00009600,97318,vTaskSwitchContext,tasks.c:5115
97318,0x70106202,0x00004639,97317,vTaskSwitchContext,tasks.c:5115
97317,0x70106200,0x00004642,97316,vTaskSwitchContext,tasks.c:5115
97316,0x701061FE,0x00004620,97315,vTaskSwitchContext,tasks.c:5115
97315,0x701061FA,0xF24133FB,97314,vTaskSwitchContext,tasks.c:5115
97314,0x70106212,0x0000D0F2,97313,vTaskSwitchContext,tasks.c:5115
97313,0x70106210,0x00002B00,97312,vTaskSwitchContext,tasks.c:5115
97312,0x7010620C,0xF8553D14,97311,vTaskSwitchContext,tasks.c:5115
97311,0x802F068A,0x00004770,97310,_DebugP_assert,DebugP_log.c:92
97310,0x802F0688,0x0000B100,97309,_DebugP_assert,DebugP_log.c:92
97309,0x7015991C,0xE51FF004,97308,___DebugP_assert_from_arm,:?
97308,0x70106208,0xF053EB88,97307,vTaskSwitchContext,tasks.c:5115
97307,0x70106206,0x00003C01,97306,vTaskSwitchContext,tasks.c:5115
97306,0x70106204,0x00009600,97305,vTaskSwitchContext,tasks.c:5115
97305,0x70106202,0x00004639,97304,vTaskSwitchContext,tasks.c:5115
97304,0x70106200,0x00004642,97303,vTaskSwitchContext,tasks.c:5115
97303,0x701061FE,0x00004620,97302,vTaskSwitchContext,tasks.c:5115
97302,0x701061FA,0xF24133FB,97301,vTaskSwitchContext,tasks.c:5115
97301,0x70106212,0x0000D0F2,97300,vTaskSwitchContext,tasks.c:5115
97300,0x70106210,0x00002B00,97299,vTaskSwitchContext,tasks.c:5115
97299,0x7010620C,0xF8553D14,97298,vTaskSwitchContext,tasks.c:5115
97298,0x802F068A,0x00004770,97297,_DebugP_assert,DebugP_log.c:92
97297,0x802F0688,0x0000B100,97296,_DebugP_assert,DebugP_log.c:92
97296,0x7015991C,0xE51FF004,97295,___DebugP_assert_from_arm,:?
97295,0x70106208,0xF053EB88,97294,vTaskSwitchContext,tasks.c:5115
97294,0x70106206,0x00003C01,97293,vTaskSwitchContext,tasks.c:5115
97293,0x70106204,0x00009600,97292,vTaskSwitchContext,tasks.c:5115
97292,0x70106202,0x00004639,97291,vTaskSwitchContext,tasks.c:5115
97291,0x70106200,0x00004642,97290,vTaskSwitchContext,tasks.c:5115
97290,0x701061FE,0x00004620,97289,vTaskSwitchContext,tasks.c:5115
97289,0x701061FA,0xF24133FB,97288,vTaskSwitchContext,tasks.c:5115
97288,0x70106212,0x0000D0F2,97287,vTaskSwitchContext,tasks.c:5115
97287,0x70106210,0x00002B00,97286,vTaskSwitchContext,tasks.c:5115
97286,0x7010620C,0xF8553D14,97285,vTaskSwitchContext,tasks.c:5115
97285,0x802F068A,0x00004770,97284,_DebugP_assert,DebugP_log.c:92
97284,0x802F0688,0x0000B100,97283,_DebugP_assert,DebugP_log.c:92
97283,0x7015991C,0xE51FF004,97282,___DebugP_assert_from_arm,:?
97282,0x70106208,0xF053EB88,97281,vTaskSwitchContext,tasks.c:5115
97281,0x70106206,0x00003C01,97280,vTaskSwitchContext,tasks.c:5115
97280,0x70106204,0x00009600,97279,vTaskSwitchContext,tasks.c:5115
97279,0x70106202,0x00004639,97278,vTaskSwitchContext,tasks.c:5115
97278,0x70106200,0x00004642,97277,vTaskSwitchContext,tasks.c:5115
97277,0x701061FE,0x00004620,97276,vTaskSwitchContext,tasks.c:5115
97276,0x701061FA,0xF24133FB,97275,vTaskSwitchContext,tasks.c:5115
97275,0x70106212,0x0000D0F2,97274,vTaskSwitchContext,tasks.c:5115
97274,0x70106210,0x00002B00,97273,vTaskSwitchContext,tasks.c:5115
97273,0x7010620C,0xF8553D14,97272,vTaskSwitchContext,tasks.c:5115
97272,0x802F068A,0x00004770,97271,_DebugP_assert,DebugP_log.c:92
97271,0x802F0688,0x0000B100,97270,_DebugP_assert,DebugP_log.c:92
97270,0x7015991C,0xE51FF004,97269,___DebugP_assert_from_arm,:?
97269,0x70106208,0xF053EB88,97268,vTaskSwitchContext,tasks.c:5115
97268,0x70106206,0x00003C01,97267,vTaskSwitchContext,tasks.c:5115
97267,0x70106204,0x00009600,97266,vTaskSwitchContext,tasks.c:5115
97266,0x70106202,0x00004639,97265,vTaskSwitchContext,tasks.c:5115
97265,0x70106200,0x00004642,97264,vTaskSwitchContext,tasks.c:5115
97264,0x701061FE,0x00004620,97263,vTaskSwitchContext,tasks.c:5115
97263,0x701061FA,0xF24133FB,97262,vTaskSwitchContext,tasks.c:5115
97262,0x701061F8,0x00004690,97261,vTaskSwitchContext,tasks.c:5115
97261,0x701061F6,0x00004646,97260,vTaskSwitchContext,tasks.c:5115
97260,0x701061F2,0xF2C70710,97259,vTaskSwitchContext,tasks.c:5115
97259,0x701061F0,0x000046B1,97258,vTaskSwitchContext,tasks.c:5115
97258,0x701061EC,0xF2C70210,97257,vTaskSwitchContext,tasks.c:5115
97257,0x701061E8,0xF8CD900C,97256,vTaskSwitchContext,tasks.c:5115
97256,0x701061E4,0xF2C70810,97255,vTaskSwitchContext,tasks.c:5115
97255,0x701061E0,0xF64537E0,97254,vTaskSwitchContext,tasks.c:5115
97254,0x701061DC,0xF6484278,97253,vTaskSwitchContext,tasks.c:5115
97253,0x701061D8,0xF2461828,97252,vTaskSwitchContext,tasks.c:5115
97252,0x701061D6,0x0000BB0A,97251,vTaskSwitchContext,tasks.c:5115
97251,0x701061D2,0xF8562022,97250,vTaskSwitchContext,tasks.c:5115
97250,0x701061CE,0xEB060582,97249,vTaskSwitchContext,tasks.c:5115
97249,0x701061CC,0x000000A3,97248,vTaskSwitchContext,tasks.c:5115
97248,0x701061C8,0xF8C10088,97247,vTaskSwitchContext,tasks.c:5106
97247,0x701061C4,0xEB040284,97246,vTaskSwitchContext,tasks.c:5115
97246,0x701061C0,0xF8DA0000,97245,vTaskSwitchContext,tasks.c:5106
97245,0x701061BC,0xF8DB4000,97244,vTaskSwitchContext,tasks.c:5115
97244,0x701061B8,0xF2C70A10,97243,vTaskSwitchContext,tasks.c:5106
97243,0x701061B4,0xF2C70610,97242,vTaskSwitchContext,tasks.c:5115
97242,0x701061B0,0xF6425AA0,97241,vTaskSwitchContext,tasks.c:5106
97241,0x701061AC,0xF2C70B10,97240,vTaskSwitchContext,tasks.c:5115
97240,0x701061A8,0xF8D91000,97239,vTaskSwitchContext,tasks.c:5106
97239,0x701061A4,0xF64256B0,97238,vTaskSwitchContext,tasks.c:5115
97238,0x701061A0,0xF2430B48,97237,vTaskSwitchContext,tasks.c:5115
97237,0x7010619E,0x0000D959,97236,vTaskSwitchContext,tasks.c:5101
97236,0x7010619C,0x0000429A,97235,vTaskSwitchContext,tasks.c:5101
97235,0x7010619A,0x00006B1B,97234,vTaskSwitchContext,tasks.c:5101
97234,0x70106198,0x0000680A,97233,vTaskSwitchContext,tasks.c:5101
97233,0x70106196,0x00006010,97232,vTaskSwitchContext,tasks.c:5096
97232,0x70106192,0xF8D93000,97231,vTaskSwitchContext,tasks.c:5101
97231,0x7010618E,0xF8D91000,97230,vTaskSwitchContext,tasks.c:5101
97230,0x7010618C,0x00006818,97229,vTaskSwitchContext,tasks.c:5096
97229,0x7010618A,0x000067C1,97228,vTaskSwitchContext,tasks.c:5089
97228,0x70106188,0x00001949,97227,vTaskSwitchContext,tasks.c:5089
97227,0x70106186,0x0000BF84,97226,vTaskSwitchContext,tasks.c:5089
97226,0x70106184,0x00001B09,97225,vTaskSwitchContext,tasks.c:5089
97225,0x70106182,0x00006FC1,97224,vTaskSwitchContext,tasks.c:5089
97224,0x7010617E,0xF8D90000,97223,vTaskSwitchContext,tasks.c:5089
97223,0x7010617C,0x0000681D,97222,vTaskSwitchContext,tasks.c:5089
97222,0x7010617A,0x0000BF81,97221,vTaskSwitchContext,tasks.c:5089
97221,0x70106178,0x000042A1,97220,vTaskSwitchContext,tasks.c:5087
97220,0x70106176,0x00006819,97219,vTaskSwitchContext,tasks.c:5087
97219,0x70106174,0x00006018,97218,vTaskSwitchContext,tasks.c:5077
97218,0x70106172,0x00006814,97217,vTaskSwitchContext,tasks.c:5087
97217,0x7010616E,0xF2C70910,97216,vTaskSwitchContext,tasks.c:5089
97216,0x7010616A,0xF2C70210,97215,vTaskSwitchContext,tasks.c:5087
97215,0x70106166,0xF64259A4,97214,vTaskSwitchContext,tasks.c:5089
97214,0x70106162,0xF2C70310,97213,vTaskSwitchContext,tasks.c:5077
97213,0x7010615E,0xF2430230,97212,vTaskSwitchContext,tasks.c:5087
97212,0x7010615A,0xF2430334,97211,vTaskSwitchContext,tasks.c:5077
97211,0x7010902E,0x0000BD08,97210,uiPortGetRunTimeCounterValue,port.c:357
97210,0x802F0C4E,0x00001830,97209,ClockP_getTimeUsec,ClockP_freertos.c:298
97209,0x802F0C4A,0xFB027705,97208,ClockP_getTimeUsec,ClockP_freertos.c:292
97208,0x802F0C46,0xFBB3F0F0,97207,ClockP_getTimeUsec,ClockP_freertos.c:294
97207,0x802F0C42,0xFBA26704,97206,ClockP_getTimeUsec,ClockP_freertos.c:292
97206,0x802F0C3E,0xFB02F303,97205,ClockP_getTimeUsec,ClockP_freertos.c:294
97205,0x802F0C3C,0x000043C0,97204,ClockP_getTimeUsec,ClockP_freertos.c:294
97204,0x802F0C3A,0x00001A1B,97203,ClockP_getTimeUsec,ClockP_freertos.c:294
97203,0x802F0C38,0x000068B2,97202,ClockP_getTimeUsec,ClockP_freertos.c:292
97202,0x802F0C36,0x00006B30,97201,ClockP_getTimeUsec,ClockP_freertos.c:294
97201,0x802F0C32,0xF1450500,97200,ClockP_getTimeUsec,ClockP_freertos.c:288
97200,0x802F0C30,0x00003401,97199,ClockP_getTimeUsec,ClockP_freertos.c:288
97199,0x802F0C2E,0x0000B117,97198,ClockP_getTimeUsec,ClockP_freertos.c:286
97198,0x802F0C2C,0x0000D1E4,97197,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97197,0x802F0C2A,0x00002900,97196,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97196,0x802F0C26,0xF0410101,97195,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97195,0x802F0C24,0x0000BF88,97194,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97194,0x802F0C22,0x00004582,97193,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97193,0x802F0C20,0x00004603,97192,ClockP_getTimeUsec,ClockP_freertos.c:281 (discriminator 1)
97192,0x802F0C1E,0x00002100,97191,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97191,0x802F0C1C,0x00002101,97190,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97190,0x802F0C1A,0x00004544,97189,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97189,0x802F0C18,0x0000BF0A,97188,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97188,0x802F0C16,0x0000454D,97187,ClockP_getTimeUsec,ClockP_freertos.c:283 (discriminator 1)
97187,0x802F0C12,0xE9D64500,97186,ClockP_getTimeUsec,ClockP_freertos.c:282 (discriminator 1)
97186,0x802F1E3A,0x00004770,97185,TimerP_getCount,TimerP.c:171
97185,0x802F1E38,0x00006BC0,97184,TimerP_getCount,TimerP.c:170
97184,0x802F0CA4,0xF001B8C8,97183,ClockP_getTimerCount,ClockP_freertos_r5.c:43
97183,0x802F0C0E,0xF000F849,97182,ClockP_getTimeUsec,ClockP_freertos.c:281 (discriminator 1)
97182,0x802F0C0C,0x00006AF0,97181,ClockP_getTimeUsec,ClockP_freertos.c:281 (discriminator 1)
97181,0x802F0C0A,0x00004607,97180,ClockP_getTimeUsec,ClockP_freertos.c:278 (discriminator 1)
97180,0x802F1E56,0x00004770,97179,TimerP_isOverflowed,TimerP.c:212
97179,0x802F1E52,0xF3C00040,97178,TimerP_isOverflowed,TimerP.c:212
97178,0x802F1E50,0x00006A40,97177,TimerP_isOverflowed,TimerP.c:209
97177,0x802F0C06,0xF001F923,97176,ClockP_getTimeUsec,ClockP_freertos.c:278 (discriminator 1)
97176,0x802F0C04,0x00006AF0,97175,ClockP_getTimeUsec,ClockP_freertos.c:278 (discriminator 1)
97175,0x802F0C02,0x00004682,97174,ClockP_getTimeUsec,ClockP_freertos.c:271 (discriminator 1)
97174,0x802F0C00,0x000046A9,97173,ClockP_getTimeUsec,ClockP_freertos.c:271 (discriminator 1)
97173,0x802F1E3A,0x00004770,97172,TimerP_getCount,TimerP.c:171
97172,0x802F1E38,0x00006BC0,97171,TimerP_getCount,TimerP.c:170
97171,0x802F0CA4,0xF001B8C8,97170,ClockP_getTimerCount,ClockP_freertos_r5.c:43
97170,0x802F0BFC,0xF000F852,97169,ClockP_getTimeUsec,ClockP_freertos.c:271 (discriminator 1)
97169,0x802F0BFA,0x000046A0,97168,ClockP_getTimeUsec,ClockP_freertos.c:271 (discriminator 1)
97168,0x802F0BF8,0x00006AF0,97167,ClockP_getTimeUsec,ClockP_freertos.c:271 (discriminator 1)
97167,0x802F0BF4,0xE9D64500,97166,ClockP_getTimeUsec,ClockP_freertos.c:262
97166,0x802F0BF0,0xF2C8060E,97165,ClockP_getTimeUsec,ClockP_freertos.c:262
97165,0x802F0BEC,0xF64F5600,97164,ClockP_getTimeUsec,ClockP_freertos.c:262
97164,0x802F0BE8,0xE92D47F0,97163,ClockP_getTimeUsec,ClockP_freertos.c:262
97163,0x70159710,0xE51FF004,97162,__ClockP_getTimeUsec_veneer,:?
97162,0x7010614E,0xE92D4FF0,97161,vTaskSwitchContext,tasks.c:5057
97161,0x7010614A,0xF2C70310,97160,vTaskSwitchContext,tasks.c:5069
97160,0x70106148,0x00002200,97159,vTaskSwitchContext,tasks.c:5069
97159,0x70106144,0xF24303C8,97158,vTaskSwitchContext,tasks.c:5069
97158,0x70106722,0xF7FFBD0F,97157,vTaskSwitchContext,tasks.c:5140
97157,0x70106720,0x00004770,97156,vTaskSwitchContext,tasks.c:5140
97156,0x7010671E,0x0000601A,97155,vTaskSwitchContext,tasks.c:5065
97155,0x7010671A,0xF2C70310,97154,vTaskSwitchContext,tasks.c:5065
97154,0x70106718,0x00002201,97153,vTaskSwitchContext,tasks.c:5065
97153,0x70106714,0xF24303C8,97152,vTaskSwitchContext,tasks.c:5065
97152,0x70106712,0x0000B133,97151,vTaskSwitchContext,tasks.c:5061
97151,0x70106710,0x0000681B,97150,vTaskSwitchContext,tasks.c:5061
97150,0x7010670C,0xF2C70310,97149,vTaskSwitchContext,tasks.c:5061
97149,0x70106708,0xF2430340,97148,vTaskSwitchContext,tasks.c:5061
97148,0x701001E0,0xE12FFF30,97147,HwiP_svc_handler,portASM.S:148
97147,0x701001DC,0xE59F0168,97146,HwiP_svc_handler,portASM.S:147
97146,0x701001D8,0xE581D000,97145,HwiP_svc_handler,portASM.S:146
97145,0x701001D4,0xE5901000,97144,HwiP_svc_handler,portASM.S:146
97144,0x701001D0,0xE59F016C,97143,HwiP_svc_handler,portASM.S:146
97143,0x701001CC,0xE52D3004,97142,HwiP_svc_handler,portASM.S:146
97142,0x701001C8,0x152D1004,97141,HwiP_svc_handler,portASM.S:146
97141,0x701001C4,0x1D2D0B20,97140,HwiP_svc_handler,portASM.S:146
97140,0x701001C0,0x1EF11A10,97139,HwiP_svc_handler,portASM.S:146
97139,0x701001BC,0xE3530000,97138,HwiP_svc_handler,portASM.S:146
97138,0x701001B8,0xE5923000,97137,HwiP_svc_handler,portASM.S:146
97137,0x701001B4,0xE59F218C,97136,HwiP_svc_handler,portASM.S:146
97136,0x701001B0,0xE92D5FFF,97135,HwiP_svc_handler,portASM.S:146
97135,0x701001AC,0xF102001F,97134,HwiP_svc_handler,portASM.S:146
97134,0x701001A8,0xF96D051F,97133,HwiP_svc_handler,portASM.S:146
97133,0x00000008,0xE59FF018,97132,Supervisor call (SVC),_vectors,HwiP_armv7r_vectors_freertos_asm.S:42
97132,0x7010A0E2,0x0000DF00,97131,xQueueSemaphoreTake,queue.c:1804
97131,0x7010A0E0,0x0000B900,97130,xQueueSemaphoreTake,queue.c:1802
97130,0x70107A5A,0xE8BD8FF0,97129,xTaskResumeAll,tasks.c:4104
97129,0x70107A58,0x0000B007,97128,xTaskResumeAll,tasks.c:4104
97128,0x70107A56,0x00009802,97127,xTaskResumeAll,tasks.c:4104
97127,0x70107034,0x0000BD30,97126,vTaskExitCritical,tasks.c:7076
97126,0x70107032,0x0000B003,97125,vTaskExitCritical,tasks.c:7076
97125,0x70107030,0x0000B662,97124,vEnableInterruptPriority,portmacro.h:195
97124,0x7010702E,0x0000B903,97123,vTaskExitCritical,tasks.c:7056
97123,0x7010702C,0x00006D4B,97122,vTaskExitCritical,tasks.c:7056
97122,0x7010702A,0x00006553,97121,vTaskExitCritical,tasks.c:7054
97121,0x70107028,0x00003B01,97120,vTaskExitCritical,tasks.c:7054
97120,0x70107026,0x00006D53,97119,vTaskExitCritical,tasks.c:7054
97119,0x70107024,0x00006821,97118,vTaskExitCritical,tasks.c:7056
97118,0x70107022,0x00006822,97117,vTaskExitCritical,tasks.c:7054
97117,0x70107020,0x0000B13B,97116,vTaskExitCritical,tasks.c:7052
97116,0x7010701E,0x00006D5B,97115,vTaskExitCritical,tasks.c:7052
97115,0x7010701C,0x00006823,97114,vTaskExitCritical,tasks.c:7052
97114,0x802F068A,0x00004770,97113,_DebugP_assert,DebugP_log.c:92
97113,0x802F0688,0x0000B100,97112,_DebugP_assert,DebugP_log.c:92
97112,0x7015991C,0xE51FF004,97111,___DebugP_assert_from_arm,:?
97111,0x70107018,0xF052EC80,97110,vTaskExitCritical,tasks.c:7050
97110,0x70107016,0x00000940,97109,vTaskExitCritical,tasks.c:7050
97109,0x70107012,0xFAB0F080,97108,vTaskExitCritical,tasks.c:7050
97108,0x7010700E,0xF641338A,97107,vTaskExitCritical,tasks.c:7050
97107,0x7010700A,0xF2C70110,97106,vTaskExitCritical,tasks.c:7050
97106,0x70107008,0x00009300,97105,vTaskExitCritical,tasks.c:7050
97105,0x70107004,0xF64531E0,97104,vTaskExitCritical,tasks.c:7050
97104,0x70107002,0x00006808,97103,vTaskExitCritical,tasks.c:7050
97103,0x70106FFE,0xF2C70210,97102,vTaskExitCritical,tasks.c:7050
97102,0x70106FFA,0xF2C70310,97101,vTaskExitCritical,tasks.c:7050
97101,0x70106FF6,0xF64852D8,97100,vTaskExitCritical,tasks.c:7050
97100,0x70106FF2,0xF2C70110,97099,vTaskExitCritical,tasks.c:7050
97099,0x70106FEE,0xF64663E4,97098,vTaskExitCritical,tasks.c:7050
97098,0x70106FEA,0xF24301D0,97097,vTaskExitCritical,tasks.c:7050
97097,0x802F068A,0x00004770,97096,_DebugP_assert,DebugP_log.c:92
97096,0x802F0688,0x0000B100,97095,_DebugP_assert,DebugP_log.c:92
97095,0x7015991C,0xE51FF004,97094,___DebugP_assert_from_arm,:?
97094,0x7010610C,0x0000681B,97093,xTaskIncrementTick,tasks.c:4864
97093,0x70106108,0xF2C70310,97092,xTaskIncrementTick,tasks.c:4864
97092,0x70106104,0xF24303C8,97091,xTaskIncrementTick,tasks.c:4864
97091,0x70106022,0x0000D36F,97090,xTaskIncrementTick,tasks.c:4715
97090,0x7010601E,0xF04F0C00,97089,xTaskIncrementTick,tasks.c:4675
97089,0x7010601C,0x0000BF38,97088,xTaskIncrementTick,tasks.c:4675
97088,0x7010601A,0x00004598,97087,xTaskIncrementTick,tasks.c:4715
97087,0x70106018,0x0000681B,97086,xTaskIncrementTick,tasks.c:4715
97086,0x70106016,0x00009B05,97085,xTaskIncrementTick,tasks.c:4715
97085,0x70106014,0x00009305,97084,prvResetNextTaskUnblockTime,tasks.c:6464
97084,0x70106010,0xF2C70310,97083,prvResetNextTaskUnblockTime,tasks.c:6464
97083,0x7010600C,0xF2430378,97082,prvResetNextTaskUnblockTime,tasks.c:6464
97082,0x70105F9C,0x0000D136,97081,xTaskIncrementTick,tasks.c:4702
97081,0x70105F98,0xF1B80F00,97080,xTaskIncrementTick,tasks.c:4702
97080,0x70105F94,0xF8C38000,97079,xTaskIncrementTick,tasks.c:4700
97079,0x70105F90,0xF1020801,97078,xTaskIncrementTick,tasks.c:4696
97078,0x70105F8E,0x0000B087,97077,xTaskIncrementTick,tasks.c:4671
97077,0x70105F8C,0x0000681A,97076,xTaskIncrementTick,tasks.c:4696
97076,0x70105F88,0xE92D4FF0,97075,xTaskIncrementTick,tasks.c:4671
97075,0x70105F84,0xF2C70310,97074,xTaskIncrementTick,tasks.c:4696
97074,0x70105F80,0xF24303C4,97073,xTaskIncrementTick,tasks.c:4696
97073,0x70107A16,0xF7FEFAB3,97072,xTaskIncrementTick,tasks.c:4055
97072,0x70107A28,0x0000D0F5,97071,xTaskIncrementTick,tasks.c:4692
97071,0x70107A26,0x00002B00,97070,xTaskIncrementTick,tasks.c:4692
97070,0x70107A24,0x00006823,97069,xTaskIncrementTick,tasks.c:4692
97069,0x70107A14,0x0000E006,97068,xTaskResumeAll,tasks.c:4055
97068,0x70107A12,0x00002701,97067,xTaskResumeAll,tasks.c:4055
97067,0x70107A0E,0xF8DD8010,97066,xTaskResumeAll,tasks.c:4055

here is stack frame (shown before and after CurrentTcb->PxTopOfStack.
There is a correlation between value (red) 0x40100221 in R7 and its location in Frame and registers stored before and after R7 It seems that registers are stored at offset CurrentTcb->PxTopOfStack + 4 bytes. I do not have logical explanations for this offset (probably LR stored first?)

incorrect value (0x40100221) is persistent - reproduces avery time, even if I change an app a little bit.

It looks like problem is somewhere in _fclose_r. R7 gets corrupted somewhere inside this function.

Are you writing any function in assembly? Can you share your complete code?

No assembly.
Problem is probably in libc _retarget_lock* functions that do not do what I expect.
I use Mutex and figured out that some _retarget_lock* functions are called before main.

Is there FreeRTOS-friendly _retarget_lock* implementation for libc ?

Can you change your implementation to use mutex only after the scheduler is started:

if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )
{
       /* use mutex. */
}
1 Like

that’s it!
it is better then
if (!xTaskGetCurrentTaskHandle()) /* not in task */
{
return;
}

Great! So this fixes your problem, right?

unfortunaty not yet. problem is somewhere on stitch between libc and freertos.
any modification/instrumentation to problematic code and problem goes away.
i’ll post results , but it may take time.
the funny thing that i didnt find any glue code for libc that looks good and is not being criticized.

I think that I found direction.
In the newer version of FreeRTOS port of TI
I see that configUSE_NEWLIB_REENTRANT is abandoned and configUSE_C_RUNTIME_TLS_SUPPORT do something similar.
It would be nice if they could keep the same heuristics if configUSE_NEWLIB_REENTRANT is enabled.

So setting configUSE_NEWLIB_REENTRANT (which is still in FreeRTOS.h) to 1 makes no effect.
instead
#ifndef configSET_TLS_BLOCK
#define configSET_TLS_BLOCK( xTLSBlock ) ( _impure_ptr = &( xTLSBlock ) )
#endif

UPDATE: there is the same heuristics, configSET_TLS_BLOCK depends on configUSE_NEWLIB_REENTRANT. indirectly.
I enable it and keep fingers crossed.
UPDATE 1:
I recall why it was not defined, because in TI RTOS wrappers they use hardcoded TCB size
/** Minimum requirement for FreeRTOS MPU Port to work

  • In this case, TCB stores the MPU settings including system mode stack as well the task context. */
    #define TaskP_OBJECT_SIZE_MAX (4568u)
    #else
    #define TaskP_OBJECT_SIZE_MAX (180u)
    #endif
    and system load stops in some ASSERT.

UPDATE2:
It appears that configUSE_NEWLIB_REENTRANT is not enough.
Need also to rewrite __sfp_lock_acquire and __sfp_lock_release, which is bit more tricky, since these symbols are defined as “strong” in newlib and maybe also a bunch of functions that start with __retarget_lock*

Final verdict
configUSE_NEWLIB_REENTRANT plus __sfp_lock_acquire and __sfp_lock_release

1 Like

I’m glad you got it working.

In our embedded system the additional per-task storage that configUSE_NEWLIB_REENTRANT causes was unafffordable. Instead we designed our software to avoid using any library functions that uses impure_ptr. This required:

  • Writing our own versions of printf and similar functions. Doing this also allowed us to printf to our own data structures and add facilities for JSON escaping. The printf code in newlib is quite complicated because it handles all representable floating pint values; however if your application doesn’t need to print values that are always correct to the very last digit then a simpler implementation will suffice.
  • Writing our own versions of strtod and related functions. Again, the newlib version handles all representable values, but if your application doesn’t need to handle extreme values accurately then a simpler version is possible.
  • Several standard library functions such as gmtime return a pointer to a static buffer, which is in the area pointed to by impure_ptr. However, gcc provides alternative versions of these functions such as gmtime_r where you supply the buffer; so we use those instead.
1 Like

Glad that you worked it out!