Advertisement
Guest User

Untitled

a guest
Jul 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #include "stm32f4xx_conf.h"
  2. #include <stm32f4xx.h>
  3. #include <stm32f4xx_gpio.h>
  4.  
  5. /* A Led blink lab for STM32 Discovry Disco *
  6. * Based on: *
  7. * Discovering the STM32 Microcontroller by Geoffrey Brown. */
  8.  
  9. void setupLED(GPIO_InitTypeDef *LED_InitStruct);
  10. void sleep(uint32_t nSec);
  11.  
  12. int main(int argc, char **argv)
  13. {
  14. int LEDVal = 0;
  15. GPIO_InitTypeDef LED_InitStruct;
  16.  
  17. /* Setup LED */
  18. setupLED(&LED_InitStruct);
  19.  
  20. /* Setup timer interrupt interval to nano second */
  21. if(SysTick_Config(SystemCoreClock / 1000)) {
  22. while(1); /* Trap here if failed */
  23. }
  24.  
  25. /* Blinking LED3 and LED4 */
  26. while(1) {
  27. GPIO_WriteBit(GPIOG, GPIO_Pin_13 , LEDVal);
  28. GPIO_WriteBit(GPIOG, GPIO_Pin_14 , !LEDVal);
  29.  
  30. sleep(250);
  31. LEDVal = !LEDVal;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
  37. void setupLED(GPIO_InitTypeDef *LED_InitStruct)
  38. {
  39. /* Setup LED GPIO */
  40. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE);
  41.  
  42. GPIO_StructInit(LED_InitStruct);
  43. LED_InitStruct->GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 ;
  44. LED_InitStruct->GPIO_Mode = GPIO_Mode_OUT;
  45. LED_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
  46. GPIO_Init(GPIOG, LED_InitStruct);
  47. }
  48.  
  49. static __IO uint32_t g_timeToWakeUp;
  50. void sleep(uint32_t nSec)
  51. {
  52. g_timeToWakeUp = nSec;
  53.  
  54. /* Busy waiting */
  55. while(g_timeToWakeUp != 0);
  56. }
  57.  
  58. /* ISR for system tick */
  59. void SysTick_Handler(void)
  60. {
  61. if (g_timeToWakeUp != 0x00) {
  62. g_timeToWakeUp--;
  63. }
  64. }
  65.  
  66. /* Trap here for gdb if asserted */
  67. void assert_failed(uint8_t* file, uint32_t line)
  68. {
  69. while(1);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement