Preview only show first 10 pages with watermark. For full document please download

Developing Applications On Stm32cubef4 With Rtos

February 2014 DocID025801 Rev 1 1/26 UM1722 User manual Developing Applications on STM32CubeF4 with RTOS Introduction The STM32Cube TM initiative was originated by STMicroelectronics to ease developers life by reducing development efforts, time and cost. STM32Cube TM covers the STM32 portfolio. STM32Cube TM Version 1.x includes: ã The STM32CubeMX, a graphical software configuration tool that allows to generate C initialization code using graphical wizards. ã A comprehensive embedded softwa

   EMBED


Share

Transcript

  February 2014DocID025801 Rev 11/26 UM1722User manual Developing Applications on STM32CubeF4 with RTOS Introduction The STM32Cube TM  initiative was srcinated by STMicroelectronics to ease developers life by reducing development efforts, time and cost. STM32Cube TM  covers the STM32 portfolio.STM32Cube TM  Version 1.x includes: ã The STM32CubeMX, a graphical software configuration tool that allows to generate C initialization code using graphical wizards. ã  A comprehensive embedded software platform, delivered per series (namely, STM32CubeF4 for STM32F4 series) –The STM32CubeF4 HAL, an STM32 abstraction layer embedded software, ensuring maximized portability across STM32 portfolio –A consistent set of middleware components such as RTOS, USB, TCP/IP, Graphics –All embedded software utilities coming with a full set of examples. A Real Time Operating System is an operating system optimized for use in embedded/real time applications. Their primary objective is to ensure a timely and deterministic response to events. Using a real time operating system allows applications to be written as a set of independent threads that inter-communicate using message queues and semaphores.This user manual is intended for developers who use STM32CubeF4 firmware on STM32 microcontrollers. It provides a full description of how to use the STM32CubeF4 firmware components with a real time operating system (RTOS); this user manual comes also with description of a set of examples based on FreeRTOS using the common APIs provided by the CMSIS-OS wrapping layer.In the STM32CubeF4 firmware FreeRTOS is used as real time operating system through the generic CMSIS-OS wrapping layer provided by ARM. Examples and applications using the FreeRTOS can be direcltly ported on any other RTOS without modifying the high level  APIs, only the CMSIS-OS wrapper has to be changed in this case.Please refer to the release notes of the package to know the version of FreeRTOS and CMSIS-RTOS firmware components used with the STM32Cube TM . www.st.com Real Time Operating System  ContentsUM1722 2/26DocID025801 Rev 1 Contents 1Free RTOS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.2License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.3Free RTOS source organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.4Porting FreeRTOS on STM32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.5FreeRTOS API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81.6FreeRTOS memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.7FreeRTOS low power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.8FreeRTOS configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 2CMSIS-RTOS module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.1Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122.2CMSIS-RTOS API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3FreeRTOS applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.1Thread Creation example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163.2Semaphores examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.2.1Semaphore between threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173.2.2Semaphore from ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.3Mutexes example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.4Queues example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.5Timer example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203.6Low power example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25  DocID025801 Rev 13/26 UM1722List of tables 3 List of tables Table 1.Free RTOS API. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Table 2.CMSIS-RTOS API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Table 3.Free RTOS application categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Table 4.Comparison of power consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22Table 5.Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25  List of figuresUM1722 4/26DocID025801 Rev 1 List of figures Figure 1.FreeRTOS license . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6Figure 2.Free RTOS architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Figure 3.Free RTOS port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7Figure 4.FreeRTOS configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Figure 5.CMSIS-RTOS architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Figure 6.Thread example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Figure 7.Semaphore example. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Figure 8.Obtaining semaphore from ISR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Figure 9.Queue process. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Figure 10.Periodic timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21