Loading...
 

SW4STM32 and SW4Linux fully supports the STM32MP1 asymmetric multicore Cortex/A7+M4 MPUs

   With System Workbench for Linux, Embedded Linux on the STM32MP1 family of MPUs from ST was never as simple to build and maintain, even for newcomers in the Linux world.
And, if you install System Workbench for Linux in System Workbench for STM32 you can seamlessly develop and debug asymmetric applications running partly on Linux, partly on the Cortex-M4.
You can get more information from the ac6-tools website and download two short videos (registration required) highlighting:

System Workbench for STM32


Issue snprintf floats

Hi,
I am having an issue with floats and snprintf. I created a small demo program using CubeMX 5.2 and put it on bitbucket: https://bitbucket.org/arminoonk/printf-float-issue/src/master/Question

I have added “-u _printf_float” to the GCC Linker flags. Complete linker flags are: “-specs=nosys.specs -specs=nano.specs -u _printf_float”

In the default task I have added a small blinking led. In a separate task I have the following code:

char temp33;
snprintf(temp, 33, “%f”, 6.66)

When snprintf is run a hard fault handler occurs. The stack size for the snprintf task is 2048 words which should be enough.
I have created code using snprintf before using cubemx. This worked beautifully but now suddenly it stopped.

I am using system workbench with the latest software updates installed.
System Workbench

Is there a known issue with the newer releases of cubeMX/system workbench? Is there a work around?

Kind regards,
Armin

I have been looking further into this.
When the hardfault occurs the PC points to _Bfree
Hardfault

I have been looking into what the implementation of snprintf does. It seems it is using some dynamic memory using malloc().

Way back I found some resource telling me to use pvPortMalloc and vPortFree instead of the normal malloc and free. I am using FreeRTOS with heap4.

Could it be the call to malloc causing problems because I am using FreeRTOS?

The answer to this is, no it does not always work. I will continue this monologue.

I have used the solution from: http://www.openstm32.org/forumthread353#threadId354Question
It appears to be an incorrect _sbrk implementation

I have update the example project on bitbucket

_sbrk implementation

caddr_t _sbrk(int incr) {

extern char end asm(“end”);
extern char _min_heap_end asm(“_min_heap_end”);
static char *heap_end;
char *prev_heap_end;

if (heap_end == 0) {
heap_end = &end;
}

prev_heap_end = heap_end;
if (prev_heap_end + incr > &_min_heap_end) {
if (heap_end + incr > stack_ptr) {
errno = ENOMEM;
return (caddr_t) -1;
}
}
heap_end += incr;
return (caddr_t) prev_heap_end;

}



Update to linker file:

/* User_heap_stack section, used to check that there is enough RAM left */
._user_heap_stack :
{
. = ALIGN(4);
PROVIDE ( end = . );
PROVIDE ( _end = . );
. = . + _Min_Heap_Size;
PROVIDE ( _min_heap_end = . );
. = . + _Min_Stack_Size;
. = ALIGN(4);
} >RAM