6 years, 5 months ago.

Thread stack underflow - i have no clue

After working with mbed and cli for about two month now, porting mbed to a custom board based on the STM32F072VB.

128KB Flash, 16KB SRAM. Stack Pointer is on 0x20004000UL, and this is my code:

main.cpp

#include "mbed.h"
	Serial myserial(PA_9,PA_10, 9600);
	Thread t1,t2;

void toggle_on(Serial *thisserial) {
	for(;;){
		thisserial->printf("Thread-number: %d", Thread::gettid());
	}
}


int main() {
    // Start the event queue
    t1.start(callback(toggle_on, &myserial));
    t2.start(callback(toggle_on, &myserial));
    for(;;){
    }
}

And my error-msg: ThreadCMSIS-RTOS error: Stack underflow (status: 0x1, task ID: 0x200014F4, task name: (null))

I have no clue whats going wrong. I already decreased the main-stack-size(2kB) and thread-stack-size (512byte). With more stack-sizes, i get an error that i dont have enough memory for allocation.

Best regards Chris

Using printf in this context leads to cluster fuck. Question answered.

posted by Christopher Meis 25 Oct 2017

1 Answer

6 years, 5 months ago.

Hello Chris,

"ThreadCMSIS-RTOS error: Stack underflow (status: 0x1, task ID: 0x200014F4, task name: (null))" indicates stack overflow. ( I agree that its confusing to have the word "underflow" ). So, please try increasing your stack size and see if that fixes the problem. You can set a custom stack size using osThreadAttr_t struct.

Thanks, Senthil

Accepted Answer

Hello Senthil, thank you for your answer.

the printf-Function inside the Thread caused my problem above. I changed it to puts and used a constand char array.

posted by Christopher Meis 26 Oct 2017