rt-thread/bsp/stm32f7-disco/drivers/board.c

190 lines
5.6 KiB
C
Raw Normal View History

2015-08-07 13:30:13 +08:00
/*
2018-10-16 13:00:37 +08:00
* Copyright (c) 2006-2018, RT-Thread Development Team
2015-08-07 13:30:13 +08:00
*
2018-10-16 13:00:37 +08:00
* SPDX-License-Identifier: Apache-2.0
2015-08-07 13:30:13 +08:00
*
* Change Logs:
* Date Author Notes
* 2018-05-17 ZYH first implementation
2015-08-07 13:30:13 +08:00
*/
#include <rtthread.h>
#include "board.h"
#include "drv_mpu.h"
#include "drv_sdram.h"
#include <rthw.h>
2015-08-09 09:17:28 +08:00
2015-08-07 13:30:13 +08:00
/**
* @addtogroup STM32
*/
static void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
2015-08-09 09:17:28 +08:00
/**Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 25;
RCC_OscInitStruct.PLL.PLLN = 432;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 9;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
/**Activate the Over-Drive mode
*/
HAL_PWREx_EnableOverDrive();
2015-08-09 09:17:28 +08:00
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7);
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC|RCC_PERIPHCLK_USART1
|RCC_PERIPHCLK_USART6|RCC_PERIPHCLK_UART4
|RCC_PERIPHCLK_UART5|RCC_PERIPHCLK_UART7
|RCC_PERIPHCLK_SDMMC2|RCC_PERIPHCLK_CLK48;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
PeriphClkInitStruct.Uart4ClockSelection = RCC_UART4CLKSOURCE_PCLK1;
PeriphClkInitStruct.Uart5ClockSelection = RCC_UART5CLKSOURCE_PCLK1;
PeriphClkInitStruct.Usart6ClockSelection = RCC_USART6CLKSOURCE_PCLK2;
PeriphClkInitStruct.Uart7ClockSelection = RCC_UART7CLKSOURCE_PCLK1;
PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48SOURCE_PLL;
PeriphClkInitStruct.Sdmmc2ClockSelection = RCC_SDMMC2CLKSOURCE_CLK48;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
2015-08-07 13:30:13 +08:00
}
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
/**Configure the Systick interrupt time
*/
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / RT_TICK_PER_SECOND);
/**Configure the Systick
*/
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
return HAL_OK;
}
uint32_t HAL_GetTick(void)
{
return rt_tick_get() * 1000 / RT_TICK_PER_SECOND;
}
void HAL_Delay(__IO uint32_t Delay)
{
rt_thread_delay(Delay * 1000 / RT_TICK_PER_SECOND);
}
void HAL_SuspendTick(void)
{
/* we should not suspend tick */
}
void HAL_ResumeTick(void)
{
/* we should not resume tick */
}
#if defined(BSP_USING_SDRAM) && defined(RT_USING_MEMHEAP_AS_HEAP)
static struct rt_memheap system_heap;
#endif
void HAL_MspInit(void)
{
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
/* System interrupt init*/
/* MemoryManagement_IRQn interrupt configuration */
HAL_NVIC_SetPriority(MemoryManagement_IRQn, 0, 0);
/* BusFault_IRQn interrupt configuration */
HAL_NVIC_SetPriority(BusFault_IRQn, 0, 0);
/* UsageFault_IRQn interrupt configuration */
HAL_NVIC_SetPriority(UsageFault_IRQn, 0, 0);
/* SVCall_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SVCall_IRQn, 0, 0);
/* DebugMonitor_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DebugMonitor_IRQn, 0, 0);
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
}
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 */
bsp_mpu_hw_init();
/* Enable I-Cache-------------------------------------------------------------*/
rt_hw_cpu_icache_enable();
2015-08-09 09:17:28 +08:00
/* Enable D-Cache-------------------------------------------------------------*/
rt_hw_cpu_dcache_enable();
2015-08-09 09:17:28 +08:00
/* 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
*/
/* Configure the system clock @ 216 Mhz */
2015-08-09 09:17:28 +08:00
SystemClock_Config();
2015-08-07 13:30:13 +08:00
HAL_Init();
#ifdef RT_USING_HEAP
#if defined(BSP_USING_SDRAM) && defined(RT_USING_MEMHEAP_AS_HEAP)
bsp_sdram_hw_init();
rt_system_heap_init((void *)SDRAM_BEGIN, (void *)SDRAM_END);
rt_memheap_init(&system_heap, "sram", (void *)HEAP_BEGIN, HEAP_SIZE);
#else
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
#endif
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
#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
}