cancel
Showing results for 
Search instead for 
Did you mean: 

ostringstream and stringstream operator<< makes hardfault exception (stm32f4, touchGFX, freeRTOS, malloc-wrapper), how to solve or alternatives?

awiernie
Senior II

Does ofstringstream and stringstream not work with freeRTOS?

We develop a device using stm32f46x using touch GFX and freeRTOS. The system is generated with the latest STM32Cube IDE and the configuration tool. After crashes with localtime, new etc. I overloaded new and malloc first and later I used the suggested solution of David Nadler. Now the program crashed with hardfault (CFSR Register Content 0x1400 - stack fault) at every place where a std::ofstringstream or std::stringstream uses operator<<. Debugging seem to show sufficient stack and heap sizes. Always when "<<" is applied with data (not with precision()) a hardfault is thrown immdiately. While I had set breakpoint at the malloc and malloc_r wrappers, these functions are not called.

  1. Any solution?
  2. Does anyone successfull use stringstreams with stm32?
  3. What is the alternative, use of ftoa, itoa?
  4. I know that ofstringstream is maybe not the best as the template my consume space at all places where it is used and sizeof also is morte than 300 bytes.
  5. The device configuration tool installs an older version of freeRTOS (10.0.1) while the latest touchGFX 4.14 delivers a newer one (10.2.1), but this is not installed and not compatible with the main.c etc generated by the devcice configuration tool. Can the older rtos be a problem?
4 REPLIES 4
KnarfB
Principal III
awiernie
Senior II

What I mentioned with the use of the malloc and malloc_r wrappers is from your link. I used the recommended solution of David Nadler. It seems to work with some other parts but ostringstream does not. No malloc_lock in Nadler's heap_useNewlib_ST.c is not called.

Maybe the solution does not work for the precompiled lib provided by ST?

awiernie
Senior II

Now I solved it.

The main reason was that I had used the ostringstream in order to convert a floating point number into a string. Floating Pointer formating however is disabled in the compiler options by default. Using printf did also not work but there was a warning displayed in the editor: If one activates printf support, the ofstream::operator<<(float) works.

AT the same time there were two other problems which had also caused crashes. One was that after an update of the CubeMX has replaced IRQ 5 by IRQ 0 - there is another discussion about this. And the modification of malloc in combination with freeRTOS if one uses loaltime, std::string, ...

Hi

Im having same problem but im also kinda new to stm32. Could you tell what you exactly change with IRQ and malloc and where? Thanks