Giter Club home page Giter Club logo

stm32-freertos-float's Introduction

Attention: This repository has been archived!

New version of STM32CubeMX generate correct code for GCC(newlib) to use float and double (converting values to char type) under FreeRTOS use printf, sprintf, snprintf.

Configuring STM32 to work with float and double (converting values to char type) under FreeRTOS use printf, sprintf, snprintf.

If you use standard tools for converting float and double to char type such as printf, sprintf, snprintf, then when you run these conversions under FreeRTOS and using the GNU Arm Embedded Toolchain (https://developer.arm.com/tools-and-software/ open-source-software / developer-tools / gnu-toolchain / gnu-rm) the microcontroller hangs and a Hard Fault error occurs. According to research on this topic http://www.nadler.com/embedded/newlibAndFreeRTOS.html, this error is associated with incorrect operation of dynamic memory allocation (malloc / malloc_r).

Source code https://github.com/DRNadler/FreeRTOS_helpers

How is it all corrected.

  1. Remove the heap_4.c file from the \Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang\ directory of your project
  2. Copy the heap_useNewlib_ST.c file from the given repository (src) to the above directory(src);
  3. Comment or delete define function caddr_t _sbrk(int incr) in file Core\Src\syscalls.c
  4. Open the FreeRTOS configuration file (FreeRTOSConfig.h) and add an additional define to the section;
/* USER CODE BEGIN Defines */   	      
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */

#define configUSE_NEWLIB_REENTRANT 1

/* USER CODE END Defines */

Remember to enable the extra option for the "-u _printf_float" compiler.

This completes the setup. Compilation and operation of the printf, sprintf, snprintf functions should occur without hovering and Hard Fault.

Do not forget that when you re-generate the project in STM32CubeMX, the procedure will need to be repeated!

p.s. The version of the heap_useNewlib_ST.c file provided in this repository is slightly different from the original (https://github.com/DRNadler/FreeRTOS_helpers) in terms of fixing compilation errors. It was tested on the following versions of the STM32F401CCU6 microcontrollers under Windows 10 and Ubuntu 20.04

Настройка STM32 для работы с float и double (преобразования значений к типу char) под FreeRTOS.

Если использовать стандартные инструменты по преобразованию float и double к типу char такие как printf, sprintf, snprintf, то при запуске этих преобразований под FreeRTOS и используя GNU Arm Embedded Toolchain (https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm) наблюдается зависание микроконтроллера и появление ошибки Hard Fault.

Согласно исследованиям этой темы http://www.nadler.com/embedded/newlibAndFreeRTOS.html данная ошибка связанна с некорректной работой динамического выделения памяти (malloc/malloc_r).

Как это все правиться:

  1. Удалите из директори `````\Middlewares\Third_Party\FreeRTOS\Source\portable\MemMang``` вашего проекта файл heap_4.c;
  2. Скопируйте в вышеуказанную директорию файл heap_useNewlib.c из данного репозитария (src);
  3. Закоментируйте или удалите функцию caddr_t _sbrk(int incr) в файле Core\Src\syscalls.c
  4. Откройте конфигурационный файл FreeRTOS (FreeRTOSConfig.h) и добавьте в секцию дополнительный define;
/* USER CODE BEGIN Defines */   	      
/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */

#define configUSE_NEWLIB_REENTRANT 1

/* USER CODE END Defines */

Не забудьте включить дополнительную опцию для компилятора "-u _printf_float".

На этом настройка закончена. Компиляция и работа функций printf, sprintf, snprintf должны происходить без зависания и Hard Fault.

Не забывайте, что при пере генерации проекта в STM32CubeMX процедуру необходимо будет повторить!

p.s. Версия файла heap_useNewlib.c приведенного в данном репозитарии немного отличается от исходной (https://github.com/DRNadler/FreeRTOS_helpers) в части исправления ошибок компиляции. Проверялось на следующих версиях микроконтроллеров STM32F401CCU6 под Windows 10 и Ubuntu 20.04

stm32-freertos-float's People

Contributors

leech001 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.