Let's Play STM32

Download Let's Play STM32

Post on 24-May-2015

1.010 views

Category:

Technology

7 download

Embed Size (px)

DESCRIPTION

a course Slide for Taipei Tech

TRANSCRIPT

  • 1. Lets Play STM32PJayChen Hung-Da Lin

2. ARM Cortex-M4 3. ARM ProcessorsCortex-A (Application)High-end embedded OS, MMU. Ex: Smart PhoneCortex-R(Real-time)Ex: BlueRayplayers, Hard Disk Drive controllersCortex-M(Microcontroller)Embedded System, replace 8051http://www.arm.com/index.php 4. ARM Cortex-M Chip 5. ARM Cortex-MARMv7M ArchitectureNo Cache, No MMUSupport DIV instructionInterrupts automatically save/restore stateFixed memory mapThumb-2 processing coreHigh code density 6. ARM Cortex-M 7. DocumentationThe Definitive Guide To The ARM Cortex-M3ARM Cortex-M3 IntroductionJserv week3 8. STM32f4xx 9. DocumentationSTM32F429_DatasheetDevice features, OverviewDevice block diagramMemory mapPinoutsand pin descriptionSTM32F4xx_Reference ManualHow to use the STM32f4xx memory and peripheralsSTM32, but its use the Cortex-M3STM32f10xwikiSTM32 10. Memory MappingFixed4GI/O 0x8000000 11. STM32F4xx Standard Peripherals LibrarySTAPICprintf(),LibrarySTM32F429I-Discovery_FW_V1.0.1LibrariesSTM32F4xx_StdPeriph_Driver 12. CMSISCMSIS(Cortex Microcontroller Software Interface Standard)vendor-independent hardware abstraction layerCPU(Cortex-M)Chip 13. CMSISSTM32 14. CMSISsystem_stm32f4xx.c STM32F4xx_Clock_Configuration.xls 15. CMSISstartup_stm32f4xx.sstack,vector table(Reset_Handler)ResetReset_HandlerdataflashSRAM(Harvard architecture)bssdata0system_stm32f4xx.cSystemInit(),blmain; Entry point,main()Linker scriptstartup code 16. Device Block DiagramSTM32F407_datasheet 17. Device Block DiagramSTM32F407_datasheet 18. Clock TreeClock gatingSTM32F4xx_Reference Manual 19. How to Use PeripheralsGPIO ConfigurationAlternate Function ConfigurationEnable PeriphClockRCC_AHB1PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);Enable Alternate function PeriphClockRCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);Configure AF to specific GPIOGPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); 20. GPIOGPIO(General-purpose I/O) ()GPIOA~GPIOE, 0~15pin 21. GPIO Input ConfigurationpinGPIO_InitStructure.GPIO_Mode= GPIO_Mode_IN;Floating, Pull-up/pull-downpull-up or pull-down GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;orGPIO_PuPd_UP;orGPIO_PuPd_DOWN; 22. GPIO Output ConfigurationpinGPIO_InitStructure.GPIO_Mode= GPIO_Mode_OUT;Push-PullGPIO_InitStructure.GPIO_OType= GPIO_OType_PP;Open-DrainGPIO_InitStructure.GPIO_OType= GPIO_OType_OD; 23. GPIO Analog configuration/pinGPIO_InitStructure.GPIO_Mode= GPIO_Mode_AN;input data register0ADC, DAC 24. GPIO Alternate function configurationAFGPIO_InitStructure.GPIO_Mode= GPIO_Mode_AF;SPI, USART, I2C, SDIO, TIM 25. Exercise ! https://github.com/PJayChen/STM32f4xx_Bootloader/blob/master/src/hw_conf.c#L12 26. An example, How to use USARTStep 1, Check the AF mapping from the Datasheet123 27. An example, How to use USARTStep 2, Find the USART1 is connect to which bus 28. An example, How to use USARTStep 3, Lets coding, Configure the system clocks/* USART1 clock enable */RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);/* GPIOA clock enable */RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); 29. An example, How to use USARTStep 4, Configure the GPIOGPIO_InitTypeDefGPIO_InitStructure;GPIO_InitStructure.GPIO_Pin= GPIO_Pin_9 | GPIO_Pin_10;GPIO_InitStructure.GPIO_Mode= GPIO_Mode_AF;GPIO_InitStructure.GPIO_OType= GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_NOPULL;GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz;GPIO_Init(GPIOA, &GPIO_InitStructure); 30. An example, How to use USARTStep 5, Connect USART with GPIO pinsGPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); //TXGPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); //RX 31. An example, How to use USARTStep 6, Configure the USART//Structure With Data For USART ConfigurationUSART_InitTypeDefUSART_InitStructure;//USART ParametersUSART_InitStructure.USART_BaudRate= 9600;USART_InitStructure.USART_WordLength= USART_WordLength_8b;USART_InitStructure.USART_StopBits= USART_StopBits_1;USART_InitStructure.USART_Parity= USART_Parity_No;USART_InitStructure.USART_HardwareFlowControl= USART_HardwareFlowControl_None;USART_InitStructure.USART_Mode= USART_Mode_Rx| USART_Mode_Tx;//Configuring And Enabling USART1USART_Init(USART1, &USART_InitStructure);USART_Cmd(USART1, ENABLE); 32. An example, How to use USARTStep 7, Rx/TxTx//Wait till the flag resetswhile(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);//Send the dataUSART_SendData(USART2, data);Rx//Wait for characterwhile(USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == RESET) ;//Collect the characterData = USART_ReceiveData(USART2); //the data type is uint8_t 33. FreeRTOS 34. DocumentationThe Architecture of Open Source Application: FreeRTOSStudy of an operating system: FreeRTOS