board.c 6.0 KB

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