board.c 6.0 KB

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