board.c 6.2 KB

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