board.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 RT-Thread Develop Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard first implementation
  13. * 2013-07-12 aozima update for auto initial.
  14. */
  15. #include <rthw.h>
  16. #include <rtthread.h>
  17. #include "stm32f10x.h"
  18. #include "stm32f10x_fsmc.h"
  19. #include "board.h"
  20. #ifdef RT_USING_COMPONENTS_INIT
  21. #include <components.h>
  22. #endif /* RT_USING_COMPONENTS_INIT */
  23. /**
  24. * @addtogroup STM32
  25. */
  26. /*@{*/
  27. /*******************************************************************************
  28. * Function Name : NVIC_Configuration
  29. * Description : Configures Vector Table base location.
  30. * Input : None
  31. * Output : None
  32. * Return : None
  33. *******************************************************************************/
  34. void NVIC_Configuration(void)
  35. {
  36. #ifdef VECT_TAB_RAM
  37. /* Set the Vector Table base location at 0x20000000 */
  38. NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  39. #else /* VECT_TAB_FLASH */
  40. /* Set the Vector Table base location at 0x08000000 */
  41. NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  42. #endif
  43. }
  44. #if STM32_EXT_SRAM
  45. void EXT_SRAM_Configuration(void)
  46. {
  47. FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
  48. FSMC_NORSRAMTimingInitTypeDef p;
  49. /* FSMC GPIO configure */
  50. {
  51. GPIO_InitTypeDef GPIO_InitStructure;
  52. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF
  53. | RCC_APB2Periph_GPIOG, ENABLE);
  54. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  55. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  56. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  57. /*
  58. FSMC_D0 ~ FSMC_D3
  59. PD14 FSMC_D0 PD15 FSMC_D1 PD0 FSMC_D2 PD1 FSMC_D3
  60. */
  61. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_14 | GPIO_Pin_15;
  62. GPIO_Init(GPIOD,&GPIO_InitStructure);
  63. /*
  64. FSMC_D4 ~ FSMC_D12
  65. PE7 ~ PE15 FSMC_D4 ~ FSMC_D12
  66. */
  67. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10
  68. | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  69. GPIO_Init(GPIOE,&GPIO_InitStructure);
  70. /* FSMC_D13 ~ FSMC_D15 PD8 ~ PD10 */
  71. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10;
  72. GPIO_Init(GPIOD,&GPIO_InitStructure);
  73. /*
  74. FSMC_A0 ~ FSMC_A5 FSMC_A6 ~ FSMC_A9
  75. PF0 ~ PF5 PF12 ~ PF15
  76. */
  77. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3
  78. | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  79. GPIO_Init(GPIOF,&GPIO_InitStructure);
  80. /* FSMC_A10 ~ FSMC_A15 PG0 ~ PG5 */
  81. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
  82. GPIO_Init(GPIOG,&GPIO_InitStructure);
  83. /* FSMC_A16 ~ FSMC_A18 PD11 ~ PD13 */
  84. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  85. GPIO_Init(GPIOD,&GPIO_InitStructure);
  86. /* RD-PD4 WR-PD5 */
  87. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
  88. GPIO_Init(GPIOD,&GPIO_InitStructure);
  89. /* NBL0-PE0 NBL1-PE1 */
  90. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  91. GPIO_Init(GPIOE,&GPIO_InitStructure);
  92. /* NE1/NCE2 */
  93. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  94. GPIO_Init(GPIOD,&GPIO_InitStructure);
  95. /* NE2 */
  96. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  97. GPIO_Init(GPIOG,&GPIO_InitStructure);
  98. /* NE3 */
  99. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  100. GPIO_Init(GPIOG,&GPIO_InitStructure);
  101. /* NE4 */
  102. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  103. GPIO_Init(GPIOG,&GPIO_InitStructure);
  104. }
  105. /* FSMC GPIO configure */
  106. /*-- FSMC Configuration ------------------------------------------------------*/
  107. p.FSMC_AddressSetupTime = 0;
  108. p.FSMC_AddressHoldTime = 0;
  109. p.FSMC_DataSetupTime = 2;
  110. p.FSMC_BusTurnAroundDuration = 0;
  111. p.FSMC_CLKDivision = 0;
  112. p.FSMC_DataLatency = 0;
  113. p.FSMC_AccessMode = FSMC_AccessMode_A;
  114. FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
  115. FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  116. FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  117. FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  118. FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  119. FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
  120. FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  121. FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  122. FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  123. FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  124. FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  125. FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  126. FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  127. FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  128. FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
  129. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  130. /* Enable FSMC Bank1_SRAM Bank */
  131. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
  132. }
  133. #endif
  134. /**
  135. * This is the timer interrupt service routine.
  136. *
  137. */
  138. void SysTick_Handler(void)
  139. {
  140. /* enter interrupt */
  141. rt_interrupt_enter();
  142. rt_tick_increase();
  143. /* leave interrupt */
  144. rt_interrupt_leave();
  145. }
  146. /**
  147. * This function will initial STM32 board.
  148. */
  149. void rt_hw_board_init(void)
  150. {
  151. /* NVIC Configuration */
  152. NVIC_Configuration();
  153. /* Configure the SysTick */
  154. SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );
  155. #if STM32_EXT_SRAM
  156. EXT_SRAM_Configuration();
  157. #endif
  158. rt_hw_usart_init();
  159. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  160. #ifdef RT_USING_COMPONENTS_INIT
  161. rt_components_board_init();
  162. #endif
  163. }
  164. /*@}*/