PageRenderTime 26ms CodeModel.GetById 47ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/stm32f4xx/stm32f4xx.c

https://github.com/hikob/openlab
C | 119 lines | 72 code | 16 blank | 31 comment | 0 complexity | e908c37331abf0f665cd7463bedfc404 MD5 | raw file
  1. /*
  2. * This file is part of HiKoB Openlab.
  3. *
  4. * HiKoB Openlab is free software: you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public License
  6. * as published by the Free Software Foundation, version 3.
  7. *
  8. * HiKoB Openlab is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with HiKoB Openlab. If not, see
  15. * <http://www.gnu.org/licenses/>.
  16. *
  17. * Copyright (C) 2011,2012 HiKoB.
  18. */
  19. /*
  20. * stm32f4xx.c
  21. *
  22. * Created on: Nov 6, 2012
  23. * Author: Clément Burin des Roziers <clement.burin-des-roziers.at.hikob.com>
  24. */
  25. #include "stm32f4xx.h"
  26. #include "nvic_.h"
  27. /* All GPIOs */
  28. GPIO_INIT(_gpioA, GPIOA_BASE_ADDRESS, RCC_AHB_BIT_GPIOA);
  29. GPIO_INIT(_gpioB, GPIOB_BASE_ADDRESS, RCC_AHB_BIT_GPIOB);
  30. GPIO_INIT(_gpioC, GPIOC_BASE_ADDRESS, RCC_AHB_BIT_GPIOC);
  31. GPIO_INIT(_gpioD, GPIOD_BASE_ADDRESS, RCC_AHB_BIT_GPIOD);
  32. GPIO_INIT(_gpioE, GPIOE_BASE_ADDRESS, RCC_AHB_BIT_GPIOE);
  33. GPIO_INIT(_gpioF, GPIOF_BASE_ADDRESS, RCC_AHB_BIT_GPIOF);
  34. GPIO_INIT(_gpioG, GPIOG_BASE_ADDRESS, RCC_AHB_BIT_GPIOG);
  35. GPIO_INIT(_gpioH, GPIOH_BASE_ADDRESS, RCC_AHB_BIT_GPIOH);
  36. GPIO_INIT(_gpioI, GPIOI_BASE_ADDRESS, RCC_AHB_BIT_GPIOI);
  37. /* Real I2C */
  38. I2C_INIT(_i2c1, I2C1_BASE_ADDRESS, RCC_APB_BUS_I2C1, RCC_APB_BIT_I2C1,
  39. NVIC_IRQ_LINE_I2C1_EV, NVIC_IRQ_LINE_I2C1_ER);
  40. I2C_INIT(_i2c2, I2C2_BASE_ADDRESS, RCC_APB_BUS_I2C2, RCC_APB_BIT_I2C2,
  41. NVIC_IRQ_LINE_I2C2_EV, NVIC_IRQ_LINE_I2C2_ER);
  42. /* Real SPIs */
  43. SPI_INIT(_spi1, SPI1_BASE_ADDRESS, RCC_APB_BUS_SPI1, RCC_APB_BIT_SPI1, NVIC_IRQ_LINE_SPI1);
  44. SPI_INIT(_spi2, SPI2_BASE_ADDRESS, RCC_APB_BUS_SPI2, RCC_APB_BIT_SPI2, NVIC_IRQ_LINE_SPI2);
  45. SPI_INIT(_spi3, SPI3_BASE_ADDRESS, RCC_APB_BUS_SPI3, RCC_APB_BIT_SPI3, NVIC_IRQ_LINE_SPI3);
  46. /* Real Timers */
  47. TIMER_INIT(_tim1, TIM1_BASE_ADDRESS, RCC_APB_BUS_TIM1, RCC_APB_BIT_TIM1, NVIC_IRQ_LINE_TIM1_CC, 4);
  48. TIMER_INIT(_tim2, TIM2_BASE_ADDRESS, RCC_APB_BUS_TIM2, RCC_APB_BIT_TIM2, NVIC_IRQ_LINE_TIM2, 4);
  49. TIMER_INIT(_tim3, TIM3_BASE_ADDRESS, RCC_APB_BUS_TIM3, RCC_APB_BIT_TIM3, NVIC_IRQ_LINE_TIM3, 4);
  50. TIMER_INIT(_tim4, TIM4_BASE_ADDRESS, RCC_APB_BUS_TIM4, RCC_APB_BIT_TIM4, NVIC_IRQ_LINE_TIM4, 4);
  51. TIMER_INIT(_tim5, TIM5_BASE_ADDRESS, RCC_APB_BUS_TIM5, RCC_APB_BIT_TIM5, NVIC_IRQ_LINE_TIM5, 4);
  52. TIMER_INIT(_tim6, TIM6_BASE_ADDRESS, RCC_APB_BUS_TIM6, RCC_APB_BIT_TIM6, NVIC_IRQ_LINE_TIM6_DAC, 0);
  53. TIMER_INIT(_tim7, TIM7_BASE_ADDRESS, RCC_APB_BUS_TIM7, RCC_APB_BIT_TIM7, NVIC_IRQ_LINE_TIM7, 0);
  54. TIMER_INIT(_tim8, TIM8_BASE_ADDRESS, RCC_APB_BUS_TIM8, RCC_APB_BIT_TIM8, NVIC_IRQ_LINE_TIM8_CC, 4);
  55. /* Real UARTs */
  56. UART_INIT(_uart1, USART1_BASE_ADDRESS, RCC_APB_BUS_USART1,
  57. RCC_APB_BIT_USART1, NVIC_IRQ_LINE_USART1);
  58. UART_INIT(_uart2, USART2_BASE_ADDRESS, RCC_APB_BUS_USART2,
  59. RCC_APB_BIT_USART2, NVIC_IRQ_LINE_USART2);
  60. UART_INIT(_uart3, USART3_BASE_ADDRESS, RCC_APB_BUS_USART3,
  61. RCC_APB_BIT_USART3, NVIC_IRQ_LINE_USART3);
  62. /* DMA STREAMS */
  63. DMA_INIT(_dma1_str0, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 0, NVIC_IRQ_LINE_DMA1_STR0);
  64. DMA_INIT(_dma1_str1, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 1, NVIC_IRQ_LINE_DMA1_STR1);
  65. DMA_INIT(_dma1_str2, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 2, NVIC_IRQ_LINE_DMA1_STR2);
  66. DMA_INIT(_dma1_str3, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 3, NVIC_IRQ_LINE_DMA1_STR3);
  67. DMA_INIT(_dma1_str4, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 4, NVIC_IRQ_LINE_DMA1_STR4);
  68. DMA_INIT(_dma1_str5, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 5, NVIC_IRQ_LINE_DMA1_STR5);
  69. DMA_INIT(_dma1_str6, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 6, NVIC_IRQ_LINE_DMA1_STR6);
  70. DMA_INIT(_dma1_str7, DMA1_BASE_ADDRESS, RCC_AHB_BIT_DMA1, 7, NVIC_IRQ_LINE_DMA1_STR7);
  71. DMA_INIT(_dma2_str0, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 0, NVIC_IRQ_LINE_DMA2_STR0);
  72. DMA_INIT(_dma2_str1, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 1, NVIC_IRQ_LINE_DMA2_STR1);
  73. DMA_INIT(_dma2_str2, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 2, NVIC_IRQ_LINE_DMA2_STR2);
  74. DMA_INIT(_dma2_str3, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 3, NVIC_IRQ_LINE_DMA2_STR3);
  75. DMA_INIT(_dma2_str4, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 4, NVIC_IRQ_LINE_DMA2_STR4);
  76. DMA_INIT(_dma2_str5, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 5, NVIC_IRQ_LINE_DMA2_STR5);
  77. DMA_INIT(_dma2_str6, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 6, NVIC_IRQ_LINE_DMA2_STR6);
  78. DMA_INIT(_dma2_str7, DMA2_BASE_ADDRESS, RCC_AHB_BIT_DMA2, 7, NVIC_IRQ_LINE_DMA2_STR7);
  79. /* Definitions for user access */
  80. const gpio_t gpioA = GPIO_A;
  81. const gpio_t gpioB = GPIO_B;
  82. const gpio_t gpioC = GPIO_C;
  83. const gpio_t gpioD = GPIO_D;
  84. const gpio_t gpioE = GPIO_E;
  85. const gpio_t gpioF = GPIO_F;
  86. const gpio_t gpioG = GPIO_G;
  87. const gpio_t gpioH = GPIO_H;
  88. const gpio_t gpioI = GPIO_I;
  89. const i2c_t i2c1 = I2C_1;
  90. const i2c_t i2c2 = I2C_2;
  91. const spi_t spi1 = SPI_1;
  92. const spi_t spi2 = SPI_2;
  93. const uart_t uart1 = UART_1;
  94. const uart_t uart2 = UART_2;
  95. const uart_t uart3 = UART_3;
  96. const openlab_timer_t tim1 = TIM_1;
  97. const openlab_timer_t tim2 = TIM_2;
  98. const openlab_timer_t tim3 = TIM_3;
  99. const openlab_timer_t tim4 = TIM_4;
  100. const openlab_timer_t tim5 = TIM_5;
  101. const openlab_timer_t tim6 = TIM_6;
  102. const openlab_timer_t tim7 = TIM_7;
  103. const openlab_timer_t tim8 = TIM_8;