1
0

board.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. /*******************************************************************************
  41. * Function Name : SysTick_Configuration
  42. * Description : Configures the SysTick for OS tick.
  43. * Input : None
  44. * Output : None
  45. * Return : None
  46. *******************************************************************************/
  47. void SysTick_Configuration(void)
  48. {
  49. RCC_ClocksTypeDef rcc_clocks;
  50. rt_uint32_t cnts;
  51. RCC_GetClocksFreq(&rcc_clocks);
  52. cnts = (rt_uint32_t)rcc_clocks.HCLK_Frequency / RT_TICK_PER_SECOND;
  53. SysTick_Config(cnts);
  54. SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  55. }
  56. #if STM32_EXT_SRAM
  57. void EXT_SRAM_Configuration(void)
  58. {
  59. FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
  60. FSMC_NORSRAMTimingInitTypeDef p;
  61. GPIO_InitTypeDef GPIO_InitStructure;
  62. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
  63. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOG | RCC_APB2Periph_GPIOE |
  64. RCC_APB2Periph_GPIOF, ENABLE);
  65. /*-- GPIO Configuration ------------------------------------------------------*/
  66. /* SRAM Data lines configuration */
  67. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
  68. GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  69. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  70. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  71. GPIO_Init(GPIOD, &GPIO_InitStructure);
  72. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  73. GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  74. GPIO_Pin_15;
  75. GPIO_Init(GPIOE, &GPIO_InitStructure);
  76. /* SRAM Address lines configuration */
  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 |
  79. GPIO_Pin_14 | GPIO_Pin_15;
  80. GPIO_Init(GPIOF, &GPIO_InitStructure);
  81. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
  82. GPIO_Pin_4 | GPIO_Pin_5;
  83. GPIO_Init(GPIOG, &GPIO_InitStructure);
  84. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  85. GPIO_Init(GPIOD, &GPIO_InitStructure);
  86. /* NOE and NWE configuration */
  87. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5;
  88. GPIO_Init(GPIOD, &GPIO_InitStructure);
  89. /* NE3 NE4 configuration */
  90. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_12;
  91. GPIO_Init(GPIOG, &GPIO_InitStructure);
  92. /* NBL0, NBL1 configuration */
  93. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
  94. GPIO_Init(GPIOE, &GPIO_InitStructure);
  95. /*-- FSMC Configuration ------------------------------------------------------*/
  96. p.FSMC_AddressSetupTime = 0;
  97. p.FSMC_AddressHoldTime = 0;
  98. p.FSMC_DataSetupTime = 2;
  99. p.FSMC_BusTurnAroundDuration = 0;
  100. p.FSMC_CLKDivision = 0;
  101. p.FSMC_DataLatency = 0;
  102. p.FSMC_AccessMode = FSMC_AccessMode_A;
  103. FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
  104. FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
  105. FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
  106. FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
  107. FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
  108. FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
  109. FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
  110. FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
  111. FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
  112. FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
  113. FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
  114. FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
  115. FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
  116. FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
  117. FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
  118. /* Enable FSMC Bank1_SRAM Bank */
  119. FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE);
  120. }
  121. #endif
  122. /**
  123. * This is the timer interrupt service routine.
  124. *
  125. */
  126. void rt_hw_timer_handler(void)
  127. {
  128. /* enter interrupt */
  129. rt_interrupt_enter();
  130. rt_tick_increase();
  131. /* leave interrupt */
  132. rt_interrupt_leave();
  133. }
  134. /**
  135. * This function will initial STM32 board.
  136. */
  137. void rt_hw_board_init()
  138. {
  139. /* NVIC Configuration */
  140. NVIC_Configuration();
  141. /* Configure the SysTick */
  142. SysTick_Configuration();
  143. #if STM32_EXT_SRAM
  144. EXT_SRAM_Configuration();
  145. #endif
  146. rt_hw_usart_init();
  147. rt_console_set_device(CONSOLE_DEVICE);
  148. }
  149. /*@}*/