2015-08-07 13:30:13 +08:00
|
|
|
/*
|
|
|
|
* File : board.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
2015-09-02 12:06:40 +08:00
|
|
|
* COPYRIGHT (C) 2015, RT-Thread Development Team
|
2015-08-07 13:30:13 +08:00
|
|
|
*
|
2015-09-02 12:06:40 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2015-08-07 13:30:13 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-01-05 Bernard first implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include "board.h"
|
2015-09-25 15:35:37 +08:00
|
|
|
#include "sram.h"
|
|
|
|
|
2015-08-09 09:17:28 +08:00
|
|
|
|
2015-08-07 13:30:13 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup STM32
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief System Clock Configuration
|
2015-08-09 09:17:28 +08:00
|
|
|
* The system Clock is configured as follow :
|
2015-08-07 13:30:13 +08:00
|
|
|
* System Clock source = PLL (HSE)
|
|
|
|
* SYSCLK(Hz) = 200000000
|
|
|
|
* HCLK(Hz) = 200000000
|
|
|
|
* AHB Prescaler = 1
|
|
|
|
* APB1 Prescaler = 4
|
|
|
|
* APB2 Prescaler = 2
|
|
|
|
* HSE Frequency(Hz) = 25000000
|
|
|
|
* PLL_M = 25
|
|
|
|
* PLL_N = 400
|
|
|
|
* PLL_P = 2
|
|
|
|
* PLLSAI_N = 384
|
|
|
|
* PLLSAI_P = 8
|
|
|
|
* VDD(V) = 3.3
|
|
|
|
* Main regulator output voltage = Scale1 mode
|
|
|
|
* Flash Latency(WS) = 6
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static void SystemClock_Config(void)
|
|
|
|
{
|
2015-08-09 09:17:28 +08:00
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
|
|
HAL_StatusTypeDef ret = HAL_OK;
|
|
|
|
|
|
|
|
/* Enable HSE Oscillator and activate PLL with HSE as source */
|
|
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
|
|
|
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
|
|
|
RCC_OscInitStruct.PLL.PLLM = 25;
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 400;
|
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
2015-09-20 14:47:50 +08:00
|
|
|
RCC_OscInitStruct.PLL.PLLQ = 8;
|
2015-09-25 15:35:37 +08:00
|
|
|
|
2015-09-20 14:47:50 +08:00
|
|
|
ret = HAL_RCC_OscConfig(&RCC_OscInitStruct);
|
|
|
|
if(ret != HAL_OK)
|
|
|
|
{
|
2015-09-25 15:35:37 +08:00
|
|
|
while (1) { ; }
|
2015-09-20 14:47:50 +08:00
|
|
|
}
|
2015-08-09 09:17:28 +08:00
|
|
|
|
|
|
|
ret = HAL_PWREx_EnableOverDrive();
|
|
|
|
if (ret != HAL_OK)
|
|
|
|
{
|
2015-09-20 14:47:50 +08:00
|
|
|
while (1) { ; }
|
2015-08-09 09:17:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
|
|
|
|
clocks dividers */
|
2015-09-25 15:35:37 +08:00
|
|
|
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |\
|
|
|
|
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
|
2015-08-09 09:17:28 +08:00
|
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
|
|
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
|
2015-09-20 14:47:50 +08:00
|
|
|
ret = HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
|
|
|
|
if (ret != HAL_OK)
|
|
|
|
{
|
|
|
|
while (1) { ; }
|
|
|
|
}
|
2015-08-07 13:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief CPU L1-Cache enable.
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
static void CPU_CACHE_Enable(void)
|
|
|
|
{
|
2015-08-09 09:17:28 +08:00
|
|
|
/* Enable branch prediction */
|
|
|
|
SCB->CCR |= (1 << 18);
|
|
|
|
__DSB();
|
|
|
|
|
|
|
|
/* Enable I-Cache */
|
|
|
|
SCB_EnableICache();
|
|
|
|
|
|
|
|
/* Enable D-Cache */
|
|
|
|
SCB_EnableDCache();
|
2015-08-07 13:30:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the timer interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
|
|
|
/* enter interrupt */
|
|
|
|
rt_interrupt_enter();
|
|
|
|
|
2015-09-20 14:47:50 +08:00
|
|
|
/* tick for HAL Library */
|
|
|
|
HAL_IncTick();
|
|
|
|
|
2015-08-07 13:30:13 +08:00
|
|
|
rt_tick_increase();
|
|
|
|
|
|
|
|
/* leave interrupt */
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
2015-09-20 14:47:50 +08:00
|
|
|
/* re-implementat tick interface for STM32 HAL */
|
|
|
|
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
|
|
|
|
{
|
|
|
|
/*Configure the SysTick to have interrupt in 1ms time basis*/
|
|
|
|
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/RT_TICK_PER_SECOND);
|
|
|
|
|
|
|
|
/*Configure the SysTick IRQ priority */
|
|
|
|
HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);
|
|
|
|
|
|
|
|
/* Return function status */
|
|
|
|
return HAL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_Delay(__IO uint32_t Delay)
|
|
|
|
{
|
|
|
|
rt_thread_delay(Delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_SuspendTick(void)
|
|
|
|
{
|
|
|
|
/* we should not suspend tick */
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_ResumeTick(void)
|
|
|
|
{
|
|
|
|
/* we should not resume tick */
|
|
|
|
}
|
|
|
|
|
2015-08-07 13:30:13 +08:00
|
|
|
/**
|
|
|
|
* This function will initial STM32 board.
|
|
|
|
*/
|
|
|
|
void rt_hw_board_init()
|
|
|
|
{
|
2015-08-09 09:17:28 +08:00
|
|
|
/* Configure the MPU attributes as Write Through */
|
2015-09-25 15:35:37 +08:00
|
|
|
//mpu_init();
|
2015-08-09 09:17:28 +08:00
|
|
|
|
|
|
|
/* Enable the CPU Cache */
|
|
|
|
CPU_CACHE_Enable();
|
|
|
|
|
|
|
|
/* STM32F7xx HAL library initialization:
|
|
|
|
- Configure the Flash ART accelerator on ITCM interface
|
|
|
|
- Configure the Systick to generate an interrupt each 1 msec
|
|
|
|
- Set NVIC Group Priority to 4
|
|
|
|
- Global MSP (MCU Support Package) initialization
|
|
|
|
*/
|
|
|
|
HAL_Init();
|
|
|
|
/* Configure the system clock @ 200 Mhz */
|
|
|
|
SystemClock_Config();
|
|
|
|
/* init systick */
|
2015-08-07 13:30:13 +08:00
|
|
|
SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);
|
|
|
|
/* set pend exception priority */
|
|
|
|
NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1);
|
|
|
|
|
2015-09-25 15:35:37 +08:00
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
2015-08-09 09:17:28 +08:00
|
|
|
rt_components_board_init();
|
2015-09-25 15:35:37 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RT_USING_EXT_SDRAM
|
|
|
|
rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END);
|
|
|
|
sram_init();
|
|
|
|
#else
|
|
|
|
rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END);
|
|
|
|
#endif
|
2015-08-09 09:17:28 +08:00
|
|
|
|
2015-08-07 13:30:13 +08:00
|
|
|
#ifdef RT_USING_CONSOLE
|
|
|
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|