Home

"user manual"

image

Contents

1. TAB gt Configuration gt System gt gt WWDG gt Parameter Settings Set prescaller to 8 WWDG window to 80 And free running counter to 127 Button OK atcndog Clocking WWDG counter clock Prescaler 8 WWDG window value 80 WWDG free running downcounter 127 Ly life augmented 23 Use WWDG e Now we set the project details for generation e Menu gt Project gt Project Settings Project Setings Set the project name Project location Type of toolchain Now we can Generate Code Menu Project Generate Code ISTM32FA39ZITX 1 Firmware Package and Version STM32Cube FW F4 V1 3 0 Use latest available version life augmented 23 Use WWDG e How calculate the window APB1 45MHz prescaller 8 twwdg min 7 Appi 4096 N WWDG PRESCALLER REFRESH 7 I wiNDOW 4096 8 127 80 34 2ms 1 twwdg a 4096 8 127 63 46 6ms We refresh the WWDG to 127 Ox3F Fixed 63 Refresh allowed Time Refresh not allowed life augmented T 6 0 CNT downcounter 23 Use WWDG e Solution WWDG Start USER CODE BEGIN 2 HAL WWDG Start amp hwwdg USER CODE END 2 e WWDG refresh USER CODE BEGIN 3 Infinite loop while 1 30ms 5015 is outside the WWDG window 40ms fits inside the window HAL
2. life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start ES Va DMA2 StreamO IRQHandler N e HAL IRQHandler HAL OK HAL ERROR HAL BUSY end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Generated in stm32f4xx it c Ly life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start DMA2 StreamO IRQHandler HAL OK HAL ERROR HAL BUSY end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Defined in stm32f4xx hal dma c Ly life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC Start DMA buffer transfer Not blocking function program can continue initializations tart process with interrupt generation at erra of process Start IT HAL DMA2_Stream0_IRQHandler HAL_OK HAL_ERROR HAL_BUSY end of process callback XferCpltCallback process Err
3. HSE M 1 Configure GPIO for LED toggling Clock Configuration overview 6 3 Low speed external clocks riot 2 e Clock sources e Internal oscillators LSE LSI 1 Low speed internal External clock sources oscillator LSE 32 KHz 2 High speed internal oscillator HSI RC External 32 768Hz crystal or external signal in bypass mode PLL Source Mux HSI Input frequency M Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 7 e Clock sources Internal oscillators LSI HSI 1 Low speed internal External clock sources oscillator e LSE crystal or external signal in bypass mode HSE 32 KHz 2 High speed internal oscillator External crystal 4 26MHz or external signal 1 50Mhz in bypass mode PLL Source Mux 4 High speed external clocks requ TN ESSA HSE M Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 8 3 Low speed external HSE He Clock sources clocks s nternal oscillators LSE e LSI LH Hel 1 Low speed internal External clock sources oscillator e LSE crystal or external signal in bypagS mode e HSE crystal 4 26MHz or external sighal 1 50MHz 32 KHz bypass mode 2 High speed internal HSI RC os
4. stm32f4xx discovery sdram c stm32f4xx_discovery_io c stm32f4xx_discovery_eeprom c stm32f4xx_discovery c 4 stm32f4xx_discovery c Utilities 19341 lis3dsh Use stm32f4xx hal i2c to m commutate with eeprom memory Fonts p M X HAL API EENET stm32f4xx_hal_ltdc c J stm32f4xx hal c stm32f4xx_ll_fmc c stm32f4xx_hal_i2c c 27 Use BSP to access EEPROM 1 BSP_SDRAM BSP SDRAM Confi 4 Application We use the project from BSP LCD lab 26 pO M because we want to display the memory e ss 8 513214 hal content on LCD E msp c a BSP ili9341 c stm32f429i_discovery c stm32f429i_discovery_Icd c stm321429i discovery sdram c amp O Drivers aC1CMSIS system_stm32f4xx c La C1STM32F4xx HAL Driver C 51013214 hal c Ha E stm32f4xx hal cortex c stm32f4xx hal crc c E 51013214 hal dma c stm32f4xx hal dma2d c 51013214 hal ex c Ha stm32f4xx hal flash c stm32f4xx flash ex c C stm32f4xx flash ramfunc c 5103214 hal gpio c stm32f4xx hal i2c c stm32f4xx hal Itdc c stm32f4xx hal pwr c stm32f4xx hal ex c 513214 hal rcc c 513214 hal rcc ex c Ha E stm32f4xx hal sdram c y stm32f4xx hal spi c iiie augmented 5103214 fmc c m 1 27 Use BSP to access EEPROM e We add the
5. Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags For Wake up we need to setup wake up pin HAL PWR EnableWakeUpPin uint32 t WakeUpPinx e Function to enter STANDBY Ly life augmented e HAL_PWR_EnterSTANDBYMode We can measure consumption To be able to reprogram the STM32 which is in LP mode use connection during reset option Category Runtime Checking Compiler Assembler Output Converter Ijet JTAGjet J4ink J Trace Stellaris Macraigor PE micro General Options T 0 ST LINK Reset Interface Clock setup JTAG CPU clock 720 SWO clock E Auto 2000 kHz SWD 05100 200 01 5 Use STANDBY mode Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags Function to enter SLEEP e HAL EnterSTOPMode uint32 t Regulator uint8 t STOPEntry e HAL PWREx EnterUnderDriveSTOPMode uint32 t Regulator uint8 t STOPEntry We can measure consumption USER CODE BEGIN 3 Infinite loop while 1 HAL GPIO TogglePin GPIOG GPIO PIN 14 HAL Delay 2000 HAL PWR EnableWakeUpPin PWR WAKEUP 1 HAL EnterSTANDBYMode USER CODE END 3 life augmented 5 Use STANDBY mode We cannot go into STA
6. One Pulse Mode O E Activated One Pulse Mode life au 5 i Activated 2 Configure EXT which turns LED e NVIC Configuration Enable interrupt for Priority Group 4 bits pre emption priority 0 bits for subpriority E Sort by Premption Priority and Sub Prority DENT 09 Show only enabled interrupts EXTI LineO Button OK Non Maskable Interrupt O D E Prefethfaut memoryacessfaut 1 1 1 p 0 02 Undefined instruction or ilegalstate p 0 2 Deg Mente System ee 1 OSS p 000 Preemption Priority Sub Priority Ly life augmented 2 Configure EXT which turns on LED e Now we set the project details for generation Menu Project Project Settings e Set the project name Project location Project Settings Type of toolchain 4 Project Folder Now we can Generate Code PAEMSSTIDocsISTMG2FA 4 training Murich 2014 Cube examples abs ab2_ EXT Menu gt Project gt Generate Code Toolchain IDE EWARM 6 70 xj Mcu and Firmware Package Mcu Reference 57 327429217 Firmware Package Name and Version STM32Cube FW_F4V1 3 0 V Use latest available version Ly life augmented 2 Configure EXT which turns LED HAL Library work flow 1 P
7. TOUT li lage fror n 2 5 HS EVEN 4 CH4 CH2 DO COL TOUT ST M 32 F429 OTG_HS_ LcD EVEN 7 SOF HSYNC VSYNC TOUT SP SCK DCMI_ TIM13 A LCD G2 TIM8 CH1 TIM2 jos ETR EN 25 ia I CH1 c 4 N c x 5 2 N TIM1 TIM3_ TIM8 CHIN CH2 CH1N TIM1 CI SE HERES d TIM1 12C3_ E c 4 E o 5 CH4 life augmented ETR e 3 g TIM1_ TIM3_ TIM8 BKIN CHT BKIN 25 121 4 UART Hardware preparation e We connect selected pins together by jumper this help us to create loopback UART om stn LOI ET life augmented 9 simple UART communication Create project in CubeMX Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx e CubeMX UART selection e Select USART1 in asynchronous mode Select PA9 and PA10 for USART1 if weren t selected UARTS 9 9 9 USART1_RX USART1 TX USART2 Ly life augmented simple UART communication n order to run on maximum frequency setup clock system Details in lab O Dre 14 To RTC KHz X 180 Ethernet PTP clock MHz LSIRC 180 to AHB bus core memory IWDG 2 32 KHz 225 To Cortex System timer MH
8. with interrupt Create project CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F 429 439 gt LQFP144 gt STM32F439ZITx CubeMX TIM selection e 6 Select clock source Internal clock Enable GPIO for LED 4 e Use ETR as Clearing Source C XOR activation life augmented 15 Use with interrupt CubeMX TIM configuration e Tao gt Configuration gt Control gt TIM1 Check the settings File Project Window Help 79 Pinout Clock Configuration Configuration onfiguration Middlewares C FATES L E User defined 9 FREERTOS E Enabled Peripherals S CRC T Activated C DMA2D i E Activated IWDG Activated G RCC High Speed Clock HSE lt RNG 0 7 Activated Clock Source Internal 5 6 TIM6 7 Activated C One Pulse Mode 9 lt 7 i E Activated 1 C One Pulse Mode life augmented Middlewares Analog System oma ll 11 4 E 2 5 9 WWDG 15 Use with interrupt TIM configuration e Tab Parameter Settings Prescaler to 18000 Counter period to 10000 Together with 180MHz TIMER1 clock we get period 1Hz Repetition Counter RCR 8 bits value Trigger Output TRGO Parameters Master Slave Mode Disable no sync between this TIM Master
9. 14 life augmented 4 STM32F4 Labs T O M A S Technically Oriented Microcontrolle V1 07 Application Services CONTENT 1 3 GPIO lab EXTI lab SLEEP lab STOP lab STANDBY lab DMA Poll lab DMA Interrupt lab RTC Alarm lab UART Poll lab UART Interrupt lab UART DMA lab e we c EU oe 25019 o STM32F42xx Technical Training 20 10 2015 CONTENT 2 3 12 SPI Poll lab 13 SPI Interrupt lab 14 SPI DMA lab 15 TIM Interrupt lab 16 TIM PWM out lab 17 TIM DMA lab 18 TIM Counter lab 19 DAC wave generation lab 20 ADC Poll lab 21 ADC Interrupt lab 22 ADC DMA lab life augmented STM32F42xx Technical Training 20 10 2015 23 24 22 26 27 28 3 3 WWDG lab IWDG lab FMC SDRAM BSP lab LCD BSP Print text lab 2 BSP EEPROM lab SPI BSP GYROSCOPE lab STM32F42xx Technical Training 20 10 2015 GPIO Lab 1 life augmented STM32F42xx Technical Training 20 10 2015 1 Configure GPIO for LED toggling Objective Learn how to setup pin and GPIO port in CubeMX How to Generate Code in CubeMX and use HAL functions Goal Configure GPIO pin CubeMX and Generate Code Add in to project HAL Delay function and HAL GPIO Toggle function Verify the correct functionality on toggling LED z e 3 1 Configure GPIO for LED toggling Create pro
10. 7 DMA Settings cero Settings 4 Configure the below parameters Button OK 59 ADCs Common Settings e DAC from previous Node Independent mode i Ej ADC Settings exam ple 4 Clock Prescaler PCLK2 divided by 2 Miidiewsres Le Resolution 12 bits 15 ADC Clock cycles Data Alignment Right alignment Scan Conversion Mode Disabled Discontinuous Conversion Mode Disabled DMA Continuous Requests Disabled Analog End Of Conversion Selection EOC flag at the end of single channel conversion Regular ConversionMode ADC Number Of Conversion External Trigger Conversion Edge DAC Sampling Time ADC_Injected_ConversionMode Number Of Conversions E WatchDog Enable Analog WatchDog Mode Continuous Conversion Mode ContinuousConvMode Parameter ipti Description y Enable or Disable the Continuous Conversion Mode life augmented 21 CubeMX ADC configuration e TAB gt NVIC settings Enable ADC1 interrupt e Button OK life augmented Use ADC with interrupt ADC1 Configuratio aneters Settings Settings t Table DC1 ADC2 and ADC3 global interrupts a 21 Use ADC with interrupt CubeMX NVIC configuration Because we want use the Systick for delay in interrupt The ADC inter
11. 90 APB1 Timer clocks MHz 2 Prescaler Enable CSS 0 90 2 peripheral clocks MHz frequency X2 180 2 timer clocks MHz 4 26MHz gt 9 48MHz clocks MHz 125 source Mux 96 125 clocks MHz Kise 7 8 SAI1 A source Mux REAL ef 0 0 5 4 i225 5 clocks MHz 2 source 4 T 5 11 8 so Mu qe gt 1225 clocks MHz MCO1 source Mux 08 15 2255 SE N 9 yY MHz MCO2 Qee 1 i L 125 CD TFI clocks MHz life augmented 12 Simple communication CubeMX SPI configuration e Tab gt Configuration gt Connectivity gt SPI1 e Check the settings File Project Window Help Button Bul g 79 Pinout Clock Configuratio Po onfiguration MiddleWare FATES The CLK frequency with core on 180MHz is now 45MHz e For this clock use Ac HIGH GPIO speed LAGH Clock Parameters C IWDG Prescaler for Baud Rate 2 8 9 RCC Clock Polarity Low High Clock Phase CPHA 1Edge Connectivity B RNG Advanced Parameters 4 CRC Calculation Disabled 2 TIM6 68 TIM 7 Ac 9 Ly life augmented 12 Simple SP communication e CubeMX 5 GPIO configuration
12. Button OK close project options Include directory PROJ_DIRS Inc PROJ_DIR Drivers S TM32F 4xx_HAL_Driver Inc PROJ DIR 25 Use BSP for SDRAM initialization 88 Module Selection PPSESSPPSESSESSPSSESSE SEES SS Now last thing 5 allow to include lem This is the list of modules to be used in the HAL driver new HAL files which we added 22 DES eue define HAL CAN MODULE ENABLED e Open stm32f4xx hal conf h in lnc define cac define HAL CRYP MODULE ENABLED define HAL DAC MODULE ENABLED Uncomment files which we added define HAL 20 MODULE ENABLED HAL_SDRAM_MODULE_ENABLED define HAL NAND MODULE ENABLED HAL I2C MODULE ENABLED tetine HAL NOR MODULE ENABLED define HAL PCCARD MODULE ENABLED HAL SPI MODULE ENABLED define HAL IWDG MODULE ENABLED define HAL LTDC MODULE ENABLED define HAL RNG MODULE ENABLED define HAL RTC MODULE ENABLED define HAL SAI MODULE ENABLED i HAL SD MODULE ENABLED f ENAB define HAL UART MODULE ENABLED define HAL USART MODULE ENABLED define HAL IRDA MODULE ENABLED define HAL SMARTCARD MODULE ENABLED define HAL WWDG MODULE ENABLED define HAL PCD MODULE ENABLED define HAL HCD MODULE ENABLED define HAL
13. USER CODE BEGIN 2 J ENABLE DMA amp htimi UPDATE HAL Start amp hdma tim1 up uint32 t data uint32 t amp GPIOG ODR 2 HAL TIM Base Start amp htim1 USER CODE END 2 life augmented TIM as counter lab 18 18 Use as pulse counter Objective Learn how to setup TIM as counter in CubeMX How to Generate Code CubeMX and use HAL functions e Indicate TIM count 5 button press with LED toggle e Goal e Configure as counter in CubeMX and Generate Code Learn how start timer and handle interrupt Verify the correct functionality with LED toggle after 5 button press z e 18 Use as pulse counter Create project in CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX TIM selection Select TIM clock source ETR2 Enable GPIO for LED PG14 Activate Break Input i Use as Clearing Source XOR activation z One Pulse Mode life augmented Hard ware setting Connect Button PAO and ETR pin with wire together life augmented 18 Use as pulse counter CubeMX TIM configuration e Tao gt Configuration gt Control gt TIM1 Check the settings File Project Window Help 79 Pinout Clock Configuration Configuration onfiguration Middlewares C
14. amp 5 LCO VSYNC DE LCD TFT lt 2 4 compl chan CH1 1 4 N 4 chan 0411 4JETR BKIN as AF 4 compl chan 111 490 4 chan 1 1 4 ETR BIN AF Ls sel 7 MOSI SD 50 50 ext SCK CK NSS WS as AF perle DAC OUT DAC2 OUT asAF AF overview Ly life augmented Configure GPIO for L gt GPIO PORT coron coni 23 PG 15 0K F PH 15 0 28 PI 15 0 12 3 Core memory ie DMA1 168AF EXT IT WKUP K D 7 0 CMD as a y SDIO MMC g gt 4 compl chan TIM1 CH1 1 4 N 4 chan TIM1 1 1 4 5 BKIN as AF 4 compl chan TIM8 1 1 41 m 4 chan TIM8 CH1 1 4 BKIN as AF 2 channels as AF DMA2 2 AHB APB1 TIM1 PWM 16b gt TIM8 PWM16b K gt 2 9 16 5 TIM10 165 gt gt 11 16b lt gt 1 RX TX CK Smeard CTS RTSasAF USARTI A smoard ic A ore 1 g lt 2 bus clock 1 ke aKo Pa TIM7 16 Kt qU SCK NSS AF CD se k SCK NSS as AF VDDA VDDREF gt sensor gt 8 analog inputs common han ADCi
15. stm32f4xx hal spi c stm32f4xx fmc c life augmented 26 Use BSP for LCD init and writing The copy part In our project in Drivers folder create folder Utilities J Drivers BSP_SDRAM e Now into CubeMX repository STM32Cube_FW_F4_V1 3 0 Utilities copy Fonts into Utilities folder BSP_SDRAM 4 life augmented 26 Use BSP for LCD init and writing We add the driver for LCD from HAL 15 32 4 _ _ Right click on STM32F4xx_HAL_Drive gt ADD stm32f4xx hal c from Drivers STM32F4xx_ Driven Src stm32f4xx hal cortex c 3214 hal a EI hal_cre c Stm32f4xx hal dma2d c Ha E 517032146 hal flash c 48 0 stm32f4xx flash ex c 48 stm32f4xx hal flash ramfunc c a E 83215 hel gio C TEXTES B s EUR hall ex c 48 stm32f4xx hal rcc c La E 513214 hal rcc ex c La stm32f4xx hal sdram c La stm32f4xx hal La stm32f4xx Il fmc c gt 5 26 Use BSP for LCD init and writing We add the driver for BSP LDC e Right click BSP gt ADD from Drivers BSP STM32F429I Discovery e stm321429i discovery Right click on BSP gt ADD from Drivers BSP Components ili9341 e ili9341 c i 1 EY e Dr Ta z e 26 Now las
16. Learn how to send and receive data over SPI without interrupts Verify the correct functionality z e 3 12 Simple SP communication Create project CubeMX Menu gt File gt New Project e Select STM32F4 gt STM32F 429 439 gt LQFP144 gt STM32F439ZITx Pin selection e We looking for free pins where is possible to create wire loopback connection igmented 12 Simple communication Create project CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX SPI selection e Select SPI1 Full Duplex Master e Select PA5 PA6 for SPI1 if weren t selected 0 0 17 O ae 2 5 life augmented Hardware preparation e Connect 6 and together with jumper 1 ES Cy C ar Aa 77 gt SKI UXOR ECT life augmented 12 Simple SP communication In order to run on maximum frequency setup clock system Details in lab 0 To RTC KHz 180 Ethernet PTP clock MHz LSIRC 2 180 to AHB bus core memory IWDG 2 32 KHz 225 To Cortex System timer MHz HSI RC 16 FCLK Cortex clock MHz SYSCLK MHz AHB HCLK MHz ADB1 Prescaler 180 10 45 APBi peripheral clocks MHz x2
17. Ly life augmented 20 Use ADC in polling mode Solution Main loop with DAC set and ADC set USER CODE BEGIN 3 Infinite loop while 1 HAL_ADC_Start amp hadc1 HAL ADC PollForConversion amp hadc1 10 value adc HAL ADC GetValue amp hadc1 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 12B R value dac value if value dac 4095 value dac 0 HAL Delay 1 USER CODE END 3 life augmented 20 Use ADC in polling mode Test the functionality We need the address of variable value adc This can be found usually in debug mode in watch my address is 0x2000005C depends on compilator and optimizations e Start the STMStudio Set the ST Link SWD z VarViewer Right click into Display variable settings Select NEW w 1888888888888 Ly life augmented 20 Use ADC in polling mode STM studio settings Set value adc 8007688 Display Variables settings my 0x2000005C ed Set 16bit unsigned val 0 2000005 unsigned 16 bit Right click on this line Select Send VarViewer 1 Ly life augmented 20 Use ADC in polling mode STM studio settings Viewers settings is on bottom Set the correct upper value to 4096 1 2bit 3 20 Use ADC in polling mode STM studio setti
18. SPI CLK frequency with core on 180MHz is now 45 2 For this clock use HIGH GPIO speed Tab gt Configuration gt System gt gt GPIO e Tab gt SPI1 Seth High output speed Button OK Ly 9 Select Pins from table to configure them MullipleseleconisAlowed life augmented Group By IP 12 Simple communication e Now we set the project details for generation e Menu gt Project gt Project Settings e Projectsetings 220 s Set the project name Project location 0 Project Name Type of toolchain SPI_Pool Project Location Now we can Generate Code 1D Radek _Training_examples F4_prague 2014 modif_my abs Menu gt Project gt Generate Code ae D Radek __Training_examples F4_prague_2014_modif_my Labs SPI_Pool Firmware Package Name and Version STM32Cube FW_F4V1 3 0 life augmented 12 Simple communication HAL Library transmit receive flow Peripheral Initializations Polling process HAL_SPI_TransmitReceive Function blocks Polling with timeout HAL_TIMEOUT HAL_OK HAL_ERROR HAL_BUSY z e 3 12 Simple communication Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For transmit and receive use function e HAL SPI TransmitReceive SPI HandleTypeDef hspi uint8 t pT
19. USB FS tree 25 Prescaler 42 2 52 2 peripheral clocks MHz X2 150 2 timer clocks MHz 4 48MHz docks MHz Main PLL Q I2S source Mux life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 25 MCO output e TAB gt Pinout e RCC gt MCO1 checkbox TAB gt Clock Configuration Now the MCO1 output can be set V Master Clock Output 1 MCO1 source Mux Master Clock Output 2 LSE i E Audio Clock Input 125 CKIN 4 Set MCO1 HSI PLLCLK L 3 CubeMX assign pin Pis 1 Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 26 RTC gt e RCC gt RTC set RTC feature TAB gt Clock Configuration Now the RTC can be set To RTC KHz 3 Set RTC Tamper 1 Routed to 1 ibration Disable Reference dock detection 151 RC 32 To IWDG KHz 1 Configure GPIO for LED toggling Clock Configuration overview 26 Prescaler 92 USB 1 USB disabled 5 A 2 z 6 TAB gt Pinout l 2 16 2 timer clocks e RCC gt USB_OTG FS set feature Main PLL Q 125 m Mux TAB gt Clock Configuration 2 USB enable 9 USB OTG FS Now the USB clock can be set Device Only i E Activate SOF E Activate VBUS 3 CubeM
20. Project Project Settings Set the project name Project location Type of toolchain Now we can Generate Code D Wadek Training 4 prague 2014 modif Menu gt Project gt Generate Code D Radek __Training_examples F4_prague_2014_modif_my Labs DMA_M2M Toolchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference STM32F439ZITx Firmware Package Name and Version STM32Cube FW F4V1 3 0 Ly life augmented 6 Use DMA 2 transfer Start process DMA same for TIM ADC Non blocking start process The end of the process must be checked by polling 1 init DMA Peripheral Initializations 2 Start DMA Start Process HAL DMA Start 3 DMA transfer data 4 Check if transfer is complete Poll for process complete PollForTransfe life augmented 6 Use DMA in M2M transfer e Return values Most of CubeMX functions have return values which indicate if operation was successful timeout occurs of function end with error s recommended handle this return values to be sure that program working as expected Ex Poll for process complete HAL DMA PollForTransfer HAL OK HAL ERROR HAL BUSY DMA transfer was successfully finished and data was transferred to destination without error Ly life augmented 6 Use DMA M2M transfer e Return
21. RTC Clock Mux Hen LSE 2 To RTC KHz LSIRC 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AHB Prescaler HCLK MHz APB1 Prescaler 180 45 peripheral clocks MHz 180 MHz max gt 2 50 Timer clocks MHz APB2 Prescaler ma 90 APB2 peripheral clocks MHz 90 MHz max Input frequency X2 lt gt 180 2 clocks MHz gt 9 48MHz clocks MHz 125 source Mux 125 clocks MHz 5 source 2 PLLI2S Q o SAI A clocks MHz 2 source Mux pre cu 2 lt 4 lt SERES l SAI B docks MHz MCO1 source Mux 4 7 44 gt 1 9 MHz MCO1 0 4 16 gt 4 2 5 2 1225 LCD TFT clocks MHz ys gt PLLSAI B life augmented 7 Use 2 transfer with interrupt DMA configuration TAB gt Configuration e System gt DMA TAB gt DMA2 e Button ADD 1 TAB gt Configuration 4 Add DMA channel 7 Use 2 transfer with interrupt DMA configuration Select MEMTOMEM DMA request Normal mode Increment source and destination address FIFO setup Byte data
22. gt ie ie ie ie R te io io AT P Ms a wr 13211115500 Solution explanation www st com stm32 STM32F42xx Technical Training 20 10 2015
23. 1 L to the 3 ADCs mid DAC2 8 analog inputs common 777 ADC2 _ tothe ADC1 82 F lt 8 analog inputs for ADC3 APCS SVODA DAC1_OUT DAC2_OUT as AF as AF ED toggling Standby interface VBAT 1 65 to 3 6 V 6032 menm OSC32 OUT AF1 rry AF APB1 bus clock NT 4 channels ETR as AF 4 16 K 4 channels ETR as channels e CL 1 channel AF CR Ky CTS RTS as AF RX TX as AF CTS RTS as AF 6 RX TX as AF C RX TX as AF RX TX as AF RX TX as AF MOSI SD MISO SD ext SCK CK 5 253 I2C1 SMBUS 2 channels as 1 pe NSS WS as AF s MOSI SD MISO SD ext SCK CK C SCL SDA SMBA as AF 5 SCL SDA SMBA as NSS WS MCK as AF Lem ap Digital filte SCL SDA SMBA AF bxCAN2 6 TX RX MS30426V5 Configure GPIO for LED toggling External memory controller FMC CLK NE 3 0 A 23 0 SRAM SDRAM PSRAM D 31 0 NOEN NWEN R NBL 3 0 SDCLKE 1 0 SDNE 1 0 M 64 KB M data Clock Configuration Flash Card J weu PO Can SOnWE A overview 23 STDOISWD J EAE
24. 4 peripheral clocks MHz AHB Prescaler HCLK MHz 11 180 2 90 1 5 2 Prescaler 728852 sou 30 APB2 peripheral clocks MHz Input frequency X2 150 2 clocks MHz 4 26 gt 90 48MHz clocks MHz 125 clocks MHz PLLI2S 1225 clocks MHz SAI B clocks MHz Ly life augmented LCD TFT clocks MHz PLLSAI 11 Use UART with DMA transfer CubeMX UART configuration e Tab gt Configuration gt Connectivity gt USART 1 STM32CubeMX Untitled STM32F429ZITx File Project Window Help RSU Si Middlewares E Activated RNG E Activated USARTI VP 6 LEN 7 One Pulse Mode configured You can generate code using the current values 6 7 Activated i One Pulse Mode USART1 L Mode Asynchronous WWDG 7 Activated Connectivity System lite augment 11 Use UART with DMA transfer e CubeMX USART configuration check BaudRate dns S Parameter setings 9 Configure the below parameters Stop bits Data direction 8 Bits induding Parity Oversampling ie 1 Baud Rate BaudRate must be between 110 Bits s and 10 5 MBits s life augmented 11 Use UART with DMA transfer CubeMX USART configuration DMA settings TA
25. Low speed internal 32 KHz HSI RC Low speed internal LSI RC oscillator Table 42 LSI oscillator characteristics 1 swa mvp ee tQ 6 9 9 power consumpson oa 96 1 Voo 3 V T4 40 to 105 unless otherwise specified 2 Based on characterization not tested in production 3 Guaranteed by design not tested in production quency PLL Source Mux 16 M Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 5 e Clock sources Internal oscillators LSI e HSI External clock sources Input frequency able 41 oscillator characteristics Con Parameter min Typ Max 8 User trimmed with the CR E RN 401087091 9 09 10085 4 4 Accuracy of the HSI oscillator Factory calibrated 86 2 HSI oscillator startup time 2 HSI oscillator 1 3 3 V Ta 40 to 105 unless otherwise specified 2 Guaranteed by design not tested in production 3 Based on characterization not tested in production aquency Ly life augmented HSE HS 5 LSE 1 Low speed internal oscillator 32 KHz 2 High speed internal HSI RC oscillator PLL Source Mux HSI VN
26. gt The HSE is now available TAB gt Clock configuration PLL Source Mux Click on Blue square and change frequency on 8 2 Input frequency 4 26MHz z e 3 1 Configure GPIO for LED toggling Clock Configuration overview 12 Clock tree for core description System multiplexer e PLL e PLL source multiplexer HSI RC PLL Source Mux Input frequency 46 i X192 7 2 HSE 4 26MHz Clock source for PLL life augmented PLL multiplies frequency Frequency of Core AHB bridge and memories System Clock Mux HS HSE SYSCLK MHz AHB Prescaler HCN MHz 16 1 16 m 180 MHz max PLLCLK w Enable CSS Multiplexer select clock source for system 1 Configure GPIO for LED toggling Clock Configuration overview 13 Core clocked from HSI default option after reset as system source System frequency 16MHz AHB Prescaler HCLK MHz 160 MHz max AHB prescaler divide by 1 TEA Core frequency is now 16MHz 1 Configure GPIO for LED toggling Clock Configuration overview 14 Core clocked from HSE HSE as system source System frequency 8MHz HSE crystal or external signal A SYSCLK MHz AHBPrescaler HCLK MHz 8 1 180 MHz PLL Source w 24 prescaler Input frequenc
27. lt 4 lt SERES l SAI B docks MHz MCO1 source Mux 4 7 44 gt 1 9 MHz MCO1 0 4 16 gt 4 2 5 2 1225 LCD TFT clocks MHz ys gt PLLSAI B life augmented 8 Use RTC and Alarm with interrupt RTC Configuration TAB gt Configuration Control RTC Set parameters which you want File Project Window Help BSU GSi tA Configuration figura Configuration Power Consumption Calculator 9 RTC Configuration 1 TAB gt Configuration Data Format Day Light Saving value of hour a Alarm Mask None All Alarm SS fields are masked Alarm Date Week Day Sel Date 1 life augmented 8 Use RTC and Alarm with interrupt Parameter Settings Settings 1 gt NVIC RTC Configuration NVIC TAB gt NVIC Setup Enable Alarm interrupt Button OK 2 Enable RTC Alarm life augmented 8 Use RTC and Alarm with interrupt e Now we set the project details for generation Menu Project Project Settings 4 Set the project name Project location Type of toolchain Now we can Generate Code D XRadek Training exampleslF4 prague 2014 modif myW abs Menu Project Generate Code i Reet m 2 D Radek __Training_examples 4_prague_2014_modif_my Labs RTC_Alarm STM32F439Z
28. stm32f4xx hal uart c s m Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT ES HAL_UART_IRQHandler USART1_IRQHandler 22 HAL HAL_ERROR HAL_BUSY e end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Generated in stm32f4xx it c Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY USART1 IRQHandler end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Defined in stm32f4xx hal uart c Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Send buffer over UART Not blocking function program can continue tart process with interrupt generation at erra of process HAL UART Transmit IT HAL_UART_IRQHandler USART1_IRQHandler HAL_OK HAL_ERROR HAL_BUSY end of
29. 5 To Cortex System timer MHz 180 FCLK Cortex clock MHz HCLK MHz 1 Prescaler 180 M i MH 45 1 peripheral clocks MHz 180 MHz max X2 gt 90 APB1 Timer clocks MHz APB2 Prescaler 2 90 APB2 peripheral clocks MHz 90 MHz max vr X2 1502 APB2timer clocks MHz Ys i life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 18 AHB prescalers and peripheral speed Systick divider HCLK to AHB bus core memory and DMA MHz To Cortex System timer MHz FCLK Cortex clock MHz HCLK MHz 1 Prescaler 180 M i 45 1 peripheral clocks MHz 180 MHz max X2 gt 90 APB1 Timer clocks MHz APB2 Prescaler 2 90 MHz 90 2 peripheral clocks MHz vs X2 1502 APB2timer clocks MHz Ys life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 19 APB prescalers and peripheral speed 2 Ethernet clock MHz External memory core memory controller clock To Cortex System timer MHz FCLK Cortex clock MHz HCLK MHz 180 180 1 Prescaler 4 M 45 MHz men 45 APB1 peripheral clocks MHz X2 gt 90 APB1 Timer clocks MHz APB2 Prescaler 2 90 MHz 90 2 peripheral clocks MHz vs X2 1502 APB2timer clocks MHz Ys life augmented 1 Configure GPIO for LED toggling Clock C
30. BSP_GYRO_GetXYZ valxyz WES 45 22 Display sprintf buffer x f valxyz BSP_LCD_DisplayStringAtLine 2 buffer Display Y sprintf buffer y F valxyz 1 BSP_LCD_DisplayStringAtLine 3 buffer Display Z sprintf buffer z F valxyz 2 BSP_LCD_DisplayStringAtLine 4 buffer Delay HAL Delay 1000 USER CODE END 3 life augmented Appendix A install life augmented install CubeMX tool htto www st com web catalog tools FM147 CL1794 SC961 SS1533 PF259242 s searchtype partnumber The CubeMX tool need the java Please check if you have actual java on your pc for sure 32bit and 64bit version e Optionally you can download the Cube packages for STM32 device if you don t want to download them throe CubeMX STM32CubeLO e STM32CubeL 1 STM32CubeFO STM32CubeF2 STM32CubeF3 STM32CubeF4 Ly life augmented install Install the After installation run CubeMX In case you download the package from web we need to find the place where they need to be stored File Project Window Help a F1 m 0 O About Alt A 6 Check for Updates Alt C Install New Libraries Alt U Updater Settings 5 e MENU gt Help gt Updater Settings You will see where is the repository folder Default is C User Acc_name STM
31. CODE BEGIN 3 Infinite loop while 1 HAL UART Transmit amp huart1 data 10 1000 USER CODE END 3 T 2 gt 9 Simple UART communication Receive solution Create data structure for data USER CODE BEGIN uint8 t data 10 USER CODE END 0 Call transmit function from while loop USER CODE BEGIN 3 Infinite loop while 1 HAL UART Receive amp huarti data 10 1000 USER CODE END 3 T 2 gt UART Interrupt lab 10 10 Use UART with interrupt Objective Learn how to setup UART with interrupts CubeMX How to Generate Code CubeMX and use HAL functions Create simple loopback example with interrupts Goal Configure UART in CubeMX and Generate Code Learn how to send and receive data over UART with interrupts Verify the correct functionality z e 10 Use UART with interrupt Create project in CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx Pin selection t will be same as previous lab we use again PA9 and 10 UARTS UART7 UARTS USART1 Flow Control 85232 Disable 5 USART2 USART1 RX USART1 TX 9 9 9 9 Ly life augmented Hardware preparation e We connect selected pins together by jumper this help us to create loopback UART life augmented 10 Use
32. DMA MODULE ENABLED define HAL RCC MODULE ENABLED define HAL FLASH MODULE ENABLED define HAL PWR MODULE ENABLED define HAL CORTEX MODULE ENABLED 26 Use BSP for LCD init and writing e Into main c now we modify include from stm321429i discovery sdram h to 3214291 discovery lcd h USER CODE BEGIN Includes include stm32f429i discovery lcd h USER CODE END Includes And remove the 5 SDRAM Init USER CODE BEGIN 2 USER CODE END 2 26 Use BSP for LCD init and writing e Simple LCD demonstration USER CODE BEGIN 2 BSP_LCD_Init init LCD set the layer buffer address into SDRAM BSP LCD LayerDefaultInit 1 SDRAM DEVICE ADDR BSP LCD SelectLayer 1 select on which layer we write BSP LCD DisplayOn turn on LCD BSP LCD Clear LCD COLOR BLUE clear the LCD on blue color BSP LCD SetBackColor LCD COLOR BLUE set text background color BSP LCD SetTextColor LCD COLOR WHITE set text color fec ENS write text BSP LCD DisplayStringAtLine 2 Cube STM32 BSP LCD DisplayStringAtLine 3 5 BSP LCD DisplayStringAtLine 4 LCD DEMO USER CODE END 2 fe augmented BSP EEPROM lab 27 27 Use BSP to access EEPROM Objective Learn how import BSP EEPROM into project We use the project from lab 26 Which part need to by configured in GUI Try to write text into EEPROM and read it Read text from EEPROM and display it on LCD Goal Successful
33. FATES L E User defined C 9 FREERTOS E Enabled Peripherals S CRC T Activated C DMA2D i E Activated IWDG Activated G RCC High Speed Clock HSE lt RNG 0 7 Activated Clock Source Internal 5 6 TIM6 7 Activated C One Pulse Mode 9 lt 7 i E Activated 1 C One Pulse Mode life augmented Middlewares Analog System 5 9 WWDG 18 Use as pulse counter CubeMX TIM configuration Tab gt Parameter Settings the Dcow Porcio Counter set to 5 5 button press Counter Settings Clock set the ETR pin filter and Prescaler PSC 16 bits value edge reaction Repetition Counter RCR 8 bits value Trigger Output TRGO Parameters Master Slave Mode Disable no sync between this TIM Master and its Slaves Trigger Event Selection Reset UG bit from TIMx_EGR Clod Clock Filter 4 bits value 0 Clock Polarity non inverted Clock Prescaler Prescaler not used life augmented 18 Use pulse counter CubeMX TIM configuration Tab gt NVIC Settings eon runc EET e Enable TIM1 Update interrupt Button OK Ly life augmented 18 Use as pulse counter e Now we set the project details for generation Menu gt Project gt Project Settings Prcject setina Set the
34. GPIO MODULE ENABLED define HAL MODULE ENABLED define HAL FLASH MODULE ENABLED y define HAL PWR MODULE ENABLED life augmented define HAL CORTEX MODULE ENABLED 1 25 Use BSP for SDRAM initialization Into main c now we add include of stm321429i discovery sdram h USER CODE BEGIN Includes include stm32f429i discovery sdram h USER CODE END Includes Now we can use the SDRAM init functions from BSP USER CODE BEGIN 2 BSP SDRAM Init USER CODE END 2 Now you can try to write into SDRAM area In stm321429i discovery sdram h you can find where is the SDRAM memory and how is their size e SDRAM DEVICE ADDR uint32 1 0 00000000 e SDRAM DEVICE SIZE uint32 1 0 800000 SDRAM device size in MBytes 25 Use BSP for SDRAM initialization gt SDRAM test USER CODE BEGIN PV volatile uint32 t value USER CODE END PV USER CODE BEGIN 2 BSP SDRAM Init uint32 t SDRAM DEVICE ADDR 0x12345678 value uint32 t SDRAM DEVICE ADDR USER CODE END 2 4 2 gt BSP LCD lab 26 life augmented STM32F42xx Technical Training 20 10 2015 26 Use BSP for LCD init and writing Objective Learn how import BSP LCD into project Because the LCD use the SDRAM we use project from lab 25 Which part need to by configured in GUI Try to write text on LCD Goal Successfully import BSP LCD into your project Learn which part you
35. Init GPIO and NVIC for UART Ly life augmented 9 Simple UART communication HAL Library init flow 2 Call UARTI init MX USART1 UART Init function Init UART1 structure 3 Store UART1 configuration into structure 0 6 HAL_UART_Init amp huart1 aaa Function wrote parameters from structure HAL_UART_Msplnit callback into UART1 registers Init GPIO and NVIC for UART life augmented 9 Simple UART communication HAL Library init flow 2 Call UARTI init MX USART1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure E huart 4 Write to UART1 registers AL UART Init amp 6 HAL_UART_Msplnit callback a Optional callback from M 1 HAL UART Init function be default empty weak Init GPIO and NVIC for UART function Ly life augmented 9 Simple UART communication HAL Library init flow 2 Call UARTI init MX USART1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure HAL UART Init amp huart Write to UART1 registers C HAL_UART_Msplnit callback a CubeMX configure here UART1 GPIOs and enable UART1 clock Init GPIO and NVIC for UART system Ly life augmented 9 Simple UART communication HAL Library init flow 2 Call UARTI init MX USART1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure HAL_
36. M F Activated i One Pulse 5 TIM7 Activated One Pulse Ma life augmented Apply k J 4 19 Use DAC as wave generator e Now we set the project details for generation Menu gt Project gt Project Settings ease Set the project name Project location Type of toolchain I Project Location Now we can Generate Code Dade Training examples r4 prague 2014 modf my abel Project Folder Menu Project Generate Code 1 5 STM32Cube FW 4 1 3 0 V Use latest available version life augmented 19 Use DAC as wave generator Start process DAC generation same for DMA ADC Non blocking start process Peripheral Initializations Start Process HAL DAC Start Set value HAL DAC SetValue 5 z e 42 3 19 Use DAC as wave generator Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags e and USER CODE BEGIN USER CODE END tags For DAC start use function e HAL DAC Start DAC HandleTypeDef hdac uint32 t Channel DAC set DAC value e HAL DAC SetValue DAC HandleTypeDef hdac uint32 t Channel uint32 t Alignment uint3
37. Menu gt Project gt Project Settings e Project seins 25200 X e Set the project name Project location Project Name Type of toolchain mex Now we can Generate Code Traring examples prague 2014 Menu Project Generate Code Dade 0 14 a STM32F439ZITx Firmware Package Name and Version STM32Cube FW F4 V1 3 0 Use latest available version L life augmented 13 Use with interrupt HAL Library SPI with IT transmit receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL SPI TransmitReceive IT HAL OK HAL ERROR HAL BUSY HAL SPI IRQHandler IRQHandler end of process callback HAL SPI TxRxOCpltCallback process Error callback HAL SPI ErrorCallback Ly life augmented 13 Use SPI with interrupt Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For transmit use function e HAL SPI TransmitReceive IT SPI HandleTypeDef hspi uint8 t pTxData uint8_t oRxData 16 t Size igmented 13 Use SPI with interrupt Buffer definition USER CODE BEGIN 0 uint8 t tx_buff 0 1 2 3 4 5 6 7 8 9 uint8 t rx buff 10 USER CODE END 0 Sending and recei
38. Output Configure Button as GPIO EXTIX E en b 25 GPIO_EXTIO 100nF o m N gt SB2 0 R2 9 USER amp WAKE UP Button 220K v 2 Configure EXT which turns on LED In order to run on maximum frequency setup clock system Details in lab O RTC Clock Mux Hen LSE 2 To RTC KHz LSIRC 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AHBPrescaler HCLK MHz APB1 Prescaler 180 5 45 APB1 peripheral clocks MHz 180 MHz max 3 gt 2 90 APBiTimerclocks MHz 2 Prescaler ma 90 2 peripheral clocks MHz Input frequency 2 1 0 2 clocks MHz i gt 30 48 clocks MHz 125 source Mux pasara 125 clocks MHz 5 source 2 PLLI2S Q o SAI A clocks MHz 2 source Mux pre mp B source Mux 2 44 4 5 SERES l SAI B docks MHz MCO1 source Mux 5 P 7 4 T 1 e 4 MHz 1 D 16 gt 4 2 5 2 M 1225 LCD TFT clocks MHz iJ gt PLLSAI B life augmented 2 Configure EXT which turns LED e GPIO Configuration e TAB gt Configuration gt System gt GPIO
39. Receive error HAL UART ErrorCallback Ly life augmented HAL IRQHandler 11 Use UART with DMA transfer Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For transmit use function e HAL _UART_Transmit_DMA UART_HandleTypeDef huart uint8 t pData uint16 t Size For receive use function e HAL UART Receive DMA UART HandleTypeDef huart uint8_t pData uint16 t Size Ly life augmented 11 Use UART with DMA transfer Buffer definition USER CODE BEGIN 0 uint8 t tx_buff 0 1 2 3 4 5 6 7 8 9 uint8 t rx buff 10 USER CODE END 0 Sending and receiving methods with DMA USER CODE BEGIN 2 HAL UART Receive DMA amp huarti1 nrx buff 10 HAL UART Transmit DMA amp huarti tx buff 10 USER CODE END 2 34 2 gt 11 Use UART with DMA transfer Complete callback check We put breakpoints on NOPs to watch if we receive complete buffer USER CODE BEGIN 4 void HAL UART RxCpltCallback UART HandleTypeDef huart __NOP check if we receive all data USER CODE END 4 4 2 gt Poll lab 12 life augmented STM32F42xx Technical Training 20 10 2015 12 Simple communication Objective Learn how to setup SPI in CubeMX How to Generate Code CubeMX and use HAL functions Goal Configure SPI in CubeMX and Generate Code
40. STM382F429i Discovery page htto www st com web en catalog tools FM116 SC959 SS1532 LN1848 PF259090 s searcht e keyword e STM32F4289i Discovery user manual with discovery schematics http www st com st web ui static active en resource technical document user manual DM00093903 pdf z e Example list todo 1 GPIO done 6 The 2 EXTI done iuh 3 SLEEP done E 4 STOP done 2 5 STANDBY done 6 2 done 7 DMAIT done 8 RTC done 9 USART done USART IT done Ly 11 USART DMA done life augmented Ly life augmented Example list todo 14 13 14 13 16 17 18 19 20 21 22 SPI Poll done SPI IT done SPI DMA done TIM IT done TIM PWM out done TIM DMA done TIM Counter done DAC wave generation ADC poll done ADC IT done ADC DMA done a e mee nis ES rie os EE done T AT a Example list todo 22 23 24 25 26 27 28 Ly life augmented WDG WWDG done IWDG done FMC SDRAM BSP done LCD BSP Print text done 2 flash with BSP done SPI GYRO BSP done Graphical workshop in Cube Work on Example object description oe ar 5 2 e MB10758 WWNW st com stm32fa discovery 7 0 1 3 1 DISCO TS nax 4 1 ER
41. and its Slaves Trigger Event Selection Reset UG bit from TIMx EGR Ly life augmented 15 Use with interrupt e CubeMX TIM configuration 00000 7 Tab gt NVIC Settings p Enable TIM1 Update interrupt Button OK pre life augmented 15 Use with interrupt e Now we set the project details for generation Menu gt Project gt Project Settings Projectsettings 2 x e Set the project name Project location Type of toolchain Now we can Generate Code Menu Project Generate Code z 5 2 4392 Firmware Package and Version STM32Cube FW F4 V1 3 0 Ly life augmented 15 Use with interrupt HAL Library TIM with IT flow TIM Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL TIM Base Start IT HAL OK HAL ERROR HAL BUSY HAL TIM IRQHandler TIM1 UP TIM10 IRQHandler process callback PeriodElapseadCallback process Error callback HAL TIM ErrorCallback Ly life augmented 15 Use with interrupt Open the project in our IDE The functions we want put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For TIM start use function e HAL Base Start IT TIM HandleTypeD
42. configured in GUI e Read data from GYROSCOPE and display it on LCD Goal Successfully import BSP GYROSCOPE drivers into your project Learn which part you need to import How to setup the project z e 28 Use BSP to access GYROSCOPE BSP GYRO organization BSPpackage sss 7 Discovery drivers stm32f4xx discovery io c stm32f4xx discovery gyroscope c stm32f4xx discovery c Components Utilities 1119341 c lis3dsh c stmpe811 c Fonts HAL API stm32 4xx_hal_ spi stm32f4xx hal Itdc c stm32f4xx hal c stm32f4xx hal i2c c 28 Use BSP to access GYROSCOPE BSP GYRO organization 1 Use functions from Ourprojeci stm32f4xx_discovery_eeprom c BSP package Discovery drivers stm32f4xx_discovery_lcd c stm32f4xx_discovery_sdram c stm32f4xx discovery io c stm32f4xx discovery gyroscope c stm32f4xx discovery c Utilities ili9341 c lis3dsh c stmpe811 c Fonts HAL API TEET stm32f4xx_hal_ltdc c stm32f4xx_hal c stm32f4xx_ll_fmc c stm32f4xx_hal_i2c c 28 Use BSP to access GYROSCOPE 2 stm32f4xx discovery gyroscope c call functions from stm32f4xx discovery io c stm32f4xx_discovery_Icd c stm32f4xx discovery sdram c stm32f4xx_discovery c 3 stm32f4xx_discovery_io c call functions from stm32f4xx_discovery c pin init and read functions Components 1119341 c lis3dsh c HAL API stma2ran hal spl SIm32txx II fmc
43. error HAL_UART_ErrorCallback 4 3 UART1 Tx data or manage ist t 5 Buffer sent 9 register emp error life augmented 10 Use UART with interrupt Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For transmit use function e HAL UART Transmit IT UART HandleTypeDef huart uint8 1 pData uint16 t Size For receive use function e HAL UART Receive IT UART HandleTypeDef huart uint8 t pData uint16 t Size Ly life augmented 10 Use UART with interrupt Buffer definition USER CODE BEGIN 0 uint8 t tx_buff 0 1 2 3 4 5 6 7 8 9 uint8 t rx buff 10 USER CODE END 0 Sending and receiving methods USER CODE BEGIN 2 HAL UART Receive IT amp huarti rx buff 10 HAL UART Transmit IT amp huarti1 tx buff 10 USER CODE END 2 T 2 gt 10 Use UART with interrupt Complete callback check We can put brakepoints on NOPs to watch if we send or receive complete buffer USER CODE BEGIN 4 void HAL UART RxCpltCallback UART HandleTypeDef huart __NOP test if we reach this position void HAL UART TxCpltCallback UART HandleTypeDef huart __NOP test if we reach this position USER CODE END 4 7 T 2 gt 10 Use UART with interrupt interrupt will not work correctly USER 6005 BEGIN 4 void HAL UART RxCpltCallback UART
44. function process Error callback DMA XferErrorCallback life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start end of process callback DMA_XferCpltCallback Error was detected Error callback function process Error callback DMA XferErrorCallback adi HAL OK HAL ERROR HAL BUSY Ly life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow 1 DMA init DMA Initializations including peripheral interrupt NVIC initializations 2 DMA transfer start HAL IRQHandler 4 HAL DMA 5 DMA transfer management was correct process Error callback 5 Error in DMA XferErrorCallback transfer Start process with interrupt generation at end of process HAL DMA Start IT HAL OK HAL ERROR HAL BUSY DMA2 StreamO IRQHandler 3 DMA transfer complete or error end of process callback DMA XferCpltCallback Ly life augmented 7 Use DMA 2 transfer with interrupt Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags DMA callback function We need to add the name of callback function into DMA structure HAL functions f
45. h stm32f4xx hal spi c stm32faxx_hal_i2c c_ stm32f4xx_ll_fmc c stm32f4xx_hal_sdram c stm32f4xx hal c 25 BSP for SDRAM initialization BSP SDRAM organization R 5 3 include stm32f4xx_halh OU Discovery drivers stm32f4xx_discovery c stm32f4xx_discovery_sdram c f stm32f4xx_discovery_io c Components 4 stm32t4xx_hal h include all peripherals which are used in ili9341 c 1 0 stm32f4xx discovery c E stm32f4xx_hal_spi c stm32f4xx_ll_fmc c stm32f4xx_hal_sdram c stm32f4xx_hal c 25 Use BSP for SDRAM initialization BSP SDRAM organization Discovery drivers stm32f4xx_discovery c stm32f4xx_discovery_sdram c f stm32f4xx_discovery_io c d Components D stm32f4xx_hal h include all peripherals which are used in ili9341 c lis3dsh c stmpe811 c stm32f4xx_discovery_sdram c stm32f4xx_hal_spi c stm32f4xx_hal_i2c c stm32f4xx Il fmc c stm32f4xx_hal_sdram c stm32f4xx_hal c 25 Use BSP for SDRAM initialization BSP SDRAM organization Our project 6 HAL SDRAM Init is function from 7 HAL SDRAM Init c i 4 discovery scram c call functions from sim32f4xx 11 fmc c stm32f4xx discovery stm32f4xx discovery sdram c stm32f4xx discovery io c 8 stm32f4xx fmc c use functions from stm32f4xx hal sdram c HAL API
46. need to import How to setup the project z e 26 Use BSP for LCD init and writing BSP LCD organization ane BSP package Discovery drivers Utilities stm32f4xx_discovery c stm32f4xx discovery lcd c stm32f4xx_discovery_sdram c Components 1119341 c lis3dsh c stmpe811 c Fonts HAL API stm32 4xx_hal_ spi 51713214 stm32f4xx hal c EIE L _stm32f4xx Il _fmc c 26 Use BSP for LCD init and writing BSP LCD organization 1 include Our project stm32f4xx discovery lcd h 0 sae BSP package Discovery drivers stm32f4xx_discovery c 1 stm32f4xx discovery lcd c stm32f4xx_discovery_sdram c Components 2 stm32f4xx discovery lcd h use the discovery BSP and ilig341 c lisSdsh c f stmpe811 c SDRAM HAL API stm32f4xx hal sdram c stm32f4xx hal spi c stm32f4xx_hal_ltdc c stm32f4xx_hal c simactaxx hal q_stm32t4xx_ 11 70 6 26 Use BSP for LCD init and writing BSP LCD organization 3 stm32f4xx discovery lcd h use driver ili9341 c which is TFT LCD controller iscovery drivers stm32f4xx discovery lcd c stm32f4xx discovery sdram c ili9341 c lis3dsh c stmpe811 c 4 stm32f4xx_discovery_Icd h use LCTD control
47. process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Interrupt indicate the data register is empty we can send more data or error was detected Start process with interrupt generation at end of process HAL UART Transmit IT HAL_UART_IRQHandler USART1_IRQHandler N HAL HAL_ERROR HAL_BUSY end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Process interrupt Start process with interrupt generation at end information of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY USART1 IRQHandler end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Send more data if is buffer Start process with interrupt generation at end not emply of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY USART1 IRQHandler end of process callback HAL UART Tx
48. stm32f4xx hal Itdc c stm32f4xx hal c CEA 28 Use BSP to access GYROSCOPE BSP GYRO organization BSPpackage Discovery drivers stm32f4xx_discovery_Icd c tm32f4xx di dram stm32f4xx discovery io c stm32f4xx discovery gyroscope c M 5 stm32f4xx discovery c 4 stm32f4xx_discovery c Utilities m 1 Use stm32f4xx_hal_spi to commutate with gyroscope HAL API hal spi stm32f4xx hal Itdc c stm32f4xx hal c stm382f4xx_hal_i2c c J 28 Use BSP to access GYROSCOPE 169 BSP SDRAM BSP SDRAM Confi amp CI Application We use the project from BSP LCD lab 26 pM DH because we want to display gyro values Te ss stm32f4xx hal msp c on LCD stm32f4xx a BSP Ha 2 1119341 Ha stm32f429i_discovery c stm32f429i_discovery_Icd c stm321429i discovery sdram c amp O Drivers aC1CMSIS system stm32f4xx c La C1STM32F4xx HAL Driver C 5113214 hal c Ha E stm32f4xx hal cortex c E 51013214 hal crc c E 51013214 hal dma c 513214 hal dma2d c stm32f4xx hal ex c Ha E stm32f4xx hal flash c stm32f4xx flash ex c E stm32f4xx hal flash ramfunc c stm32f4xx hal gpio c E stm32f4xx hal i2c c stm32f4xx hal Itdc c 5103214 hal pwr c 5103214 hal pwr ex c 513214 hal rcc c 513214 hal rcc ex c Ha E stm32f4xx h
49. 1 Prescaler 180 5 45 APB1 peripheral clocks MHz 180 MHz max 3 gt 2 90 APBiTimerclocks MHz 2 Prescaler ma 90 2 peripheral clocks MHz Input frequency 2 1 0 2 clocks MHz gt 9 48MHz clocks MHz 125 source Mux 125 clocks MHz 5 source 2 PLLI2S Q o SAI A clocks MHz 2 source Mux pre mp B source Mux 2 44 4 5 SERES l SAI B docks MHz MCO1 source Mux 5 P 7 4 T 1 e 4 MHz 1 D 16 gt 4 2 5 2 M 1225 LCD TFT clocks MHz iJ gt PLLSAI B life augmented 6 Use DMA in M2M transfer DMA configuration TAB gt Configuration System gt DMA TAB gt DMA2 e Button ADD 1 TAB gt Configuration 4 Add DMA channel 6 Use M2M transfer e DMA configuration Select gt Confis DMA request Normal mode e Increment source and destination address FIFO setup Byte data width 3 Increment Burst size addresses Button OK 2 Normal mode 4 FIFO setup Ly life augmented 6 Use M2M transfer e Now we set the project details for generation Menu
50. 2 t Data igmented 19 Use DAC as wave generator Solution DAC setup and start USER CODE BEGIN 2 HAL DAC Start amp hdac DAC CHANNEL 2 USER CODE END 2 Create the wave USER CODE BEGIN 3 Infinite loop while 1 1 DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 128 value dac value if value dac 4095 value_dac HAL Delay 1 USER CODE END 3 Ly life augmented ADC Poll lab 20 life augmented STM32F42xx Technical Training 20 10 2015 20 Use ADC in polling mode Objective Use the DAC part from previous lab Learn how to setup ADC CubeMX How to Generate Code in CubeMX and use HAL functions Goal Configure ADC in poll in CubeMX and Generate Code Learn how to start ADC and measure the DAC Verify the measured wave STMStudio http www st com web en catalog tools PF251373 require JAVA z e 3 20 Use ADC in polling mode Create project in CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX DAC selection e Select DAC OUT2 e Select ADC IN13 2061 3 Ly life augmented Hardware connection Connect DAC out2 PA5 and ADC1 IN13 PC3 together F life augmented 20 Use ADC in polling mode e CubeMX ADC configuration TAB gt Configuration gt Analog
51. 3 Use SPI with interrupt n order to run on maximum frequency setup clock system Details in lab 0 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AP81 Prescaler 4 4 2 uc 45 peripheral clocks MHz AHB Prescaler HCLK MHz 43 180 x2 30 APB1 Timer clocks MHz 2 Prescaler 42 90 2 peripheral clocks MHz X2 150 APB2timer clocks MHz gt 90 48MHz clocks MHz 125 clocks MHz PLLI2S 1225 clocks MHz SAI B clocks MHz 4 IQ 2 wa a 1235 LCD TFT clocks MHz PLLSAI Ly life augmented 13 Use SPI with interrupt CubeMX SPI configuration e Tab gt Configuration gt Connectivity gt SPI1 settings File Project Window Help RSU 68 Button Cramton Coast Connectivity 8 0 MBits s Low 1Edge Disabled y Bici mentod 5 32 429 439 Lore 144 None 13 SPI configuration gt Settings Enable SPI interrupt Button OK life augmented Use with interrupt 13 Use SPI with interrupt e Now we set the project details for generation
52. 3 require JAVA z e 3 29 Use ADC with DMA um Create project in CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX DAC selection e Select DAC OUT2 e Select ADC IN13 ADC1 IN13 Ly life augmented 29 Use ADC with DMA CubeMX ADC configuration TAB gt Configuration gt Analog gt ADC1 gt Parameter Settings Set ADC1 2 ADCI Configuration Parameters Settings Settings DMA Settings GPIO Settings Set sampling time for CH13 DMA Continuous requests Independent mode Button OK PCLK2 divided by 2 12 bits 15 ADC Clock cydes DAC from previous Right alignment i Disabled example Ly life augmented 29 Use ADC with DMA CubeMX ADC configuration TAB gt DMA Settings ADCI Configuration Button ADD DMA request ADC1 Peripheral to memory direction Circular mode Memory increment Half word data width e Button OK Half Word Singe life augmented 29 Use ADC with DMA e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code Menu gt Project gt Generate Code IDE EWARM 6 70 Mcu and Firmware Package M
53. 32 11 stm32f4xx_hal_sdram c stm32f4xx hal c 25 Use BSP for SDRAM initialization Source files Include files User Code BSP Drivers Stm32f4xx discovery c Stm32f4xx discovery h Stm32ffxx discovery sdram c Stm32ffxx discovery sdram h HAL Drivers life augmente 25 Use BSP for SDRAM initialization copy part e n our project in Drivers folder create folder BSP 41 1 Drivers Projects O Src 3 ject BSP_SDRAM ioc e Now go into CubeMX repository STM32Cube_FW_F4_V1 3 0 Drivers BSP e And copy Components and STM32F429l Discovery into BSP folder 5 324 91 EVAL 7 ICMSIS STM324xG EVAL STM32F4xx_HAL_Driver 3ISTM32F401 Discovery IS TM32F423I Discovery S TM32F4 Discovery STM32F4xx Nucleo Ly ife augmented 25 Use BSP for SDRAM initialization Now we need to this files also in project 2 Create BSP folder in project 1 Right click on project Workplace gt ADD gt Group yam relation Name BSP startup stm32f439xx s Now right click BSP gt ADD gt Files n s From Drivers BSP STM32F429I Discovery add stm32f429i_discovery c and stm32f429i_discovery_sdram c La SC STM32F4xx_HAL_Driver E stm32f4xx hal c stm32f4xx cortex c E stm32f4xx_hal_dma c E stm32f4x_ha
54. 32Cube Repository You need to download STM32 packages into this folder Or CubeMX automatically download them into this folder Firmware Repository Repository Folder wea STM32CubeRepository life augmented Firmware Repository Repository Folder C Users mum pm STM32Cube Repositor y In case you want to download this files automatically use in CubeMX e MENU gt Help gt Install New Libraries Select libraries which you want Force download with button Install Now File Project Window Help REU Hep Fl About Alt A D CheckforUpdates E Install New Libraries Alt U 9 Updater Settings Alt S Ly life augmented CubeMX install The comparison of the CubeMX repository settings and structure in this folder 718 DISTM32Cube_FW_FO_V0 2 0 3ISTM32Cube FW FO V1 0 0 C3ISTM32Cube FW FO 1 1 0 C3ISTM32Cube FW F2 V1 0 0 C3ISTM32Cube FW F2 1 1 0 C3ISTM32Cube FW VO0 4 0 C3ISTM32Cube FW VO0 5 0 C3ISTM32Cube FW V1 0 0 C3ISTM32Cube FW V1 1 0 C3ISTM32Cube FW VO0 8 0 C3ISTM32Cube FW F4 V1 0 0 C3ISTM32Cube FW V1 1 0 C3ISTM32Cube FW V1 2 0 3ISTM32Cube FW V1 3 0 C3ISTM32Cube FW 10 VO0 5 0 C3ISTM32Cube FW LO V1 0 0 C3ISTM32Cube FW LO V1 1 0 C3ISTM32Cube FW L1 V1 0 0 C3ISTM32Cube FW L4 VO0 0 2 install For the code generation the Cub
55. 4xx_hal c stm32f4xx hal cortex c 5 32 hal dma c stm32f4xx hal dma ex c E stm32f4xx hal flash c stm32f4xx hal flash ex c E stm32f4xx hal flash ra E stm32f4xx hal gpio c stm32f4xx hal pwr c stm32f4xx hal pwr ex c E stm32f4xx hal rcc c E stm32f4xx hal rcc ex c 1 7 Output YI life augmented SP package D Discovery drivers 3 stm32f4xx_discovery c stm32f4xx_discovery_sdram c stm32f4xx_discovery_io c ET D ili9341 c lis3dsh c stmpe811 c Components stm32f4xx_hal_spi c stm32f4xx_hal_i2c c stm32f4xx Il fmc c stm32f4xx hal sdram c stm32f4xx hal c 25 Use BSP for SDRAM initialization BSP SDRAM organization BSP package Discovery drivers stm32f4xx_discovery c stm32f4xx discovery sdram c stm32f4xx_discovery_io c Components 6 lis8dsh c stmpe811 c HAL API 51113214 2 51713214 51713214 hal sdram c stm32f4xx hal c 25 Use BSP for SDRAM initialization BSP SDRAM organization aee Our project stm32f4xx discovery sdram h BSP package Discovery drivers stm32f4xx_discovery c stm32f4xx_discovery_sdram c stm32f4xx discovery io c 6 lis8dsh c stmpe811 c HAL API 2 include stm32f4xx discovery
56. 5 30 APB2 peripheral clocks MHz x 2 3 180 2 timer clocks MHz gt 9 48MHz clocks MHz 125 source Mux 125 clocks MHz 14 5 IR SAI1 A source 42 PLLI2S SAI A clocks MHz MCO2 source Mux pre B source Mux 4 e SAI B docks MHz MCO1 source Mux H 4 e 6 1 2 2 5 2 5 1225 LCD TFT clocks MHz PLLSAI R 24 CubeMX ADC configuration TAB gt Configuration gt System gt gt IWDG gt Parameter Settings Set prescaller to 4 Max value to 50 Button OK life augmented Use IWDG E IWDG counter clock Min Max values of IWDG down co 50 24 Use IWDG e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code T AT E Menu gt Project gt Generate Code Toolchain IDE Ewann 6 70 Mcu and Firmware Package Mcu Reference 51 32 439211 Firmware Package Name and Version STM32Cube FW F4 V1 3 0 V Use latest available version L life augmented 24 Use IWDG IWDG refresh interval 1 fs IWDG _ PRESCALLER N IWDG_COUNTERVAL AA 4 50 6 2515 z e 42 3 24 Use IWDG Solution I
57. AL_RTC_AlarmAEventCallback RTC_HandleTypeDef hrtc RTC_AlarmTypeDef sAlarm HAL_RTC_GetAlarm hrtc amp sAlarm RTC_ALARM_A FORMAT_BIN if sAlarm AlarmTime Seconds 58 sAlarm AlarmTime Seconds 0 1 sAlarm AlarmTime Seconds sAlarm AlarmTime Seconds 1 while HAL SetAlarm IT hrtc amp sAlarm FORMAT _BIN HAL_OK HAL GPIO TogglePin GPIOG GPIO PIN 14 USER CODE END 4 life augmented 8 Use RTC and Alarm with interrupt Advanced task The counting stops after 1minute e Modify the project to create alarm every 1s for infinite time Enable the Alarm A Tf sAlarm AlarmTime Hours 0 sAlarm AlarmTime Minutes 0 sAlarm AlarmTime Seconds 1 sAlarm AlarmTime SubSeconds 0 sAlarm AlarmTime TimeFormat RTC HOURFORMAT12 AM sAlarm AlarmTime DayLightSaving RTC DAYLIGHTSAVING NONE sAlarm AlarmTime StoreOperation RTC STOREOPERATION RESET sAlarm AlarmMask RTC ALARMMASK DATEWEEKDAY RTC ALARMMASK HOURS RTC ALARMMASK MINUTES sAlarm AlarmSubSecondMask RTC ALARMSUBSECONDMASK ALL sAlarm AlarmDateWeekDaySel RTC ALARMDATEWEEKDAYSEL DATE sAlarm AlarmDateWeekDay 1 sAlarm Alarm RTC ALARM A HAL RTC SetAlarm IT amp hrtc amp sAlarm FORMAT BCD e We only need to modify the Alarm mask to ignore Days Hours and Minutes Ly life augmented UART Poll lab 9 life augmented STM32F42xx Technical Training 20 10 2015 9 Simple UART communication Objective Learn
58. B gt DMA Settings USARTI Configuration Button ADD ef Parameter Settings Settings DMA 5610005 7 cero Settings DMA Request Settings Mode Normal Increment Address Use Fifo Threshold One Quarter Full Data Width Burst Size life augmented 11 Use UART with DMA transfer CubeMX USART configuration DMA Tx settings Set USART1_TX request USARTE Configuration 000000000000 Memory to peripheral direction Normal mode Byte data width Increment memory address DMA Request Settings Mode Normal UseFifo F Threshold Half Full life augmented 11 Use UART with DMA transfer CubeMX USART configuration DMA Rx settings Button ADD 12 Set USART1_RX request Peripheral to memory direction e Normal mode Byte data width Increment memory address Threshold Half Full Burst Size Single Single 2571 11 Use UART with DMA transfer CubeMX USART configuration NVIC settings e TAB gt NVIC Settings USARTI Configuration Enable interrupts for 7 Parameter Setings 7 NVIC Setinos DMA Settings GPIO Settings USART1 e Button OK life augmented 11 Use UART with DMA transfer e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project locatio
59. Delay 4 HAL_GPIO WritePin GPIOG GPIO 14 GPIO PIN SET HAL WWDG Refresh amp hwwdg 127 USER CODE END 3 life augmented IWDG lab 24 life augmented STM32F42xx Technical Training 20 10 2015 24 Use IWDG Objective Learn how to setup WWDG CubeMX How to Generate Code CubeMX and use HAL functions Create simple application to test WWDG Goal Configure WDGin CubeMX and Generate Code Learn how to start WWDG WWDG indication via LED Ly life augmented 24 Use IWDG Create project CubeMX Menu gt File gt New Project e Select STM32F4 gt STM32F 429 439 gt LQFP144 gt STM32F439ZITx gt WWDG selection Select WWDG Configure PG14 for LED indication Activated Ly life augmented 24 Use IWDG In order to run on maximum frequency setup clock system Details in lab O Ly life augmented Input frequency RTC Clock Mux 3 IWDG KHz x To RTC KHz 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz System Clock Mux 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz E SYSCLK MHz AHBPrescaler HCLK MHz APB1 Prescaler 180 0 4 45 peripheral clocks MHz 180 max E PLLCLK X2 90 clocks MHz 2 Prescaler Enable CSS 2
60. File Project Window Help 5 84 t t Prout Glock Configuration 7 Power Consumpton MiddleWares 9 FATFS E User defined FREERTOS E Enabled 5 8 9 CRC E Activated 5 DMA2D L E Activated Middlewares C IWDG Activated 2 RCC High Speed Clock HSE C 2 9 RNG Multimedia Analog One Pulse Mode G 7 Activated Pulse Mode WWDG 2 Configure EXT which turns LED GPIO Pin Configuration e Select External Interrupt Mode with Rising edge trigger detection No pull up or pull down e PG14 can be let in default settings Search Signals Search Crt F Button OK External Interrupt Mode with Rising edge trigger detection life augmented Group By IP 2 Configure EXT which turns LED e NVIC Configuration We need to enable interrupts for EXTI TAB gt Configuration gt System gt NVIC File Project Windows Help gt 68 Pinout Clock Configuration Configuration power Consumption calculator onfiguration MiddleWares ER 9 FATES L E User defined G FREERTOS Peripherals 5 9 Activated 5 6 DMA2D Activated Middlewares C IWDG i E Activated 9 RCC High Speed Clock HSE C 5 RNG Analog L F Activated 6 H E Activated
61. GIN uint8 t Buffer Src 0 1 2 3 4 5 6 7 8 9 uint8 t Buffer Dest 10 USER CODE END 0 T 2 gt 6 Use DMA M2M transfer HAL DMA Start start the M2M data transfer e PollForTransfer check if the transfer ends successfully USER CODE BEGIN 2 HAL Start amp hdma memtomem dma2 streamO uint32 t Buffer Src uint32 t Buffer Dest 10 while HAL DMA PollForTransfer amp hdma memtomem dma2 stream HAL FULL TRANSFER 100 HAL OK __NOP USER CODE END 2 life augmented Data transfer over DMA with interrupt lab 7 life a 7 Use M2M transfer with interrupt Objective Learn how to setup DMA transfer with interrupt in CubeMX Create simple DMA memory to memory transfer from RAM to RAM e Goal e Use CubeMX and Generate Code with DMA Learn how to setup the DMA in HAL Verify the correct functionality by comparing transferred buffers z e 3 7 Use DMA 2 transfer with interrupt Create project in CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt 144 gt STM32F439ZITx For DMA we don t need to configure any pins 8 9 STM32F439ZITx life augmented 7 Use 2 transfer with interrupt n order to run on maximum frequency setup clock system Details in lab 0
62. Generate Code D Radek _Training_examples 4_prague_2014 modif myWabs ADCIT Menu gt Project gt Generate Code Toolchain IDE usm Mcu and Firmware Package Mcu Reference STM32F439ZITx_ Firmware Package Name and Version sTM32Cube FW_F4V1 3 0 Use latest available version life augmented 21 Use ADC with interrupt HAL Library ADC with IT flow ADClnitializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL ADC Start IT HAL OK HAL ERROR HAL BUSY HAL ADC IRQHandler ADC IRQHandler process callback ADC ConvOpltCallback process Error callback HAL ADC ErrorCallback Ly life augmented 21 Use ADC with interrupt Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags and USER CODE BEGIN 4 USER CODE END 4 tags For DAC start use function e HAL ADC Start IT ADC HandleTypeDef hadc uint32 t Channel HAL ADC GetValue ADC HandleTypeDef hadc ADC complete callback function e HAL ConvOpltCallback ADC HandleTypeDef hadc e DAC functions e HAL DAC Start DAC HandleTypeDef hdac uint32 t Channel e HAL DAC SetValue DAC HandleTypeDef hdac uint32 t Channel uint32 t Alignment uint32 t Data Ly ife augmented 21 Use ADC with interrupt Solution Variab
63. HandleTypeDef huart __NOP test if we reach this position void HAL UART TxCpltCallback UART HandleTypeDef huart __NOP test if we reach this position USER CODE END 4 T 2 gt Technical Training 20 10 2015 11 Use UART with DMA transfer Objective Learn how to setup UART with DMA in CubeMX How to Generate Code in CubeMX and use HAL functions Create simple loopback example with DMA Goal z e 3 e Configure UART CubeMX and Generate Code Learn how to send and receive data over UART with DMA Verify the correct functionality 11 Use UART with DMA transfer Create project CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx Pin selection t will be same as previous lab we use again PA9 and 10 8 4 E 23 2 USART1_RX USART1_TX Flow Control 85232 Disable 9 USART2 v UART Hardware preparation e We connect selected pins together by jumper this help us to create loopback UART life augmented 11 Use UART with DMA transfer n order to run on maximum frequency setup clock system Details in lab 0 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AP81 Prescaler E 4 2
64. ITx Firmware Package Name and Version STM32Cube FW F4 V1 3 0 Ly life augmented 8 Use RTC and Alarm with interrupt e RTC can be preserved during RESET ok LP modes CubeMX not enable the RTC by default e We need to HAL PWR EnableBkUpAccess HAL ENABLE before we call MX RTC Init Set the first alarm to 18 MX Init e We create the RTC interrupt handler and we reconfigure the Alarm A time e HAL AlarmAEventCallback RTC HandleTypeDef hrtc e HAL GetAlarm RTC HandleTypeDef hrtc AlarmTypeDef sAlarm uint32 t Alarm uint32 t Format HAL RTC SetAlarm IT RTC HandleTypeDef hrtc AlarmTypeDef sAlarm uint32 t Format RTC alarm indication will be done by LED e TogglePin GPIO TypeDef GPIOx uint8 t GPIO Pin Ly life augmented 8 Use RTC and Alarm with interrupt RTC enable Initialize all configured peripherals HAL_PWR_EnableBkUpAccess enable PWR backup domain access RTC BKReg HAL RCC RTC ENABLE Enable RTC not created by cube because the RTC can run MX GPIO Init MX RTC Init e In MX Init we set first Alarm to 1s Enable the Alarm A sAlarm AlarmTime Hours 0 sAlarm AlarmTime Minutes 0 sAlarm AlarmTime Seconds 1 sAlarm AlarmTime SubSeconds 0 life augmented 8 Use RTC and Alarm with interrupt RTC enable USER CODE BEGIN 4 void H
65. MA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start HAL ERROR HAL BUSY HAL DMA IRQHandler DMA2 0 IRQHandler end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Ly life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow Initializations including peripheral interrupt NVIC initializations Generated by CubeMX Start process with interrupt generation at end of process Start HAL HAL_ERROR HAL_BUSY pa HAL _DMA_IRQHandler DMA2_Stream0_IRQHandler lt end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Ly life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations rt process with interrupt generation at end 7 98 of process Start HAL_ERROR HAL_BUSY end of process callback DMA XferCpltCallback process Error callback Defined by user DMA XferErrorCallback p life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral inte
66. NDBY again Try to clear wake up flag e PWR CLEAR FLAG PWR FLAG WU USER CODE BEGIN 2 HAL CLEAR FLAG PWR FLAG WU USER CODE END 2 K 6 Use DMA M2M transfer Objective Learn how to setup DMA transfer in CubeMX Create simple DMA memory to memory transfer from RAM to RAM e Goal e Use CubeMX and Generate Code with DMA Learn how to setup the DMA in HAL Verify the correct functionality by comparing transferred buffers z e 3 FIFO DMA FIFO DMA FIFO 8 Streams FIFO 8 Streams 6 e e 9 6 D Code Multi AHB Bus Matrix ART Accelerator ig 6 Use M2M transfer Create project in CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt 144 gt STM32F439ZITx For DMA we don t need to configure any pins 9 STM32F439ZITx life augmented Use DMA in M2M transfer n order to run on maximum frequency setup clock system Details in lab 0 RTC Clock Mux Hen LSE 2 To RTC KHz LSIRC 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AHBPrescaler HCLK MHz APB
67. ODE BEGIN 4 void HAL TIM PeriodElapsedCallback TIM HandleTypeDef htim GPIO TogglePin GPIOG GPIO 14 USER CODE END 4 life augmented DAC wave generator lab 19 19 Use DAC as wave generator Objective Learn how to setup DAC as wave generator in CubeMX How to Generate Code in CubeMX and use HAL functions Goal Configure DAC as wave generator in CubeMX and Generate Code Learn how start it in project Q z e 3 19 Use DAC wave generator Create project CubeMX Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX DAC selection Select DAC OUT2 I e 15 19 Use DAC wave generator CubeMX DAC configuration TAB gt Configuration gt Analog gt DAC gt Parametr Settings bl File Project Window Help Enable 5 698 tp Output buffer Pinout Clock Configuration Configuration Power Consumption Calculator tion e Button a DAC Configuration ERO FATES User defined as 6 7 NVIC Settings 6 7 DMA Settings GPIO Settings D 9 FREERTOS Configure the below parameters o L F Enabled Peripherals B B Ej DAC Out Settings 7 Activated Enable Output Buffer 9 DAC Middlewares QUT2 9 DMA2D T Activated 2 9 IWDG RCC High Speed E Activated TIM6
68. OPENTRY WFI SystemClock Config USER CODE END 3 life augmented 4 Use STOP mode with Or different function USER CODE BEGIN 3 Infinite loop while 1 HAL Delay 1000 HAL PWREx EnterUnderDriveSTOPMode PWR LOWPOWERREGULATOR UNDERDRIVE ON PWR STOPENTRY SystemClock Config USER CODE END 3 life augmented 5 Use STANDBY mode Objective For this lab create empty CubeMX project Learn how to setup STANDBY HAL Create simple project with STANDBY mode with wake up on pin press e Goal Learn how to setup the STANDBY HAL which events can wake up you Verify the correct functionality by measuring consumption Ly life augmented STANDBY Mode Core and all peripherals eue Core are OFF except RTC and RTC backup reg IWDG if enabled HSE MSI HSI clocks 9 9 OFF LSI LSE be SRAM and registers content is lost except SPI RTC and standby circuitry LOE GPIO s are in high Z DAC except Reset RTC OUT mM and WKUP 1 2 3 Power 5 Use STANDBY mode HAL Library work flow summary 1 init NVIC Peripheral Initializations including peripheral interrupt NVIC a initializations Enable Wake up pin 3 Use WFI 5 Wake up 4 create edge Enter into STANDBY mode WFI STM with reset Ly life augmented 9 Use STANDBY mode
69. OpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY HAL_UART_IRQHandler USART1_IRQHandler end of process callback HAL_UART_TxCpltCallback If 5 ompiete function process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY UART TxOpltCallback use Error callback function process Error callback HAL_UART_ErrorCallback adi Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations 1 UART1 init including peripheral interrupt NVIC initializations 2 UART1 send Start process with interrupt generation at end buffer of process HAL UART Transmit IT HAL_UART_IRQHandler USART1_IRQHandler HAL_OK HAL_ERROR HAL_BUSY end of process callback HAL_UART_TxCpltCallback process Error callback 5 Transmit
70. PWM Start TIM HandleTypeDef htim uint32 t Channel e GPIO LED toggle We wire the Channel1 PE9 with LED PG14 igmented 16 Use with PWM output gt Solution TIM PWM start USER CODE BEGIN 2 HAL PWM Start amp htim1 TIM CHANNEL 1 USER CODE END 2 e TIM1 Channel 1 and LED connection Q z e Technical Training 20 10 2015 17 Use with DMA transfer Objective Learn how to setup TIM with DMA in CubeMX How to Generate Code in CubeMX and use HAL functions Indicate TIM DMA transfer with LED toggle Goal Configure TIM in CubeMX and Generate Code Learn how start timer and setup DMA Verify the correct functionality with DMA transfer into GPIO register z e 17 Use with DMA transfer Create project CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx gt CubeMX TIM selection 8 0 TIMI Select TIM clock source Internal clock Enable GPIO for LED 4 e Use ETR as Clearing Source C XOR activation life augmented 17 Use with DMA transfer CubeMX TIM configuration e Tab gt Configuration gt Control gt TIM1 Check the settings File Project Window Help 79 Pinout Clock Configuration Configuration onfiguration 9 Middlewares C 9 FATES L E User defined C F
71. REERTOS E Enabled Peripherals Q 9 CRC T Activated 2 9 DMA2D i E Activated amp IWDG Activated G RCC High Speed Clock HSE lt RNG 0 7 Activated Clock Source Internal 5 6 TIM6 7 Activated C One Pulse Mode 9 lt 7 i E Activated 1 C One Pulse Mode life augmented Middlewares Analog System 5 9 WWDG 17 Use with DMA transfer TIM configuration e Tab Parameter Settings Prescaler to 18000 Counter period to 10000 Together with 180MHz TIMER1 clock we get period 1Hz Repetition Counter RCR 8 bits value Trigger Output TRGO Parameters Master Slave Mode Disable no sync between this TIM Master and its Slaves Trigger Event Selection Reset UG bit from TIMx EGR Ly life augmented 17 Use with DMA transfer TIM configuration TAB gt DMA Settings e Button ADD e Select UP DMA request Memory to peripheral direction Set Memory increment Circular mode Half word data width Button OK i Increment Address Threshold Half Full v Data Width Half Word Half Word Burst Size si ingle singe life augmented 17 Use TIM with DMA transfer e Now we set the project details for generation Menu gt Project gt Project Settings Set the pr
72. UART with interrupt n order to run on maximum frequency setup clock system Details in lab 0 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AHB Prescaler HCLK MHz 43 180 1 Prescaler 4 4 2 uc 45 peripheral clocks MHz x2 gt 90 APB1 Timer clocks MHz APB2 Prescaler 42 Bii 30 2 peripheral clocks MHz X2 150 APB2timer clocks MHz gt 90 48MHz clocks MHz 125 clocks MHz PLLI2S 1225 clocks MHz SAI B clocks MHz LCD TFT clocks MHz Ly PLLSAI life augmented 2 10 Use UART with interrupt CubeMX UART configuration e Tab gt Configuration gt Connectivity gt USART 1 STM32CubeMX Untitled STM32F429ZITx File Project Window Help Gi ap Middlewares E Activated Connectivity System RNG M USATI WE TIM6 LN t7 E Activated USART Universal Synchronous Asynchronous Receiver Transmitter 7 One Pulse Mode configured You can generate code using the current values ue Nm gt F Activated i One Pulse Mode 6 10 Use UART with interrupt CubeMX UART configuration check e BaudRate World length Parity Stop bits Data direction 8 Bits induding Parity Oversam
73. UART_Init amp huart1 4 write to UART1 registers UART Msplnit callback 5 UART1 init callback CubeMX configure here UART1 GPIOs and enable UART1 clock system and NVIC Ly life augmented 9 Simple UART communication HAL Library init flow 2 Call init MX USART1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure HAL_UART_Init amp huart1 4 write to UART1 registers HAL UART callback 5 init callback Init GPIO and NVIC for UART 6 UART1 GPIOS NVIC and RCC init Ly life augmented 9 Simple UART communication HAL Library init flow 2 Call init MX USART1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure HAL_UART_Init amp huart1 4 write to UART1 registers HAL UART callback 5 init callback Init GPIO and NVIC for UART 6 UART1 GPIOS NVIC and RCC init 7 Next periph init or user code Ly life augmented Q Simple UART communication HAL Library transmit flow m Peripheral Initializations in Polling process UART Transmit Generated by CubeMX Function blocks Polling with timeout HAL TIMEOUT HAL OK HAL ERROR HAL BUSY z e 42 Q Simple UART communication HAL Library transmit flow Created by user Function block
74. WDG Start USER CODE BEGIN 2 HAL IWDG Start amp hiwdg USER CODE END 2 IWDGrefresh USER CODE BEGIN 3 Infinite loop while 1 Delay 7 try delay 6ms and 7ms HAL GPIO WritePin GPIOG GPIO 14 GPIO PIN SET HAL IWDG Refresh amp hiwdg USER CODE END 3 life augmented 24 Hardware IWDG Remove IWDG start from project USER CODE BEGIN 2 USER CODE END 2 Use ST Link utility and enable IWDG Hardware start life augmented Use IWDG 24 Use IWDG Hardware IWDG Read Out Protection BOR Level Start ST Link utility Level 0 OFF Menu gt Target gt Option bytes iguiation or CTRL B V mRST STDBY V nRST_STOP e Uncheck the WS e Button APPLY Now the IWDG is automatically started after reset User data storage option bytes Data 0 HJ Data 1 H IT DO NOT FORGET disable Fish IWDG automatic start after you end this example 7 Sector 2 No Protection Sector 3 No Protection Sector 4 No Protection Sector 5 No Protection E Sector No Protection Sector 7 No Protection Sector 8 No Protection F Sector 9 No Protection 7 life augmented BSP SDRAM lab 25 25 Use BSP for SDRAM initialization Objective Learn how import BSP into project Which part need to by configured in GUI e Try to write d
75. X assign pins 2 USB FS DP USB FS DM 4 12 a 84 APB2 peripheral clocks mn ru Ye 4 USB clock can be set now PEN N X2 W 165 APB2 timer clocks 7 M 48 48MHz docks MHz t Main PLL Q 1 Configure GPIO for LED toggling e GPIO Configuration e TAB gt Configuration gt System gt GPIO File Project Window Help 5 64 9 Prout Cock Configuration Con guraton Power Consumption MiddleWares 20 09 FATES User defined FREERTOS i E Enabled 5 2 CRC Activated 5 DMA2D Activated Middlewares IWDG E Activated oe RCC High Speed Clock HSE C 2 9 RNG Multimedia Analog One Pulse Mode Activated L Pulse Mode WWDG L E Activated 1 Configure GPIO for LED toggling GPIO Pin Configuration Select Push Pull mode No pull up and pull down y Output speed to HIGH Is important for faster Search Signals peripheries like USART search Show only Modified Pins e Button OK Ly life augmented Group By IP 1 Configure GPIO for LED toggling GPIO Pin output speed configuration Change the rising and falling edge when pin change state from high to low or low to high e Higher GPIO speed increase EMI noise from STM32 and
76. al sdram c y stm32f4xx hal spi c iiie augmented 5103214 fmc c m 1 28 Use BSP to access GYROSCOPE e We add the driver for BSP LDC e Right click on BSP gt ADD from Drivers BSP STM32F429I Discovery e stm321429i discovery gyroscope c e stm321429i discovery io c Right click on BSP gt ADD from Drivers BSP Components 13gd20 c 4 513214291 discovery gyroscope c a _discovery_ 28 Use BSP to access GYROSCOPE e Into main c now modify include USER CODE BEGIN Includes include stm32f429i discovery lcd h include stm32f429i discovery gyroscope h include stm32f429i discovery io h include lt stdio h gt USER CODE END Includes Define variables USER CODE BEGIN PV float valxyz 3 gyroscope values uint8 t buffer 200 text buffer USER CODE END PV life augmented 28 Use BSP to access GYROSCOPE Into main c add USER CODE BEGIN 2 I LCD init BSP LCD Init BSP LCD LayerDefaultInit 1 SDRAM DEVICE ADDR BSP LCD SelectLayer 1 BSP LCD DisplayOn BSP LCD Clear LCD COLOR BLUE BSP LCD SetBackColor LCD COLOR BLUE BSP LCD SetTextColor LCD COLOR WHITE Gyroscope init BSP GYRO Init USER CODE END 2 Ly life augmented 28 Use BSP to access GYROSCOPE Into main c add USER CODE BEGIN 3 Infinite loop while 1 Get Gyrospope value 2 4 wwyrst com stm32i Cem 5
77. alue adc 1 USER CODE END 2 Ly life augmented 29 Use ADC with DMA Solution ADC main routine USER CODE BEGIN 3 Infinite loop while 1 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 128 R value dac value 4 if value dac 4095 value dac 0 HAL Delay 5 HAL ADC Start amp hadc1 HAL Delay 5 USER CODE END 3 life augmented 29 Use ADC with DMA STM studio settings Check functionality fm stm smo New conta File Run Views Options Help again with Du ug mnn 1 STMstudio VarViewer1 Display Variables Write Variables Display Variables settings life augmented WWDG lab 23 life augmented STM32F42xx Technical Training 20 10 2015 23 Use WWDG Objective Learn how to setup WWDG CubeMX How to Generate Code CubeMX and use HAL functions Create simple application to test WWDG Goal Configure WDGin CubeMX and Generate Code Learn how to start WWDG WWDG indication via LED Ly life augmented 23 Use WWDG Create project in CubeMX e Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt 144 gt STM32F439ZITx gt WWDG selection Select WWDG Configure PG14 for LED indication Ly life augmented 23 Use WWDG Create project in CubeMX e Menu gt File gt New Project e Sel
78. an TRACECLK E NWAIT NIORD NREG CD TRACED 3 0 4 INTR 180 MHz U FP erf as AF Ethernet MAC MDIO as 24 10 100 FIFOK gt USB owe PEL mro a OTGHS 8 Streams DMA2 FIFO memory ART ACCEL CACHE ae Camera interface USB 2 ic HSYNC VSYNC PUIXCLK D 13 0 DM ULPI CK D 7 0 DIR 5 NXT ID VBUS SOF DMA clock LCD R 7 0 LCD G 7 0 LCD B 7 0 LCD HSYNC LCD VSYNC LCD DE 6 2 DP DM ID VBUS SOF SRAM 64 KB VDD 1 7 1 8 to 3 6 V vss VCAP1 VCAP2 LCD_CLK AHB clock 712203 GPIO PORT A 150 GPIO PORT B 50 3 GPIO PORT C Hd PD 50K gt GPIO PORT D 4 26MHz R 1150 GPIO PORT E Standby PF 15 0 gt GPIO PORT d Sew PG 15 0K gt GPIO PORT G 5 5 32 OSC32_OUT 50 53 GPIO PORTH 98 7 RTC_AF1 lt GPIO PORTI PJ 15 0 GPIO PORT J PK 7 0 GPIO PORT K 4 channels ETR as AF APB2 bus clock owe D 7 0 Cwo ckasaF spio wMc e 2 AHB APB1 1 Configure GPIO for LED toggling Clock Configuration overview 24 Enable clocks which are gray How to enable gray features RTC and IWDG clock tree MCO1 source Mux RTC Clock Mux wo 6 H LSE To RTC KHz T 151 RC 32 IWDG KHz 32 KHz
79. ata into SDRAM and read it Goal Successfully import BSP into your project Learn which part you need to import How to setup the project Q z e 25 BSP for SDRAM initialization Create project CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx e We need only blank project with clock initialization We only set the RCC and configure the core to maximum speed APBI Prescaler 4 APB2 Prescsler 2 5 SYSCLK MHz AHB Prescaler HCLK 25 Use BSP for SDRAM initialization e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain e Now we can Generate Code Menu Project Generate Code Toolchain IDE 5 32 4 9211 Firmware Package and Version STM32Cube FW F4 V1 3 0 V Use latest available version Ly life augmented 25 BSP for SDRAM initialization e Now we have bank project For SDRAM we need to include more parts BSP_SDRAM Configuration Files SDRAM BSP SDRA PaIEWARM fh startup_stm32f439x s User 7 stm32f4xx hal msp c stm32f4xx it c ivers J CMSIS _51 32 4 Driver 32 46 E strn32f
80. augmented 14 Use SPI with DMA transfer n order to run on maximum frequency setup clock system Details in lab O 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AP81 Prescaler 4 4 2 uc 45 peripheral clocks MHz AHB Prescaler HCLK MHz 43 180 x2 30 APB1 Timer clocks MHz 2 Prescaler 42 90 2 peripheral clocks MHz X2 150 APB2timer clocks MHz gt 90 48MHz clocks MHz 125 clocks MHz PLLI2S 1225 clocks MHz SAI B clocks MHz 4 IQ 2 wa a 1235 LCD TFT clocks MHz PLLSAI Ly life augmented 14 Use SPI with DMA transfer CubeMX SPI configuration e Tab gt Configuration gt Connectivity gt SPI1 settings File Project Window Help 1 68 72 Button Connectivity 8 0 MBits s Low 1Edge Disabled y Bici mentod 5 32 429 439 Lore 144 None 14 Use SPI with DMA transfer CubeMX SPI configuration DMA settings TAB gt DMA Settings Button ADD SPI1_RX DMA Request Stream recti Priority Memory increment Button ADD s SPIT Ix e Memory incremen
81. callback HAL UART ErrorCallback Ly life augmented 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR end of process callback HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmented LS A HAL DMA IRQHandler DMA Stream IRQ NV Handler Generated in stm32f4xx it c 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR HAL Stream IRQ N Handler end of process callback HAL_UART_RxCpltCallback Ep Defined in 51113214 hal dma c and em then linked to process rror HAL UART ErrorCallback stm32f4xx hal uart c Ly life augmented 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Receive buffer over UART with DMA Not blocking function Siart process with DMA end of transfer ntinue E interrupt generation at en
82. cillator 16 16 MHz Disabled clocks How to enable PLL Source Mux 4 High speed external clocks 5 HSE Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 9 3 Low speed external HSE He Clock sources clocks m nternal oscillators e LSI LH Hel 1 Low speed internal External clock sources oscillator e LSE crystal or external signal in bypagS mode e HSE crystal 4 26MHz or external sighal 1 50MHz 32 KHz bypass mode 2 High speed internal oscillator 16 16 MHz Disabled clocks How to enable PLL Source Mux 4 High speed external clocks 5 HSE Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 10 External clock enabling TAB gt Pinout Select HSE and LSE clocks Bypass or crystal 5 19 RCC 1 Set HSE crystal High Speed Clock HSE Crystal Ceramic Res Low Speed Clock LSE Disable 5 2 CubeMX reserve pins RCC OSC IN 66 OSC OUT LAE Ly life augmented Configuration Configuration Power Consumption Calculator DMA2D ETH 9 9o 9 9 9 9 9 9 9 Low Speed Clock LSE Disable E Master Clock Output 1 8 9 RNG 1 Configure GPIO for LED toggling Clock Configuration overview 11
83. cu Reference STM32F49ZITX Firmware Package Name and Version STM32Cube FW F4 V1 3 0 V Use latest available version Ly life augmented 29 Use ADC with DMA HAL Library ADC with DMA flow ADClnitializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL_ADC_Start_DMA HAL_OK HAL_ERROR HAL BUSY HAL DMA IRQHandler DMA1 StreamX IRQHandler process callback ADC ConvOpltCallback process Error callback HAL ADC ErrorCallback Ly life augmented 29 Use ADC with DMA Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags and USER CODE BEGIN USER CODE END tags For DAC start use function e HAL ADC Start DMA ADC HandleTypeDef hadc uint32 t pData uint32 t Length e DAC functions e HAL DAC Start DAC HandleTypeDef hdac uint32 t Channel e HAL DAC SetValue DAC HandleTypeDef hdac uint32 t Channel uint32 t Alignment uint32 t Data igmented 29 Use ADC with DMA Solution Variables USER CODE BEGIN PV uint32_t value_adc uint32 t value dac 0 USER CODE END PV DAC setup and start ADC DAC USER CODE BEGIN 2 HAL DAC Start amp hdac DAC CHANNEL 2 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 12B R value dac ADC Start DMA amp hadci uint32 t amp v
84. d 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations 4 HAL HAL_ERROR HAL_ERROR 2 end of process callback S HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback gas Ly life augmented AL_DMA_IRQHandler DMA_Stream_IRQ i Defined by user 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Generated in main c and stm32f4xx_hal_msp c Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR end of process callback HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmented HAL IRQHandler DMA Stream IRQ Handler 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations 8191 process with DMA end of transte interrupt generation at of process HAL UART Receive DMA 2 HAL HAL_ERROR HAL_ERROR MA_IRQHandler DMA_Stream_IRQ Handler We recommend to use it in main c a 4 end of process callback HAL_UART_RxCpltCallback lt lt 4 process Error
85. d of process Ne HAL UART Receive DMA HAL OK HAL ERROR HAL ERROR end of process callback HAL UART RxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented HAL IRQHandler DMA Stream IRQ Handler 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Interrupt indicate the DMA receive half complete buffer or DMA error was detected Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR end of process callback HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmented HAL IRQHandler Se 1 DMA Stream IRQ Handler 2 22 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Process interrupt information from DMA and Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA UART DMA_Stream_IRQ Handler HAL_OK HAL_ERROR HAL_ERROR end of process callback HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmented lt 7 IRQHandler e 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA s
86. dler 3 Use WFI c Enter into SLEEP mode WFl ue 6 HAL interrupt handler Edge detection callback HAL GPIO EXTI Callback HAL files clearing 7 HAL EXTI callback flags check errors Ly life augmented 3 Use SLEEP mode with e Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 3 and USER CODE END 3 tags e Function to enter SLEEP HAL EnterSLEEPMode uint32 t Regulator uint8 1 SLEEPEntry We can measure consumption To be able to reprogram the STM32 which is in sTAG 720 SWD SWO clock E Auto LP mode use x2 ua Ijet JTAGjet connection during ied dead 4 TI Stellaris reset option Macraigor PE micro Ly life augmented 3 Use SLEEP mode with Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags Function to enter SLEEP e HAL EnterSLEEPModer uint32 t Regulator uint8 t SLEEPEntry We can measure consumption USER CODE BEGIN 3 Infinite loop while 1 HAL Delay 1000 HAL PWR EnterSLEEPMode PWR LOWPOWERREGULATOR ON PWR SLEEPENTRY USER CODE END 3 life augmented 3 Use SLEEP mode with Consumption still to high e Is STM32 really in SLEEP e Is the Systick di
87. driver for BSP LDC e Right click BSP gt ADD from Drivers BSP STM32F429I Discovery stm32f429i_discovery_eeprom c e stm321429i discovery io c g BSP 9341 0 a c stm32f429i_discovery_eeprom c stm32f429i_discovery_i discovery Icd E 5113214291 discovery sdram c 27 Use BSP to access EEPROM Add the define of EEPROM into project options e Right click on project Options Category C C Compiler gt Preprocesor Into Defined symbols add M24LR64 This allow use EEPROM functions Button OK close project options Defined symbols one per line USE DRIVER 5 32 439 DISCO 4291 M24LR64 27 Use BSP to access EEPROM e Use the ATM7 M24LR A board with M24LR memory and connect it into STM32F429i Discovery kit 1 all 6 2 L MB1075B www st com stm32f4 discovery es 8 06 Y 4 TL Ly life augmented 27 Use BSP to access EEPROM Into main c now modify include USER CODE BEGIN Includes include stm32f429i discovery lcd h include stm32f429i discovery io h include stm32f429i discovery eeprom h include lt string h gt USER CODE END Includes Define variables USER CODE BEGIN PV uint8 t text to write 2 test text write to eeprom uint8 t text to read 200 read from eeprom uint32 t address 0 address in eeprom uint16 t read num 1 number of by
88. eMX use the package from the Repository folder The CubeMX can generate the code for some GUI Keil IAR Atollic For the debugging is necessity to have the ST Link drivers e STSW LINKOOS driver for Win XP Vista 7 e STSW LINKOOG driver for Win 8 For driver installation you will need the Admin rights on your PC life augmented Appendix Documents CubeMX documentation e CubeMX user manual UM1718 http www st com st web ui static active en resource technical document user manual DMO0O1 047 12 pdf CubeMX release note 0094 http www st com st web ui static active en resource technical document user manual DMO01 047 12 pdf CubeMX technical note 0072 http www st com st web ui static active en resource technical document technical note CD00214439 pdf Ly life augmented STM32F4 documentation e STM32F429Zl web page htto www st com web en catalog mmc FM141 SC1169 SS1577 LN1806 PF25541 9 STM32F429 Datasheet htto www st com st web ui static active en resource technical document datasheet DM00071990 pdf e STM32F429 Reference Manual http www st com st web ui static active en resource technical document reference_manual DM00031020 paf STM32F429 Programming manual http www st com st web ui static active en resource technical document programming manual DM00046982 pdf Ly life augmented STM32F429i Discovery documentation e
89. ect STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx gt WWDG selection Select WWDG Configure PG14 for LED indication Ly life augmented 23 Use WWDG In order to run on maximum frequency setup clock system Details in lab 0 RTC Clock Mux LSE 3 To RTC KHz J 3 To IWDG KHz System Clock Mux 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz E SYSCLK MHz AHS HCLK MHz APB1 Prescaler 180 200 4 45 peripheral clocks MHz 180 max E PLLCLK X2 90 clocks MHz 2 Prescaler Enable CSS 2 5 30 APB2 peripheral clocks MHz x 2 3 180 2 timer clocks MHz Input frequency 8 2 9 48MHz clocks MHz 125 source Mux 125 clocks MHz 42 B 8 SAI1 A source 2 a PLLI2S 5 1 clocks MHz MCO2 source Mux pre nm B source Mux 2 44 4 5 HSE 5 1 8 docks MHz MCO1 source Mux 5 44 m MHz MCO1 Dee 16 2 2 4 2 7 2 M T 1225 LCD TH clocks MHz yy gt PLLSAI 8 life augmented 23 Use WWDG 1 9 WWDG Configuration CubeMX WWDG configuration of
90. ed 2 Configure EXT which turns LED HAL Library work flow 5 Peripheral Initializations including peripheral interrupt NVIC initializations Configure the GPIO to generate interrupt on rising or falling edge HAL EXTIO IRQHandler EXTIO IRQHandler Edge detection callback HAL GPIO EXTI Callback Usually in main c between 5 USER CODE BEGIN tags z e 42 2 Configure EXT which turns on LED HAL Library work flow summary 3 create 1 init NVIC Peripheral Initializations including peripheral interrupt NVIC E initializations 2 init GPIO Configure the GPIO to generate interrupt on rising or falling edge 5 HAL EXTI interrupt handler HAL files clearing flags check errors 4 EXTI interrupt handler Edge detection callback HAL_GPIO_EXTI_Callback 6 HAL EXTI callback life augmented 2 Configure EXTI which turns on LED Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 4 USER CODE END 4 tags Wecreate function which will handle the EXTI interrupts The HAL callback function for EXTI void GPIO EXTI Callback uint6 t GPIO Pin For LED turn on we need to use this functions HAL GPIO WritePin Ly life augmented 2 Configure EXT which turns LED e Now we open the project in our IDE The functions we want t
91. ef htim TIM callback void TIM1 UP TIM10 IRQHandler void e GPIO LED toggle e HAL GPIO TogglePin GPIO TypeDef uint6 t GPIO Pin igmented 15 Use with interrupt Solution TIM start USER CODE BEGIN 2 HAL Base Start_IT amp htim1 USER CODE END 2 Callback handling USER CODE BEGIN 4 void HAL TIM PeriodElapsedCallback TIM HandleTypeDef htim HAL GPIO TogglePin GPIOG GPIO 14 USER CODE END 4 life augmented with PWM output lab 16 16 Use with PWM output Objective Learn how to setup TIM with PWM out in CubeMX How to Generate Code in CubeMX and use HAL functions Indicate PWM on LED Goal Configure TIM in CubeMX and Generate Code Learn how start timer and set PWM out Verify the correct functionality with LED z e 16 Use with PWM output Create project in CubeMX Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX TIM selection 5 0 Select TIM clock source Internal clock Set Channel1 to PWM generation Ly life augmented 16 Use with PWM output CubeMX TIM configuration gt TAB gt Configuration gt Control gt TIM1 TAB gt Parameter settings Prescaler to 18000 Counter period to 10000 Trigger Output TRGO Parameters Toget
92. erate Code Toolchain IDE EWARM 6 70 Mcu and Firmware Package STM32F439ZITx _ Firmware Package Name and Version sTM32Cube FW_F4V1 3 0 Use latest available version life augmented 20 Use ADC in polling mode Start process ADC same for DMA DAC Non blocking start process Peripheral Initializations Start Process HAL DAC Start Peripheral Initializations Start Process HAL_ADC_ Start z e 42 20 Use ADC in polling mode Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags and USER CODE BEGIN 3 USER CODE END 3 tags For DAC start use function e HAL DAC Start DAC HandleTypeDef hdac uint32 t Channel e HAL ADC PollForConversion ADC HandleTypeDef hadc uint32 t Timeout HAL ADC GetValue ADC HandleTypeDef hadc DAC functions e HAL DAC Start DAC HandleTypeDef hdac uint32 t Channel e HAL DAC SetValue DAC HandleTypeDef hdac uint32 t Channel uint32 t Alignment uint32 t Data igmented 20 Use ADC in polling mode Solution Variables USER CODE BEGIN PV uint32_t value_adc uint32 t value dac 0 USER CODE END PV DAC setup and start USER CODE BEGIN 2 HAL DAC Start amp hdac DAC CHANNEL 2 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 12B R value dac USER CODE END 2
93. eripheral Initializations including peripheral interrupt NVIC initializations Configure the GPIO to generate interrupt on rising or falling edge Generated by CubeMX amen e E HAL EXTIO IRQHandler E 1227 Edge detection callback HAL GPIO EXTI Callback z e 42 i 2 Configure EXT which turns LED HAL Library work flow 2 Peripheral Initializations including peripheral interrupt NVIC initializations MX GPIO Init inside main c Configure the GPIO to generate interrupt on rising or falling edge HAL EXTIO IRQHandler EXTIO IRQHandler Edge detection callback HAL GPIO EXTI Callback Ly life augmented 2 Configure EXT which turns on LED HAL Library working flow 3 Peripheral Initializations including peripheral interrupt NVIC initializations Configure the GPIO to generate interrupt on rising or falling edge inside stm32f4xx it c HAL EXTIO IRQHandler ee Edge detection callback HAL GPIO EXTI Callback Ly life augmented 2 Configure EXT which turns LED HAL Library work flow 4 Peripheral Initializations including peripheral interrupt NVIC initializations Configure the GPIO to generate interrupt on rising or falling edge HAL EXTIO IRQHandler EXTIO IRQHandler Edge detection callback HAL GPIO EXTI Callback User must define Callback itis declared by default as empty weak Ly life augment
94. errupt Objective Learn how to setup RTC with interrupt in CubeMX Create simple RTC project with periodic alarm interrupt e Goal Use CubeMX and Generate Code with RTC Learn how to setup the RTC in HAL Verify the correct functionality by periodic RTC alarm interrupts z e 3 8 Use RTC and Alarm with interrupt Create project in CubeMX Menu File New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx e Set Internal Alarm on Alarm A or Alarm Set GPIO to toggle with LED as alarm indication E 9 RTC LD3 Use RIC and Alarm with interrupt n order to run on maximum frequency setup clock system Details in lab 0 RTC Clock Mux Hen LSE 2 To RTC KHz LSIRC 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz AHB Prescaler HCLK MHz APB1 Prescaler 180 45 peripheral clocks MHz 180 MHz max gt 2 50 Timer clocks MHz APB2 Prescaler ma 90 APB2 peripheral clocks MHz 90 MHz max Input frequency X2 lt gt 180 2 clocks MHz gt 9 48MHz clocks MHz 125 source Mux 125 clocks MHz 5 source 2 PLLI2S Q o SAI A clocks MHz 2 source Mux pre cu 2
95. gt ADC1 gt Parametr Settings Oa m Set ADC1 Pinout Clock Configuration Configuration Power Consumption Calculator e Set sampling time pci configuration for CH13 X7 Parameters Settings 7 Settings DMA Settings GPIO Settings 4 Configure the below parameters e Button OK ADCs Common Settings e DAC from previous Node Independent mode B Settings exam ple 4 Clock Prescaler PCLK2 divided by 2 Miidiewsres Le Resolution 12 bits 15 ADC Clock cycles Data Alignment Right alignment Scan Conversion Mode Disabled Discontinuous Conversion Mode Disabled DMA Continuous Requests Disabled Analog End Of Conversion Selection EOC flag at the end of single channel conversion 5 Regular ConversionMode ADC1 Number Of Conversion External Trigger Conversion Edge DAC Sampling Time ADC_Injected_ConversionMode Number Of Conversions E WatchDog Enable Analog WatchDog Mode Description y Enable or Disable the Continuous Conversion Mode life augmented 20 Use ADC in polling mode e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code 0 Menu gt Project gt Gen
96. he below parameters Stop bits Data direction 8 Bits induding Parity Oversampling ie 1 Baud Rate BaudRate must be between 110 Bits s and 10 5 MBits s life augmented 9 Simple UART communication USART GPIO configuration check On high baud rate set the GPIO speed to HIGH coun Baa gt GPIO mode GPIO Pull up Pu Maximum outpu User Label Modified e Set the HIGH output speed LL JUSARTI Alternate Functio Pul up Button OK PA10 USART1_RX Alternate Functio Pull up Hign PA 10 Configuration GPIO mode life augmented Group By IP 9 Simple UART communication e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code a D Radek __Training_examples F4 prague_2014 Labs Menu gt Project gt Generate Code Broder D Radek __Training_examples F4_prague_2014 abs USART_Pool Toolchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference 51 2 429711 Firmware Package and Version STM32Cube FW F4 V1 3 0 V Use latest available version Ly life augmented 9 simple UART communication HAL Library init flow C Peripheral initializations main c fi
97. her with 180 2 TIMER1 Master Slave Mode Disable no sync between this TIM Master and its Slaves clock we get period 1Hz an PWM pulse to 5000 this give us 1Hz blinking frequency Automatic Output State Off State Selection for Run Mode OSSR Off State Selection for Idle Mode OSSI Lock Configuration E PWM Generation Channel 1 Mode Fast Mode CH Polarity CH Idle State Ly life augmented 16 Use with PWM output e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code D Radek Training 4 prague 2014 6 PWM Menu gt Project gt Generate Code Toolchain IDE EWARM 6 70 2 Mcu and Firmware Package Mcu Reference ISTM32FA39ZITX Firmware Package Name and Version STM32Cube FW F4 V1 3 0 L Ly life augmented 16 Use with PWM output Start process TIM with PWM same for DMA ADC Non blocking start process Peripheral Initializations Start Process HAL_TIM PWM Start z e 42 16 Use with PWM output Open the project in our IDE The functions we want put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For TIM start use function e HAL
98. how to setup UART in CubeMX How to Generate Code in CubeMX and use HAL functions Work in pairs one will create transmitter and second receiver Goal Configure UART in CubeMX and Generate Code Learn how to send and receive data over UART without interrupts Verify the correct functionality z e 3 9 Simple UART communication Create project CubeMX Menu gt File gt New Project e Select STM32F4 gt STM32F 429 439 gt LQFP144 gt STM32F439ZITx Pin selection e We looking for free pins where is possible to create wire loopback connection Q e K 2 9 Simple UART communication Table 6 MCU pin description versus board function page 1 of 7 Pin selection MCUpn Board tunction We looking for free pins 8 8 where is possible to create 8 J Image from STM32F429 Discovery user manual life augmented simple UART communication Pin selection We are looking for free pins where is possible to create wire loopback connection Table 12 STM32F427xx and alternate function OTG2_HS 8 9 SPI3 US FMC SDIO EE ii BEES p scii BE 5 USART2_ ETH_MII_ EVEN SER ETR CTS CRS TOUT ETH 2 TMS USART2_ RX CLK E EVEN cH2 cH2 RTS TOUT REF_CLK EVEN
99. igure GPIO for LED toggling The Clock configuration tree is interactive version of tree from RM Figure 16 Clock tree IWOGCLK independent LS enable 32 kHz RTCSEL 1 0 RTC OSC32 IN NE LSE enabie 5T our Ll 22788 HSE RTC Ethernet PTP clock HCLK to AHB bus core memory and OMA to Cortex System timer I2SSRC RM0090 Chapter 6 Reset and clock control 1 P age 1 51 MII TX CLK MII Peri PHY Ethemet 147 enable MACTXCLK 2510050MHz ch 220 23 Mil_RMII_SEL in SYSCFG_PMC to Ethemet ck enable gt MACRXCLK 1 lock enable i MACRMIICLK Periphera USB2 0 PHY OTG HS SCL clock 2 24 to 60 MHz life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 1 e Clock sources e Internal oscillators Input frequency Internal oscillators PLL Source Mux Input frequency 1 Configure GPIO for LED toggling Clock Configuration overview 3 e Clock sources e Internal oscillators Input frequency External clock sources External clock sources PLL Source Mux Input frequency Ly life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 4 HSE 12 e Clock sources ul Input frequency Internal oscillators EX LSI External clock sources 1
100. increase STM32 consumption e It is good to adapt GPIO speed with periphery speed Ex Toggling GPIO 1Hz is LOW optimal settings but on 45MHz the HIGH must be set GPIO output LOW speed GPIO output MEDIUM speed LOW LOW SUPP sn HIGH HIGH GPIO output FAST speed GPIO output HIGH speed LOW LOW HIGH life augmented 1 Configure GPIO for LED toggling e Now we set the project details for generation Menu gt Project gt Project Settings Project Sting S RE X Set the project name e Project location e Type of toolchain Now we can Generate Code ProjectLocation 000 FRadekl Training examples l 4V ab USB Menu Project Generate Code Proje F Radek _Training_exemples F 4 26 USBVGPIO LAB Toolchain IDE 6 70 Mcu and Firmware Package Mcu Reference STM32F4292ITx Firmware Package Name and Version STM32Cube FW F4 V1 3 0 Ly life augmented 1 Configure GPIO for LED toggling Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags e Into infinite loop while 1 For toggling we need to use this functions HAL HAL Delay which create specific delay HAL GPIO WritePin HAL GPIO TogglePin Ly life augmented 1 Configure GPIO for LED toggling Now we open the project in our IDE The functions we want to pu
101. ject CubeMX Menu gt File gt New Project e Select STM32F4 gt STM32F 429 439 gt LQFP144 gt STM32F439ZITx Configure LED pin as GPIO_ Output life augmented 1 Configure GPIO for LED toggling For debug purpose is recommended to select debug pins SWD or JTAG e Select be done TAB gt Pinout gt SYS e On discovery is available only SWD option If SWD JTAG is not selected and the Set all free pins as analog MENU Project Settings TAB Code Generator is selected debug is not possible 9 SYS d x Debug Serial Wire Debug SWD deer E System Wake Up 5 gt HAL Settings i SYS_JTMS SWDIO life augmented Configure GPIO for LED toggling e Clock Configuration TAB gt Clock Configuration RTC Clock Mux 32 RTC KHz 180 Ethernet clock MHz 32 IWDG KHz 180 System Clock Mux 225 To Cortex System timer MHz 16 FCLK Cortex clock MHz SYSCLK MHz AHB Prescaler HCLK MHz APB1 Prescaler 180 41 180 4 5 45 1 peripheral clocks MHz 180 MHz max 30 APB1 Timer clocks MHz 90 2 peripheral clocks MHz 180 APB2 timer clocks MHz 48 clocks MHz 125 clocks 2 5 1 clocks MHz 2 source Mux 8 source Mux We can easily setup 51 32 clocks life augmented 1 Conf
102. l_dma_ex c stm32f4xx_hal_flash c E stm32f4xx_hal_flash_ex c stm32f4xx_hal_flash_ra E stm32f4xx hal gpio c 7 stm32f4xx hal pwr c E stm32f4xx hal pwr ex c stm32f4xx_hal_rec c stm32f4xx hal rcc ex c Ly Output life augmented 25 Use BSP for SDRAM initialization e stm32f429i_discovery c contains functions for all components on discovery kit LCD GYRO Then we also need add into project HAL library which handle their interface 12 SPI Loc M32F 40 HAL Driver EH Right click on STM32F4xx HAL Drive ADD Ee nae from Drivers STM32F4xx_HAL_Driver Sre stm32f4xx_hal_i2c c stm32fdxx hal dma c e stm32f4xx hal spi c stm32f4dxx hal dma exc stm32f4xx hal flash c stm32f4xx hal flash ex c 5 3214 1 fmc c stm3efdxx hal flash ramfunc c stm32f4xx hal sdram c 513214 hal pwr c 513214 hal pwr ex c stm32f4xx hal rec c stm32f4xx hal rcc ex c 13 Simca nal saram cC stm3efdxx hal spi c stm32f4xx I Ly life augmented 25 Use BSP for SDRAM initialization Now add the include paths for this new files e Right click on project Options Category C C Compiler gt Preprocesor e Into Defined symbols add USE 5 32 429 DISCO This allow use BSP functions Into additional includes add PROJ_DIR Drivers BSP STM32F429I Discovery Button OK Defined symbols one per line 23 DRIVER
103. le CubeMX UART init start in Init UART1 structure UART Init amp huart1 HAL UART Msplnit callback Init GPIO and NVIC for UART 5 z e 42 9 Simple UART communication HAL Library init flow Init UART1 structure HAL UART Msplnit callback UART Init amp huart1 Init GPIO and NVIC for UART 5 z e 42 9 Simple UART communication HAL Library init flow 1 We need ini 2 CubeMX create for us function which handle Init UART1 structure UART initialization HAL UART Init amp huart1 HAL UART Msplhit callback Init GPIO and NVIC for UART 5 z e 42 Simple UART communication HAL Library init flow MX_USART1_UART_Init function HAL_UART_Msplnit callback Init GPIO and NVIC for UART 5 z e 42 9 Simple UART communication HAL Library init flow 2 Call init MX USART1 UART Init function nc ___ __ structure gt d structure with parameters which we choose in Configuration window HAL UART Msplhit callback Init GPIO and NVIC for UART z e 42 9 Simple UART communication HAL Library init flow 2 Call UARTI init MX USART 1 UART Init function Init UART1 structure 3 Store UARTI configuration into structure UART Init amp huart1 HAL UART Msplhit callback
104. ler from HAL HAL API stm32f4xx hal i2c c f stm32f4xx hal sdram c sim32f4xx Il stm32f4xx hal Itdc c stm32f4xx hal c 26 Use BSP for LCD init and writing BSP LCD organization Our project ane BSP package Discovery drivers stm32f4xx_discovery c stm32f4xx discovery lcd c stm32f4xx_discovery_sdram c Component 2 stm32f4xx discovery Icd h use fonts from utility folder 1119341 c lis3dsh c HAL API TEET sim32f4xx Il stm32f4Axx hal Itdc c stm32f4xx hal c EIE 26 Use BSP for LCD init and writing C9 BSP SDRAM BSP_SDRAM Confi v use the project from BSP SDRAM e eun because the LCD also use the SDRAM TT main c e We need copy the Fonts from Utilities Boni Je folder in CubeMX repository M mam strn32f429i_discovery c E 513214291 discovery sdram c 43 Drivers Ha 22 CMSIS system stm32f4xx c Lo C3 STM32F4xx HAL Driver stm32f4xx hal c stm32f4xx hal cortex c E 513214 hal crc c stm32f4xx hal dma c stm32f4xx hal dma ex c E stm32f4xx flash c 51713214 hal flash ex c 513214 hal flash ramfunc c stm32f4xx hal gpio c 5103214 hal i2c c stm32f4xx hal pwr c E stm32f4xx hal pwr ex c stm32f4xx hal rcc c stm32f4xx hal rcc ex c 513214 hal sdram c
105. les USER CODE BEGIN PV uint32_t value_adc uint32 t value dac 0 USER CODE END PV DAC setup and start ADC DAC USER CODE BEGIN 2 HAL DAC Start amp hdac DAC CHANNEL 2 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 12B R value dac ADC Start IT amp hadc1 USER CODE END 2 Ly life augmented 21 Use ADC with interrupt Solution ADC complete callback routine USER CODE BEGIN 4 void HAL ADC ConvCpltCallback ADC HandleTypeDef hadc value_adc HAL_ADC_GetValue amp hadc1 HAL DAC SetValue amp hdac DAC CHANNEL 2 DAC ALIGN 12B R value dac value if value dac 4095 value dac 0 Delay 1 HAL ADC Start IT amp hadc1 USER CODE END 4 life augmented 21 Use ADC with interrupt STM studio settings e Check functionality File Run Views Options Help STMstudio VarViewer1 Display Variables Write Variables Display Variables settings life augmented ADC with DMA lab 22 29 Use ADC with DMA Objective Use the DAC part from previous lab Learn how to setup ADC with DMA in CubeMX How to Generate Code CubeMX and use HAL functions Goal Configure ADC in in CubeMX and Generate Code Learn how to start ADC and measure the DAC Verify the measured wave STMStudio http www st com web en catalog tools PF25137
106. ly import BSP EEPROM drivers into your project Learn which part you need to import How to setup the project life augmente 27 Use BSP to access EEPROM BSP EEPROM organization BSPpackagg sss 7 stm32f4xx_discovery_io c stm32f4xx_discovery_eeprom c 5 stm32f4xx discovery c Components Utilities ili9341 c lis8dsh c stmpe811 c Fonts HAL API stm32 4xx_hal_ spi stm32f4xx hal Itdc c stm32f4xx hal c stm32f4xx hal i2c c 27 Use BSP to access EEPROM BSP EEPROM organization 1 Use functions from Ourprojeci stm32f4xx discovery eeprom c BSP package stm32f4xx discovery lcd c stm32f4xx discovery sdram c stm32f4xx_discovery_io c Utilities ili9341 c lis3dsh c stmpe811 c Fonts HAL API TEET stm32f4xx_hal_ltdc c stm32f4xx_hal c stm32f4xx_ll_fmc c stm32f4xx_hal_i2c c 27 Use BSP to access EEPROM 2 stm32f4xx_discovery_eeprom c call functions from stm32f4xx discovery io c stm32f4xx_discovery_Icd c stm32f4xx discovery sdram c stm32f4xx_discovery c 3 stm32f4xx_discovery_io c call functions from stm32f4xx_discovery c pin init and write read functions Components 1119341 c lis3dsh c HAL API stma2t4xx hal SIm32txx II fmc stm32f4xx hal Itdc c stm32f4xx hal c CEA 27 Use BSP to access EEPROM BSP EEPROM organization package 00 00 88 Discovery drivers stm32f4xx_discovery_Icd c
107. n Project seking Type of toolchain UART DMA Project Location Now we can Generate Code D Radek _Training_examples F4_prague_2014 Labs Menu gt Project gt Generate Code 0 D Radek _Training_examples F4_prague_2014 abe UART_DMA Toolchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference STM32F439ZITx Firmware Package Name and Version STM32Cube FW F4V1 3 0 Use latest available version life augmented 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR end of process callback HAL_UART_RxCpltCallback process Error callback HAL_UART_ErrorCallback life augmented HAL IRQHandler DMA Stream IRQ Handler 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Generated by CubeMX V Start process with DMA end of transfer interrupt generation at end of process HAL UART Receive DMA HAL OK HAL ERROR HAL ERROR HAL_DMA_IRQHandler DMA_Stream_IRQ 7 4 end of process callback HAL_UART_RxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmente
108. ncluding peripheral interrupt NVIC 77 22 Generated main c and stm32f4xx_hal_msp c Start process with interrupt generation at end of process HAL UART Transmit IT HAL_UART_IRQHandler USART1_IRQHandler HAL_OK HAL_ERROR HAL_BUSY end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations process with interrupt gen of process HAL UART Transmit I eration RI 4 UART USART1_IRQHandler LN HAL OK HAL ERROR HAL BUSY Y end of process callback HAL UART TxCpltCallback b _ oa We recommend to use it in main c ee process Error callback HAL UART ErrorCallback 6 life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT USART1 IRQHandler IRQHandler HAL HAL_ERROR HAL_BUSY m uu HAL UART TxOCpltCallback Defined as weak you can process Error callback T find name of this functions in N HAL_UART_ErrorCallback __1 amp
109. ngs Now press STM Studio New confi File Run Views Options Help green play button u mese ETT 2 VarViewer1 And you will see content of Display Variables setings value adc 0 3 800 3 900 4 000 4 200 4 300 4 400 4 500 4 600 4 700 4 800 4 900 Ly a La life augmented ADC Interrupt lab 21 21 Use ADC with interrupt Objective Use the DAC part from previous lab Learn how to setup ADC with interrupt in CubeMX How to Generate Code CubeMX and use HAL functions Goal e Configure ADC in interrupt in CubeMX and Generate Code Learn how to start ADC and measure the DAC Verify the measured wave in STMStudio http www st com web en catalog tools PF251373 require JAVA z e 3 21 Use ADC with interrupt Create project CubeMX Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx e CubeMX DAC selection e Select DAC OUT2 e Select ADC IN13 2061 3 Ly life augmented 21 Use ADC with interrupt CubeMX ADC configuration TAB gt Configuration gt Analog gt ADC1 gt Parametr Settings Set ADC1 ccs IER Sa See Sd Pinout Clock Configuration Configuration Power Consumption Calculator e Set sampling time pci configuration for CH13 28 Parameters Settings Settings
110. o put into main c e Between USER CODE BEGIN 4 USER CODE END 4 tags Wecreate function which will handle the EXTI interrupts The HAL callback function for EXTI void GPIO EXTI Callback uint6 t GPIO Pin For LED turn on we need to use this functions HAL GPIO WritePin USER CODE BEGIN 4 void HAL GPIO EXTI Callback uinti6 t GPIO Pin if GPIO Pin GPIO 0 HAL_GPIO WritePin GPIOG GPIO PIN 14 GPIO PIN SET else __NOP USER CODE END 4 Q e K Low Power mode SLEEP lab 3 3 Use SLEEP mode with Objective We use the EXTI setup from lab 1 Learn how to setup SLEEP HAL Create simple project with SLEEP mode with wake up on pin press e Goal Use project from EXTI lab Learn how to setup the SLEEP in HAL which events can wake up you Verify the correct functionality by measuring consumption z e SLEEP Mode GPIO s ES FLASH Core is stopped Core CM4 RTC backup reg Peripherals are running Clock GP timers HSI HSE LSI USART LSE 12C Power regulator life augmented 3 Use SLEEP mode with HAL Library work flow summary create ERN Peripheral Initializations including peripheral interrupt NVIC a initializations 2 init GPIO Configure the GPIO to generate interrupt on rising or falling edge 5 EXTI interrupt han
111. oject name Project location Project Settings Type of toolchain s e peas Now we can Generate Code 2 Menu gt Project gt Generate Code pee Folder D Radek _Training_examples F4 prague _2014_modif_my Labs TIM_DMA Mcu Reference 32 43921 Firmware Package Name and Version 51 320 FW_F4V1 3 0 life augmented 17 Use with DMA transfer HAL Library TIM with DMA flow Peripheral Initializations including DMA stream initializations Start process with DMA DMA Start HAL HAL_ERROR HAL_ERROR Start process with TIM HAL TIM Base Start HAL OK HAL ERROR HAL ERROR Ly life augmented 17 Use with DMA transfer Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For TIM start use function e Base Start DMA TIM HandleTypeDef htim uint32 t pData uint16_t Length TIM1 trigger DMA transfer e ENABLE DMA start function HAL DMA Start DMA HandleTypeDef hdma uint32 t SrcAddress uint32 t DstAddress uint32 t DataLength GPIO LED register address uint32_t amp GPIOG gt ODR Ly life augmented 17 Use with DMA transfer Variable data definition USER CODE BEGIN PV uinti6 t data GPIO PIN 14 0x0000 USER CODE END PV DMA and TIM start
112. onfiguration overview 20 AHB prescalers and peripheral speed ever 180 Ethernet clock MHz HCLK to AHB bus core memory and DMA MHz APB1 peripherals clock 180 APB1 prescaler FCLK Cortex clock MHz HCLK MHz 180 180 1 Prescaler 4 v i MH Be 45 APB1 peripheral clocks MHz X2 gt 90 APB1 Timer clocks MHz APB2 Prescaler ipheral clocks MHz APB1 timers clock APB1 timers multiplier 1 Configure GPIO for LED toggling Clock Configuration overview 21 AHB prescalers and peripheral speed 180 Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz 180 22 5 To Cortex System timer MHz FCLK Cortex clock MHz APB2 peripherals clock 180 180 2 Prescaler cr 3 2 50 2 peripheral clocks MHz X2 180 2 timer clocks MHz Ly life augmented APB2 timers multiplier APB2 timers clock cks MHz APB1 Timer clocks MHz Configure GPIO for LED toggling Figure 4 STM32F437xx and STM32F439xx block diagram Clock Configuration overview 22 Data sheet Figure 4 clock life augmented Core memory APB2 bus clock xternal memory controller CLK NE 39 A 23 0 1MB Flash e 1MB Flash ULPLCK 070 DIR STP NXT 10 VBUS LCD 0 LCO 7 0 670
113. or DMA e HAL Start IT DMA HandleTypeDef hdma uint32 t SrcAddress uint32 t DstAddress uint32 t DataLength Ly life augmented 7 Use 2 transfer with interrupt We create two buffers One with source data Second as destination buffer USER CODE BEGIN uint8 t Buffer Src 0 1 2 3 4 5 6 7 8 9 uint8 t Buffer Dest 10 USER CODE END 0 T 3 gt 7 Use DMA 2 transfer with interrupt DMA callback creation function prototype USER CODE BEGIN uint8 t Buffer 506 0 1 2 3 4 5 6 7 8 9 uint8 t Buffer Dest 10 void XferCpltCallback DMA HandleTypeDef hdma USER CODE END 0 DMA complete callback with nop where we can put breakpoint USER CODE BEGIN 4 void XferCpltCallback DMA HandleTypeDef hdma __NOP we reach this only if DMA transfer was correct USER CODE END 4 life augmented 7 Use DMA 2 transfer with interrupt DMA Start Before we start the DMA with interrupt we need to set the callback into DMA structure Then is possible use the HAL_DMA_Start_IT to begin DMA transfer USER CODE BEGIN 2 hdma_memtomem_dma2_stream XferCpltCallback amp XferCpltCallback HAL Start IT amp hdma memtomem dma2 streamO uint32 t Buffer Src uint32 t Buffer Dest 10 USER CODE END 2 Ly life augmented Use RTC Alarm lab 8 STM32F42xx Technical Training 20 10 2015 8 Use RTC and Alarm with int
114. or callback DMA XferErrorCallback Ly life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Interrupt indicate DMA process 16 half complete or error was detected Start process with interrupt generation at end of process Start HAL DMA2_Stream0_IRQHandler x HAL HAL_ERROR HAL_BUSY end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Ly life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Process interrupt Start process with interrupt generation at end information of process HAL DMA Start IT 7 HAL_DMA_IRQHandler p HAL OK HAL ERROR HAL BUSY DMA2_Stream0_IRQHandler end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Ly life augmented 7 Use DMA 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start IT HAL OK HAL ERROR HAL BUSY DMA IRQHandler DMA2_Stream0_IRQHandler Data correctly transferred omplete callbac
115. pling None 1 life augmented 10 Use UART with interrupt CubeMX USART configuration NVIC settings gt Settings USARTI Configuration interrupts e Parameter Settings Enabled Preemption Priority OK JSART 1 global interrupt 1 life augmented 10 Use UART with interrupt e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain e Now we can Generate Code Menu gt Project gt Generate Code life augmented D Radek Training exampleslF4 2014 305 Project Folder D Radek _Training_examples F4_prague_2014 abs USART_IT Tookchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference STM32F439Z1Tx Firmware Package Name and Version STM32Cube FW_F4V1 3 0 F Use latest available version 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Receive IT HAL OK HAL ERROR HAL BUSY HAL_UART_IRQHandler USART1_IRQHandler end of process callback HAL UART RxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT
116. project name Project location Type of toolchain Project Folder Now we can Generate Code Dade Training examples 2014 mod myVabsWIM Counter Menu Project Generate Code Toolchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference STM32F439ZITx Firmware Package Name and Version sTM32Cube FW_F4V1 3 0 Use latest available version life augmented 18 Use as pulse counter HAL Library TIM with IT flow TIM Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL TIM Base Start IT HAL OK HAL ERROR HAL BUSY HAL TIM IRQHandler TIM1 UP TIM10 IRQHandler process callback PeriodElapseadCallback process Error callback HAL TIM ErrorCallback Ly life augmented 18 Use as pulse counter e Open the project in our IDE The functions we want put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For TIM start use function e HAL Base Start IT TIM HandleTypeDef htim TIM callback void TIM1 UP TIM10 IRQHandler void e GPIO LED toggle e HAL GPIO TogglePin GPIO TypeDef GPIOx uint6 t GPIO Pin igmented 18 Use as pulse counter Solution TIM start USER CODE BEGIN 2 HAL_TIM Base Start_IT amp htim1 USER CODE END 2 Callback handling USER C
117. rror callback HAL SPI ErrorCallback Ly life augmented HAL IRQHandler DMA2 StreamO IRQ Handler 14 Use SPI with DMA transfer Open the project in our IDE The functions we want put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags For transmit use function e HAL SPI TransmitReceive DMA SPI HandleTypeDef hspi uint8 t pTxData uint8 t oRxData 16 t Size igmented 14 Use SP with DMA transfer Buffer definition USER CODE BEGIN uint8 t tx_buff 0 1 2 3 4 5 6 7 8 9 uint8 t rx buff 10 USER CODE END 0 Sending and receiving methods USER CODE BEGIN 2 HAL SPI TransmitReceive DMA amp hspii tx buff rx buff 10 USER CODE END 2 34 2 gt 14 Use SP with DMA transfer Complete callback check We can put breakpoints on NOPs to watch if we send or receive complete buffer USER CODE BEGIN 4 void HAL SPI TxRxCpltCallback SPI HandleTypeDef hspi __NOP USER CODE END 4 z e 42 3 TIM with interrupt lab 15 15 Use with interrupt Objective Learn how to setup TIM with Interrupt in CubeMX How to Generate Code CubeMX and use HAL functions e Indicate TIM interrupt with LED toggle Goal Configure TIM in CubeMX and Generate Code Learn how start timer and handle interrupt Verify the correct functionality z e 15 Use
118. rrupt NVIC 77 22 Generated Start process with interrupt generation at end of process Start HAL DMA2_Stream0_IRQHandler HAL_OK HAL_ERROR HAL_BUSY end of process callback XferCpltCallback process Error callback DMA XferErrorCallback Ly life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations process with interrupt gen of process HAL_DMA_Start_IT eration a a RI 4 HAL HAL_ERROR HAL_BUSY end of process callback DMA XferCpltCallback b _ n We recommend to use it ee process Error callback DMA XferErrorCallback Pp Ly life augmented 7 Use DMA M2M transfer with interrupt HAL Library DMA with IT flow DMA Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process Start HAL ERROR HAL BUSY HAL DMA IRQHandler DMA2 0 IRQHandler EE XferCpltCallback process Error callback DMA XferErrorCallback User defined functions The user must define functions by and put function names 1 into DMA structure
119. rupt priority must be changed TAB gt Configuration gt System gt NVIC Change ADC1 preemption priority to 1 File Project Window Help 5 64 9 Configuration Priority Group 4 bits for pre emption priority O bits for subpriority E Sort by Premption Priority and Sub Prority Search A Show only enabled interrupts Preemption Priority Sub Priority m 0 0 0 0 0 0 0 IPVD through EXTI Line 16 interrupt ADC1 ADC2 and ADC3 global interrupts E Activated E Activated B Rec High Speed Clock HSE Crys RNG Oo E Activated We MCUs Selectior Series Lines STM32F4 STM32F 429 49 STM32F4 STM32F 429 44 2 4 51 32 429 41 y ISTM32F4 STM32F429 41 C Enabled Preemption Priority Sub Priority life augmented uired Peripherals 21 Use ADC with interrupt e Now we set the project details for generation Menu gt Project gt Project Settings Prcject setings Set the project name Project location Type of toolchain Project Folder Now we can
120. s Polling with timeout Peripheral Initializations P Polling process UM Transmit HAL TIMEOUT HAL OK HAL ERROR HAL BUSY z e 42 Q Simple UART communication HAL Library receive flow E Peripheral Initializations in ae Polling process HAL UART Receive Generated by CubeMX Function blocks Polling with timeout HAL TIMEOUT HAL OK HAL ERROR HAL BUSY z e 42 Q Simple UART communication HAL Library receive flow Created by user Peripheral Initializations P Polling process UM UART Receive Function blocks Polling with timeout HAL TIMEOUT HAL OK HAL ERROR HAL BUSY z e 42 Q Simple UART communication Open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags Into infinite while function For transmit use function e HAL UART Transmit UART HandleTypeDef huart uint8 t pData uint16 t Size uint32 t Timeout For receive use function e HAL UART Receive UART HandleTypeDef huart uint8 t pData uint16 t Size uint32 t Timeout Ly life augmented 9 Simple UART communication Transmit solution Create data structure for data USER CODE BEGIN 0 uint8 t 0 1 2 3 4 5 6 7 8 9 USER CODE END 0 Call transmit function from while loop USER
121. sabled USER CODE BEGIN 3 Infinite loop while 1 HAL Delay 1000 HAL SuspendTick HAL PWR EnterSLEEPMode PWR LOWPOWERREGULATOR ON PWR SLEEPENTRY ResumeTick USER CODE END 3 s this better life augmented Low Power mode STOP lab 4 life augmented 4 Use STOP mode with Objective We use the EXTI setup from lab 1 Learn how to setup STOP in HAL Create simple project with STOP mode with wake up on pin press e Goal Use project from EXTI lab Learn how to setup the STOP HAL which events can wake up you Verify the correct functionality by measuring consumption z e STOP Mode Core is stopped GPIO s HSE MSI clocks are OFF SRAM and registers IWDG content is preserved Peripherals with HSI LSI LSE clock option can be GP timers HSE ON SP 222723 e GPIO s keep their setup Em T 12C Power regulator NO 4 Use STOP mode with HAL Library work flow summary 1 init NVIC edge a 2 init GPIO Configure the GPIO to generate interrupt on rising or falling edge Peripheral Initializations including peripheral interrupt NVIC initializations 5 EXTI interrupt handler 3 Use WFI Enter into STOP mode WFI HAL EXTIO IRQHandler 8 6 HAL EXT clock after intenup
122. t Button OK Increment Address Use Fifo Threshold Half Full Data Width Burst Size life augmented 14 Use SPI with DMA transfer CubeMX SPI configuration NVIC settings e TAB gt NVIC Settings SPI Configuration Enable interrupts for ef Parameter Settings NVIC senos 7 DMA Settings Button OK 51 1 global interrun 0 0 4 DMA2 Stream0 global interrupt Liv p 0 p Ly life augmented 14 Use SPI with DMA transfer e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Project Settings Project Name 5 1 Type of toolchain Project Location e Now we can Generate Code EE DPEN INNAN Menu Project Generate Code Perder D CRadekV Training examplesY 4 prague 2014 modif 65 DMA Toolchain IDE Mcu Reference STM32F439ZITx Firmware Package Name and Version STM32Cube FW F4 V1 3 0 V Use latest available version Ly life augmented 14 Use SPI with DMA transfer HAL Library SPI with DMA TX RX flow Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL SPI TransmitReceive DMA HAL OK HAL ERROR HAL ERROR end of process callback SPI TxRxOCpltCallback process E
123. t handier 22 Edge detection callback HAL GPIO EXTI Callback HAL files clearing 7 HAL flags check errors callback life augmented 4 Use STOP mode with e Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 3 and USER CODE END 3 tags e Function to enter SLEEP HAL EnterSTOPMode uint32 t Regulator uint8 t STOPEntry e HAL PWREx EnterUnderDriveSTOPMode uint32 t Regulator uint8 t STOPEntry We can measure consumption To be able to reprogram the STM32 which is in LP mode use connection during reset option Ly life augmented Options for node Reset Interface Clock setup JTAG 0000006 720 SWO clock F Auto 2000 kHz I jet JTAGjet JAink J Trace TI Stellaris Macraigor PE micro 05100 200 01 4 Use STOP mode with e Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN USER CODE END tags Function to enter SLEEP e HAL EnterSTOPMode uint32 t Regulator uint8 t STOPEntry e HAL PWREx EnterUnderDriveSTOPMode uint32 t Regulator uint8 t STOPEntry We can measure consumption USER CODE BEGIN 3 Infinite loop while 1 HAL Delay 1000 HAL EnterSTOPMode PWR LOWPOWERREGULATOR ST
124. t into main c Between USER CODE BEGIN USER CODE END tags e Into infinite loop while 1 For toggling we need to use this functions HAL HAL Delay which create specific delay HAL GPIO WritePin HAL GPIO TogglePin USER CODE BEGIN 3 Infinite loop while 1 HAL GPIO WritePin GPIOG GPIO PIN 14 GPIO PIN SET HAL Delay 500 HAL GPIO WritePin GPIOG GPIO PIN 14 GPIO PIN RESET HAL Delay 500 USER CODE END 3 Q e K EXTI lab 2 life augmented STM32F42xx Technical Training 20 10 2015 2 Configure EXT which turns LED Objective Learn how to setup input pin with EXTI in CubeMX How to Generate Code in CubeMX and use HAL functions e Goal Configure GPIO and EXTI pin CubeMX and Generate Code e Add into project Callback function and function which turn on led Verify the correct functionality by pressing button which turns on LED z e 3 2 Configure EXTI which turns on LED Create project in CubeMX Menu gt File gt New Project e Select STM32F4 gt STM32F429 439 gt 144 gt STM32F439ZITx Configure LED pin as GPIO Output Configure Button pin as GPIO EXTIX life augmented 2 Configure EXT which turns LED Create project e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx e Configure LED pin as GPIO
125. t thing is allow to include new HAL files which we added e Open stm32f4xx_hal_conf h in Inc Uncomment files which we added HAL DMA2D MODULE ENABLED HAL LTDC MODULE ENABLED Ly life augmented Use BSP for LCD init and writing 4 43 444 44444443 4 44444 334 Module 55160 brief This is the list of modules to be used in the HAL driver define HAL MODULE ENABLED define HAL ADC MODULE ENABLED define HAL CAN MODULE ENABLED define HAL CRC MODULE ENABLED define HAL CRYP MODULE ENABLED define HAL DAC MODULE ENABLED 4 2 EN LZ BAL ENABLED TA A 0 NAND MODULE ENABLED define HAL NOR MODULE ENABLED define HAL PCCARD MODULE ENABLED define HAL SRAM MODULE ENABLED define HAL SDRAM MODULE ENABLED define HAL HASH MODULE ENABLED define HAL 126 MODULE ENABLED define HAL _ 125 mn define HAL LTDC ENABLED TAI LE define HAL RTC MODULE ENABLED define HAL SAI MODULE ENABLED define HAL SD MODULE ENABLED define HAL SPI MODULE ENABLED define HAL MODULE ENABLED define HAL UART MODULE ENABLED define HAL USART MODULE ENABLED define HAL IRDA MODULE ENABLED define HAL SMARTCARD MODULE ENABLED define HAL WWDG MODULE ENABLED define HAL PCD MODULE ENABLED define HAL HCD MODULE ENABLED define HAL GPIO MODULE ENABLED define HAL
126. tes which we want to read from eeprom USER CODE END PV life augmented 27 Use BSP to access EEPROM e Into stm32f4xx_hal_it c add global variable for i2c handle USER CODE BEGIN 9 extern 126 HandleTypeDef I2cHandle USER CODE END 6 and define handler functions for DMA USER CODE BEGIN 1 void DMA1 Stream4 IRQHandler 1 HAL DMA IRQHandler I2cHandle hdmatx void DMA1 5676802 IRQHandler HAL DMA IRQHandler I2cHandle hdmarx USER CODE END 1 life augmented 27 Use BSP to access EEPROM 5 e Into main c add USER CODE BEGIN 2 LCD init BSP LCD Init BSP LCD LayerDefaultInit 1 SDRAM DEVICE ADDR BSP LCD SelectLayer 1 BSP LCD DisplayOn BSP LCD Clear LCD COLOR BLUE BSP LCD SetBackColor LCD COLOR BLUE BSP LCD SetTextColor LCD COLOR WHITE EEPROM init BSP EEPROM Init Write text into EEPROM BSP EEPROM WriteBuffer text to write 0 strlen text to write 41 Read text from EEPROM dot BSP EEPROM ReadBuffer uint8 t amp text to read address address uinti16 t amp read num jwhile text to 4 4 554 411 0 0 Display text BSP LCD DisplayStringAtLline 2 text to read USER CODE END 2 Ly life augmented BSP GYRO lab 28 28 Use BSP to access GYROSCOPE Objective Learn how import BSP GYROSCOPE into project We use the project from lab 26 Which part need to by
127. transmit flow Peripheral Initializations including peripheral interrupt NVIC initializations Start process with interrupt generation at end of process HAL UART Transmit IT HAL OK HAL ERROR HAL BUSY HAL_UART_IRQHandler USART1_IRQHandler end of process callback HAL UART TxOpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT transmit flow Peripheral Initializations including peripheral interrupt NVIC initializations Generated by CubeMX Start process with interrupt generation at end of process HAL UART Transmit IT HAL_UART_IRQHandler USART1_IRQHandler ME 27 HAL HAL_ERROR HAL_BUSY end of process callback HAL_UART_TxCpltCallback process Error callback HAL UART ErrorCallback Ly life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations including peripheral interrupt NVIC initializations art process with interrupt generation at end 98 of process e HAL UART Transmit IT IRQHandler USART1_IRQHandler Defined by user HAL_OK HAL_ERROR HAL_BUSY end of process callback HAL_UART_TxCpltCallback process Error callback HAL UART ErrorCallback p life augmented 10 Use UART with interrupt HAL Library UART with IT receive flow Peripheral Initializations i
128. tream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_ DMA HAL_OK HAL_ERROR HAL_ERROR HAL IRQHandler DMA Stream IRQ Handler iback process HAL UART RxCpltCallback i data buffer is full HAL use Complete callback process Error callback HAL UART ErrorCallback function Ly life augmented 11 Use UART with DMA transfer HAL Library UART with DMA RX flow Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA HAL_OK HAL_ERROR HAL_ERROR DMA_Stream_IRQ Handler Or if DMA error was detected use Error callback function HAL IRQHandler end of process callback HAL UART RxOpltCallback process Error callback P HAL UART ErrorCallback life augmented 11 Use UART with DMA transfer HAL Library UART with DMA RX flow 1 ARTI and receive buffer HAL_OK HAL_ERROR HAL_ERROR Peripheral Initializations including DMA stream initializations Start process with DMA end of transfer interrupt generation at end of process HAL_UART_Receive_DMA DMA_Stream_IRQ Handler 3 DMA buffer z Bul 4 Process full end of process callback interrupt HAL_UART_RxCpltCallback recess process Error callback 5
129. values Most of CubeMX functions have return values which indicate if operation was successful timeout occurs of function end with error s recommended handle this return values to be sure that program working as expected Ex Poll for process complete HAL DMA PollForTransfer HAL OK HAL ERROR HAL BUSY Error occurs during DMA transfer you use GetkError for details what happened Ly life augmented 6 Use DMA in M2M transfer e Return values Most of CubeMX functions have return values which indicate if operation was successful timeout occurs of function end with error s recommended handle this return values to be sure that program working as expected Ex Poll for process complete HAL DMA PollForTransfer HAL OK HAL ERROR HAL BUSY DMA transfer in progress user can only abort the transfer Ly life augmented 6 Use DMA M2M transfer Now we open the project in our IDE The functions we want to put into main c Between USER CODE BEGIN 2 USER CODE END 2 tags HAL functions for DMA HAL DMA Start DMA HandleTypeDef hdma uint32 t SrcAddress uint32 t DstAddress uint32 t DataLength HAL DMA PollForTransfer DMA HandleTypeDef hdma uint32 t CompleteLevel uint32 t Timeout Ly life augmented 6 Use 2 transfer We create two buffers One with source data Second as destination buffer USER CODE BE
130. ving methods USER CODE BEGIN 2 HAL SPI TransmitReceive IT amp hspil tx buff rx buff 10 USER CODE END 2 34 2 gt 13 Use with interrupt Complete callback check We put breakpoints on NOPs to watch if we send or receive complete buffer USER CODE BEGIN 4 void HAL SPI TxRxCpltCallback SPI HandleTypeDef hspi __NOP USER CODE END 4 Q K DMA lab 14 life augmented STM32F42xx Technical Training 20 10 2015 14 Use SPI with DMA transfer Objective Learn how to setup with DMA in CubeMX How to Generate Code CubeMX and use HAL functions Create simple loopback example with DMA Goal e Configure SPI in CubeMX and Generate Code Learn how to send and receive data over SPI with DMA Verify the correct functionality z e 3 14 Use SPI with DMA transfer Create project CubeMX e Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX SPI selection e Select SPI1 Full Duplex Master e Select PA5 PA6 for SPI1 if weren t selected 0 0 17 O ae 2 5 life augmented Hardware preparation e Connect 6 and together with jumper 1 ES Cy C 77 gt Ws Sb 906000 C 6 life
131. width 3 Increment Burst size addresses Button OK 4 FIFO setup Ly life augmented 7 Use 2 transfer with interrupt DMA configuration System gt NVIC Enable DMA2 Stream interrupt File Project Window Help ButtonOK 28 Se SL eeN 1 TAB gt Configuration Priority Group 0 bits for pre emption priority 4 bits for subpriority Sort by Premption Priority and Sub Prority _ 1 Show only enabled interrupts 3 Enable DMA2 D re OTT interrupts MM gt 7 Activated One Pulse Mode 9 E Activated C One Pulse Mode 2 WWDG E Activated Ly life augmented 7 Use 2 transfer with interrupt e Now we set the project details for generation Menu gt Project gt Project Settings Set the project name Project location Type of toolchain Now we can Generate Code D Wadek Training exampleslF4 prague 2014 modf myVabs _ Menu gt Project gt Generate Code D Radek _Training_examples F4_prague_2014_modif_my Labs DMA_IT Toolchain IDE EWARM 6 70 Mcu and Firmware Package Mcu Reference STM32F439ZITx Firmware Package Name and Version STM32Cube FW F4V1 3 0 Ly life augmented 7 Use 2 transfer with interrupt HAL Library DMA with IT flow D
132. xData uint8 t oRxData uint16 t Size uint32 t Timeout igmented 12 Simple communication Transmit receive solution Create data structure for data USER CODE BEGIN PV uint8 t tx_buffer 0 1 2 3 4 5 6 7 8 9 uint8 t rx buffer 10 USER CODE END PV Call transmit receive function USER CODE BEGIN 2 HAL SPI TransmitReceive amp hspi1 tx_buffer rx_buffer 10 100 USER CODE END 2 T 2 gt Interrupt lab 13 13 Use SPI with interrupt Objective Learn how to setup SPI with interrupts in CubeMX How to Generate Code CubeMX and use HAL functions Create simple loopback example with interrupts Goal Configure SPI in CubeMX and Generate Code Learn how to send and receive data over SPI with interrupts Verify the correct functionality z e 13 Use SPI with interrupt Create project CubeMX Menu gt File gt New Project Select STM32F4 gt STM32F429 439 gt LQFP144 gt STM32F439ZITx CubeMX SPI selection e Select SPI1 Full Duplex Master e Select PA5 PA6 for SPI1 if weren t selected 2 6 1 Mode Full Duplex Master v 9 Hardware NSS Signal ree 5 7 6 life augmented Hardware preparation e Connect 6 and together with jumper 1 ES Cy C 77 gt Ws Sb 0696 6 6 666 life augmented 1
133. y N mE muc HSE divide by 1 4 26MHz Core frequency is now 8MHz life augmented 1 Configure GPIO for LED toggling Clock Configuration overview 15 Core clocked from PLL and HSI PLL as system source System Clock Mux Lc PLL clock source SYSCLK xe AHB Prescaler HCLK MHz a gt 10 HSI 2 PLL multiplier by 360 System frequency 180MHz 180 MHz max A AHB prescaler divide by 1 Input frequency B HSE To 4 26MHz Core frequency is now 180MHz PLL in M divider by 16 PLL out P divider by 2 1 Configure GPIO for LED toggling Clock Configuration overview 16 Core clocked from PLL and HSE PLL as system source Clock System frequency 180MHz HSE crystal or external HS signal 7 PLL clock source SYSCLK MHz AHB Prescaler HCLK MHz HSE 180 j1 9 i 180 MHz max gt prescaler divide by 1 Input frequency moi 4 26MHz PLL in M divider eT EET by 8 H Core frequency is now 180MHz PLL out P divider by 2 PLL multiplier N by 360 Hj 1 Configure GPIO for LED toggling Clock Configuration overview 17 AHB prescalers and peripheral speed Ethernet PTP clock MHz HCLK to AHB bus core memory and DMA MHz B8 22
134. z HSI RC 16 FCLK Cortex clock MHz SYSCLK MHz AHB HCLK MHz ADB1 Prescaler 180 10 45 APBi peripheral clocks MHz x2 90 APB1 Timer clocks MHz 2 Prescaler Enable CSS diam 30 APB2 peripheral clocks MHz Input frequency X2 180 2 timer clocks MHz 4 26MHz gt 9 48 clocks MHz 96 125 clocks MHz Kise N IR 5 source 2 10 T 0 1 PLLI2S 8 Ew 1 jk doda piti MCO2 source Mux 1 4 SAI1 B source Mu 04 7 N gt 1225 clocks MHz MCO1 source Mux E e 0 Q MHz MCOl 046 1 lt m PLLSAI 8 life augmented simple UART communication CubeMX UART configuration e Tab gt Configuration gt Connectivity gt USART 1 STM32CubeMX Untitled STM32F429ZITx X File Project Window Help Gi ap Middlewares E Activated Connectivity System RNG M ME 6 LN t7 E Activated USART Universal Synchronous Asynchronous Receiver Transmitter 7 One Pulse Mode configured You can generate code using the current values cm m gt F Activated i One Pulse Mode 6 9 simple UART communication e CubeMX USART configuration check BaudRate M dns S Parameter setings 9 Configure t

Download Pdf Manuals

image

Related Search

Related Contents

"user manual"  File - Information Systems Department  User's gUide User's gUide  User Manual - chem IT Services  THESE PRESENTEE A L`UNIVERSITE BORDEAUX I Par Emilie  Drucken - Firmware Center  D-Link DCS-931L surveillance camera  J.P. LAND  DENTAL X-RAY Service Manual  

Copyright © All rights reserved.
Failed to retrieve file