board.c 6.3 KB

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