Stack overflow: different between main thrad and other thread?
Posted: Thu Jan 16, 2020 9:26 pm
Developing on an STM32L152RE Nucleo, I have observed the following strange behavior:
I am reading audio data from an SD card and writing the same to I2S. I currently have only one thread, which reads the data from the card. The (ISR-triggered) I2S callback then requests reading the next chunk of data, using a semaphore.
Elm Chan“s implementation uses quite some stack, with 0x4000 (16 kB) for stack it runs all fine as long as I run it in the main thread.
As soon as I move the same code into a separate thread with a working area of the same size (16kB), I run into a stack overflow assertion. Even increasing to about 50kB did not help.
Buffers are in .bss, not on the stack. The stack trace is quite long, but this does not explain a) what happens at all b) why the behavior is different between forked thread and main thread.
Looking at the stack pointer register, it points to <playThread+15248> - so a stack overflow should still be 15.2 kB away.
I would be glad to be enlightened what is going wrong here.
Thank you,
Max
I am reading audio data from an SD card and writing the same to I2S. I currently have only one thread, which reads the data from the card. The (ISR-triggered) I2S callback then requests reading the next chunk of data, using a semaphore.
Elm Chan“s implementation uses quite some stack, with 0x4000 (16 kB) for stack it runs all fine as long as I run it in the main thread.
As soon as I move the same code into a separate thread with a working area of the same size (16kB), I run into a stack overflow assertion. Even increasing to about 50kB did not help.
Buffers are in .bss, not on the stack. The stack trace is quite long, but this does not explain a) what happens at all b) why the behavior is different between forked thread and main thread.
Looking at the stack pointer register, it points to <playThread+15248> - so a stack overflow should still be 15.2 kB away.
I would be glad to be enlightened what is going wrong here.
Thank you,
Max