Comments (8)
Update.
I thought that using configMEMMANG_HEAP_NB
1 – 5 means that malloc()
and free()
provided by the standard library get replaced by FreeRTOS's implementations, but they don't. Instead, pvPortMalloc()
and pvPortFree()
are added. So that had nothing to do with this.
The problem still remained with configMEMMANG_HEAP_NB
-1 or using heap_useNewlib.c
. It comes down to vTaskSuspendAll()
/ xTaskResumeAll()
which contain taskENTER_CRITICAL()
/ taskEXIT_CRITICAL()
which map to vPortEnterCritical()
/ vPortExitCritical()
:
port.c:
void vPortEnterCritical( void )
{
portDISABLE_INTERRUPTS();
uxCriticalNesting++;
__asm volatile( "dsb" ::: "memory" );
__asm volatile( "isb" );
}
/*-----------------------------------------------------------*/
void vPortExitCritical( void )
{
configASSERT( uxCriticalNesting );
uxCriticalNesting--;
if( uxCriticalNesting == 0 )
{
portENABLE_INTERRUPTS();
}
}
Since uxCriticalNesting
is (intentionally) uninitialized (set to a large value), a call to vPortEnterCritical()
followed by vPortExitCritical()
doesn't re-enable the interrupts. Based on FAQ point 4:
If a FreeRTOS API function is called before the scheduler has been started then interrupts will deliberately be left disabled, and not re-enable again until the first task starts to execute. This is done to protect the system from crashes caused by interrupts attempting to use FreeRTOS API functions during system initialisation, before the scheduler has been started, and while the scheduler may be in an inconsistent state.
So yes, this code hanging up in the delay()
:
#include <Arduino.h>
#include <STM32FreeRTOS.h>
void setup() {
volatile int *a = (int *) malloc(16);
*a = 1;
free((int *)a);
delay(1);
}
void loop() {
}
Is things working as expected 🤔
from stm32freertos.
Look like the problem is with the realloc()
function that the STM32FreeRTOS uses.
Here's a simple program that crashes at realloc()
:
#include <Arduino.h>
void setup() {
Serial.begin(115200);
while (!Serial);
Serial.println("Starting...");
delay(500);
int *p = (int *) malloc(1);
p = (int *) realloc(p, 1);
Serial.println("Ending...");
for (;;);
}
void loop() {
}
By crashing I mean HAL_IncTick()
isn't called anymore and Serial doesn't work.
Also I'm getting this warning:
This wrapper was verified for newlib version 2.5.0; please ensure newlib's external requirements for malloc-family are unchanged!"
, the version of newlib that platformio provides is 3.1.
from stm32freertos.
Solved by uncommenting #define configMEMMANG_HEAP_NB 3
in FreeRTOSConfig_Default.h
. Not sure why it is commented out by default?
from stm32freertos.
Hi,
this is described by by default heap_useNewlib.c is used that's all because it is the best heap management to use as *alloc are used.
I didn't saw that issue before I will not be able to check this soon.
Anyway the heap_useNewlib.c have to be reviewed for newlib 3.x as it was updated, see:
https://nadler.com/embedded/newlibAndFreeRTOS.html
Note that PIO is not supported here so maybe the config is not correct with pio.
from stm32freertos.
On the second look, these are the results that I'm getting:
#define configMEMMANG_HEAP_NB -1
kills Hal_IncTick()
on malloc()
and realloc()
#define configMEMMANG_HEAP_NB 3
is fragile, hardfaults in some cases
#define configMEMMANG_HEAP_NB 1, 2, 4
doesn't compile because:
.pio\libdeps\nucleo_g071rb\STM32duino FreeRTOS\src\../portable/MemMang/heap_1.c:61:17: error: variably modified 'ucHeap' at file scope
61 | static uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
#define configMEMMANG_HEAP_NB 5
kills Hal_IncTick()
some other way
from stm32freertos.
Ok, I was able to recreate the problem in the Arduino environment.
Simply adding #include <STM32FreeRTOS.h>
to the VL53L3CX_Sat_HelloWorld
example sketch hangs the program somewhere in sensor_vl53lx_sat.InitSensor(0x12);
, presumably for the same reason as the OP.
Or even simpler, the same thing happens in the example of Wire
-> master_writer
. Adding #include <STM32FreeRTOS.h>
breaks it, presumably after a call to realloc()
is made inside Wire.requestFrom(2, 6);
.
from stm32freertos.
Ran this test with 4 processors.
STM32F407 Discovery (Cortex-M4) — PASS
STM32F103 Blue Pill (Cortex-M3) — PASS
STM32F0308 Discovery (Cortex-M0) — FAIL
STM32G071 Nucleo-64 (Cortex-M0+) — FAIL
All pass without #include <STM32FreeRTOS.h>
.
#include <STM32FreeRTOS.h>
#define LED LED_BUILTIN
void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
int *a = (int *) malloc(8);
int *b = (int *) realloc(a, 16);
free(b);
digitalWrite(LED, !digitalRead(LED));
delay(50);
}
from stm32freertos.
I must add another one - that may just be a problem of PIN interrupts, I suspect.
My current project uses IRMP library that depends on PIN interrupts to decode IR signals.
I wanted to apply RTOS tasks in favor of Arduino TaskScheduler (working very well, but is only a simple time slicer with no priority control at the end) in the future and included the library STM32FreeRTOS as lib dependency some weeks ago - to remember the idea.
Working on other parts of my project I did not test the IRMP decoding - because it just worked as expected before. Two days ago I tested the orchestration of all my routines and IRMP did not work any longer. Happy me, I was able to check different branches of my code back to the past and ensured my hardware was still ok.
The problem is - as soon as I include (no header files!) STM32FreeRTOS into the platformio configuration IRMP stops working. This is reproducible at any time.
from stm32freertos.
Related Issues (20)
- Parameters at task startup HOT 5
- Message buffer is not supported HOT 1
- How to use other timebase for HAL, cause the freeRTOS use the Systick? HOT 7
- Cannot build for STM32L552ZE-Q HOT 3
- I find a bug in osSemaphoreCreate HOT 3
- Why the freertos version is so old? HOT 1
- I can not use osSemaphoreRelease(rtcMinuteInterruptSemID) in the RTC alarm IRQ HOT 6
- Can not use HID bootloader while using STM32FreeRTOS HOT 6
- STM32 Free RTOS problem with the STM32Ethernet library HOT 1
- Including STM32FreeRTOS Crashes Board HOT 2
- L073RZ support HOT 1
- error: #5: cannot open source input file "cmsis_gcc.h" HOT 2
- STM32duino vTaskStartScheduler() problem HOT 5
- Calling vTaskDelay in loop() leads to infamous vListInsert death spiral HOT 3
- Interrupts and Multiple Tasks Causing Usage Fault INVPC HOT 14
- Is it a good practice to change HAL time base to timer and free SysTick for FreeRTOS? HOT 3
- FreeRTOS CPU HSE Clock Configuration HOT 1
- Error when compiling programs for CMSIS-RTOS V2, as well as examples HOT 1
- Documentation suggestion for configCHECK_FOR_STACK_OVERFLOW and for LED_BUILTIN HOT 1
- USB Serial is not working with STM32FreeRTOS in STM32 black pill HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stm32freertos.