STM32Cube Firmware Examples For STM32F4 Series

Transcription

AN4739Application noteSTM32Cube firmware examples for STM32F4 SeriesIntroductionThe STM32CubeF4 firmware package comes with a rich set of examples running onSTMicroelectronics boards. The examples are organized by board and provided withpreconfigured projects for the main supported toolchains (see Figure 1).Figure 1. STM32CubeF4 firmware components(YDOXDWLRQ ERDUGV'LVFRYHU\ ERDUGV670 1XFOHR ERDUGV'HGLFDWHG ERDUGV8VHU DSSOLFDWLRQ8WLOLWLHV SSOLFDWLRQ OHYHO GHPRQVWUDWLRQV7&3 ,386%*UDSKLFV) 7 ILOH 5726&06,6V\VWHP0LGGOHZDUH OHYHO 8WLOLWLHV%RDUG 6XSSRUW 3DFNDJH %63/RZ/D\HU // DUGZDUH EVWUDFWLRQ /D\HU / / DQG // 3,V 7KH VHW RI PLGGOHZDUH FRPSRQHQWV GHSHQGV RQ WKH SURGXFW 6HULHV March 2017DocID028077 Rev 406 9 1/47www.st.com47

Reference documentsAN4739Reference documentsThe reference documents are available on www.st.com/stm32cubefw:2/47 Latest release of STM32CubeF4 firmware package Getting started with the STM32CubeF4 firmware package for STM32F4 Series(UM1730) STM32CubeF4 demonstration platform (UM1743) STM32Cube Ethernet IAP example (UM1709)Description of STM32F4xx HAL drivers (UM1725)STM32Cube USB Device library (UM1734)STM32Cube USB Host library (UM1720)Developing Applications on STM32Cube with FatFS (UM1721)Developing Applications on STM32Cube with RTOS (UM1722)Developing Applications on STM32Cube with LwIP TCP/IP stack (UM1713)DocID028077 Rev 4

AN4739STM32CubeF4 examplesSTM32CubeF4 examplesThe examples are classified depending on the STM32Cube level they apply to. They arenamed as follows: Examples: the examples use only the HAL and BSP drivers (middleware not used).Their objective is to demonstrate the product/peripherals features and usage. They areorganized per peripheral (one folder per peripheral, for example TIM). Their complexitylevel ranges from the basic usage of a given peripheral (for example PWM generationusing timer) to the integration of several peripherals (for example how to use DAC forsignal generation with synchronization from TIM6 and DMA). The usage of the boardresources is reduced to the strict minimum. Examples LLThese examples use only the LL drivers (HAL drivers and middleware components notused). They offer an optimum implementation of typical use cases of the peripheralfeatures and configuration sequences. The examples are organized per peripheral(one folder for each peripheral, for example TIM) and run exclusively on Nucleo board. Examples MIXThese examples use only the HAL, BSP and LL drivers (middleware components notused). They aim at demonstrating how to use both HAL and LL APIs in the sameapplication to combine the advantages of both APIs:–The HAL offers high-level function-oriented APIs with high portability level byhiding product/IPs complexity for end users.–The LL provides low-level APIs at register level with better optimization.The examples are organized per peripheral (one folder for each peripheral, for exampleTIM) and run exclusively on Nucleo board. Applications: the applications demonstrate the product performance and how to usethe available middleware stacks. They are organized either by middleware (a folder permiddleware, for example USB Host) or by product feature that require high-levelfirmware bricks (for example Audio). The integration of applications that use severalmiddleware stacks is also supported. Demonstrations: the demonstrations aim to integrate and run the maximum numberof peripherals and middleware stacks to showcase the product features andperformance. Template project: the template project is provided to allow quickly building a firmwareapplication on a given board.The examples are located under STM32Cube FW F4 VX.Y.Z\Projects\. They all have thesame structure: \Inc folder containing all header files \Src folder containing the sources code \EWARM, \MDK-ARM, \SW4STM32, and \TrueSTUDIO folders containing thepreconfigured project for each toolchain. readme.txt file describing the example behavior and the environment required to runthe example.DocID028077 Rev 43/4747

STM32CubeF4 examplesAN4739To run the example, proceed as follows:Note:1.Open the example using your preferred toolchain.2.Rebuild all files and load the image into target memory.3.Run the example by following the readme.txt instructionsRefer to "Development toolchains and compilers" and "Supported devices and evaluationboards" sections of the firmware package release notes to know more about thesoftware/hardware environment used for the firmware development and validation. Thecorrect operation of the provided examples is not guaranteed in other environments, forexample when using different compiler or board versions.The examples can be tailored to run on any compatible hardware: simply update the BSPdrivers for your board, provided it has the same hardware functions (LED, LCD display,pushbuttons, etc.). The BSP is based on a modular architecture that can be easily ported toany hardware by implementing the low-level routines.Table 1 contains the list of examples provided within STM32CubeF4 firmware package.The total numbers of templates, templates LL, demonstrations, examples, examples LL,examples MIX and applications are highlighted in gray in the table.4/47DocID028077 Rev 4

Project NameDescriptionNUCLEO-F446ZE32F429I DISCOVERYSTM32446E F412ZGSTM324x9I EVALNUCLEO-F411RE32F4 DISCOVERYNUCLEO-F410xx32F469I DISCOVERY32F401C DISCOVERYSTM324xG EVALSTM32469I EVAL32F412G DISCOVERY32F413H DISCOVERYNUCLEO-F413ZHTemplatesLLModuleName32F411E DISCOVERYLevel-Starter projectThis projects provides a reference template through theLL API that can be used to build any l number of templates LL: 19Templates-Starter projectThis directory provides a reference template project thatcan be used to build any firmware application forSTM32F4xxxx devices using STM32CubeF4 HAL.DocID028077 Rev 4Total number of templates: 19-ExamplesADCThis example provides a description of how to use thedifferent BSP his example provides a short description of how to usetwo ADC peripherals to perform conversions ininterleaved dual-mode.---X----X-----XX---ADC InjectedConversionInterruptThis example describes how to use the ADC in interruptmode to convert data through the HAL API.---X----X-----XX---ADC RegularConversionDMAThis example describes how to use the ADC and DMAto transfer continuously converted data from ADC tomemory.XXXXX--XX-X-XXXXXXXADC RegularConversionInterruptThis example describes how to use the ADC in interruptmode to convert data through the HAL API.-X-XX--XX-----XXXXXADC RegularConversionPollingThis example describes how to use the ADC in Pollingmode to convert data through the HAL API.---X----X-----XX--XADC TriggerModeThis example describes how to use the ADC and TIM2to convert continuously data from ADC channel. Eachtime an external trigger is generated by TIM2 a newconversion is started by ADC.---X----X-----XX---ADC TripleModeInterleavedThis example provides a short description of how to usethe ADC peripheral to convert a regular channel inTriple interleaved mode.---X----X-----XX---5/47STM32CubeF4 examplesBSPAN4739Table 1. STM32CubeF4 firmware examples

NUCLEO-F446ZE32F429I DISCOVERYSTM32446E F412ZGSTM324x9I EVALNUCLEO-F411RE32F4 DISCOVERYNUCLEO-F410xx32F469I DISCOVERY32F401C DISCOVERYSTM324xG EVALSTM32469I EVAL32F412G DISCOVERY32F413H DISCOVERYNUCLEO-F413ZHModuleName32F411E DISCOVERYLevelCAN LoopBackThis example provides a description of how to set acommunication with the CAN in loopback mode.--------X-----X----CAN LoopbackThis example provides a description of how to set acommunication with the CAN in loopback mode.---X-----------X---This example shows how to configure the CANperipheral to send and receive CAN frames in normalmode. The sent frames are used to control LEDs bypressing key push button.--------X-----X----CEC DataExchangeThis example shows how to configure and use the CECperipheral to receive and transmit messages.---X---------------CEC ListenModeThis example shows how to configure and use the CECperipheral to receive and transmit messages betweentwo boards while a third one (the spy device) listens butdoes not acknowledge the received messages.---X---------------CECMultiAddressThis example shows how to configure and use the CECperipheral to receive and transmit messages in the casewhere one device supports two distinct logicaladdresses at the same time.---X---------------CRC ExampleThis example guides the user through the differentconfiguration steps by means of HAL API to ensure theuse of the CRC (Cyclic Redundancy Check) calculationunit to get a CRC code of a given buffer of data word(32-bit), based on a fixed generator polynomial(0x4C11DB7).-X-XX--XX-----XXXXXProject NameCANCAN NetworkingDocID028077 Rev 4ExamplesCECCRCDescriptionSTM32CubeF4 examples6/47Table 1. STM32CubeF4 firmware examples (continued)AN4739

STM32446E F412ZGSTM324x9I EVALNUCLEO-F411RE32F4 DISCOVERYNUCLEO-F410xx32F469I DISCOVERY32F401C DISCOVERYSTM324xG EVALSTM32469I EVAL32F412G DISCOVERY32F413H DISCOVERYNUCLEO-F413ZHCRYPAESModesThis example provides a short description of how to usethe CRYPTO peripheral to encrypt and decrypt datausing AES in chaining modes (ECB, CBC, CTR) and allkey sizes (128, 192, 256) Algorithm.--------X-----XX---CRYP AESCCMThis example provides a short description of how to usethe CRYPTO peripheral to encrypt data using AES withCombined Cipher Machine (CCM).--------X------X---CRYP AESDMAThis example provides a short description of how to usethe CRYPTO peripheral to encrypt and decrypt datausing AES-128 Algorithm with ECB chaining mode.--------X-----XX---CRYP AESGCMThis example provides a description of how to use theCRYPTO peripheral to encrypt and decrypt data usingAES with Galois/Counter Mode (GCM).--------X------X---CRYPDESTDESmodesThis example provides a short description of how to usethe CRYPTO peripheral to encrypt and decrypt datausing DES and TDES in all modes (ECB, CBC)Algorithm.--------X-----XX---CRYP TDESDMAThis example provides a short description of how to usethe CRYPTO peripheral to encrypt data using TDESAlgorithm.--------X-----XX---This example presents the MPU features onSTM32F4xxxx devices and it can be easily ported toany other STM32 device supporting MPU.-X-XX--XX-----XXX-XThis example shows how to modify the Thread modeprivilege access and stack. The Thread mode isentered on reset or when returning from an exception.---X----X-----XX--XThis example shows how to modify the Thread modeCORTEXM Procestack. The Thread mode is entered on Reset, and canssStackbe entered as a result of an exception xamplesCORTEXM MPUCORTEXMModePrivilegeCORTEXCORTEXMSysTickThis example shows how to use the defaultconfiguration of SysTick with a time base equal to 1 msin order to insert a delay between LEDs toggling.7/47STM32CubeF4 examplesDescription32F429I DISCOVERYDocID028077 Rev 4Project NameNUCLEO-F446ZEModuleName32F411E DISCOVERYLevelAN4739Table 1. STM32CubeF4 firmware examples (continued)

Description32F429I DISCOVERYSTM32446E F412ZGSTM324x9I EVALNUCLEO-F411RE32F4 DISCOVERYNUCLEO-F410xx32F469I DISCOVERY32F401C DISCOVERYSTM324xG EVALSTM32469I EVAL32F412G DISCOVERY32F413H DISCOVERYNUCLEO-F413ZHDACProject NameNUCLEO-F446ZEModuleName32F411E DISCOVERYLevelDAC SignalsGenerationThis example provides a short description of how to usethe DAC peripheral to generate several signals usingDMA controller.--XX----X-X-X-XX-X-DAC SimpleConversionThis example provides a short description of how to usethe DAC peripheral to do a simple conversion.---X----X-----XX---DCMICaptureModeThis example provides a short description of how to usethe DCMI to interface with camera module and displayin continuous mode the picture on LCD.---X----X-----XX---DCMISnapshotModeThis example provides a short description of how to usethe DCMI to interface with camera module and displayin snapshot mode the picture on LCD.---X----X-----XX---DFSDM AudioRecordThis example shows how to use the DFSDM HAL APIto perform stereo audio recording.----------------X--DFSDM PulseSki This example shows how to use the DFSDM HAL APIpperto perform stereo audio recording.-----------------X-This example provides a description of how to use aDMA channel to transfer a word data buffer from theFlash memory to embedded SRAM memory with FIFOmode enabled through the HAL API.---X----X-----XX-XXThis example provides a description of how to use aDMA channel to transfer a word data buffer from theFlash memory to embedded SRAM memory throughthe HAL API.XXXXX--XX-X-XXXXXXXDCMIDocID028077 Rev 4ExamplesDFSDMDMA FIFOModeDMADMAFLASHToRAMSTM32CubeF4 examples8/47Table 1. STM32CubeF4 firmware examples (continued)AN4739

ZGSTM324x9I EVALNUCLEO-F411RE32F4 DISCOVERYNUCLEO-F410xx32F469I DISCOVERY32F401C DISCOVERYSTM324xG EVALSTM32469I EVAL32F412G DISCOVERY32F413H DISCOVERYNUCLEO-F413ZHDMA2D MemToM This example provides a description of how to configureemDMA2D peripheral in Memory to Memory withWithBlendingblending transfer mode.--X-----X---X--X---DMA2D MemToM This example provides a description of how to configureemDMA2D peripheral in Memory to Memory transferWithLCDmode and display the result on LCD.--------X------X---DMA2D MemToM This example provides a description of how to configureemDMA2D peripheral in Memory to Memory with pixelWithPFCformat conversion transfer mode.--X-----X---X--X---DMA2D MemoryToMemoryThis example provides a description of how to configureDMA2D peripheral in Memory to Memory transfermode.--------X------X---DMA2D RegToMemWithLCDThis example provides a description of how to configureDMA2D periph

STM32Cube firmware examples for STM32F4 Series Introduction The STM32CubeF4 firmware package comes with a rich set of examples running on STMicroelectronics boards. The examples are organized by board and provided with preconfigured projects for the main supported toolchains (see Figure 1). Figure 1. STM32CubeF4 firmware components 06 9