2016-08-19 00:35:30 +08:00
|
|
|
/*
|
2018-10-05 13:29:50 +08:00
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
2016-08-19 00:35:30 +08:00
|
|
|
*
|
2018-10-05 13:29:50 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-08-19 00:35:30 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2009-01-05 Bernard first implementation
|
|
|
|
*/
|
2018-10-05 13:29:50 +08:00
|
|
|
|
2017-02-07 15:42:42 +08:00
|
|
|
#include <stdint.h>
|
2016-08-19 00:35:30 +08:00
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
2018-09-14 20:30:09 +08:00
|
|
|
#ifdef PKG_USING_GUIENGINE
|
|
|
|
#include <rtgui/driver.h>
|
|
|
|
#endif
|
|
|
|
|
2016-08-19 00:35:30 +08:00
|
|
|
#include "stm32f4xx.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "usart.h"
|
2016-08-22 01:03:17 +08:00
|
|
|
#include "stm32f4xx_hal.h"
|
2016-08-19 00:35:30 +08:00
|
|
|
|
2018-09-14 20:30:09 +08:00
|
|
|
|
2016-08-22 15:59:53 +08:00
|
|
|
void _init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-19 00:35:30 +08:00
|
|
|
/**
|
2016-08-22 01:03:17 +08:00
|
|
|
* @brief This function is executed in case of error occurrence.
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
|
|
|
void Error_Handler(void)
|
2016-08-19 00:35:30 +08:00
|
|
|
{
|
2016-08-22 01:03:17 +08:00
|
|
|
/* USER CODE BEGIN Error_Handler */
|
|
|
|
/* User can add his own implementation to report the HAL error return state */
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
/* USER CODE END Error_Handler */
|
2016-08-19 00:35:30 +08:00
|
|
|
}
|
|
|
|
|
2016-08-22 01:03:17 +08:00
|
|
|
/** System Clock Configuration
|
|
|
|
*/
|
|
|
|
void SystemClock_Config(void)
|
2016-08-19 00:35:30 +08:00
|
|
|
{
|
|
|
|
|
2016-08-22 01:03:17 +08:00
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
|
|
|
|
|
|
|
|
__HAL_RCC_PWR_CLK_ENABLE();
|
|
|
|
|
|
|
|
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
|
|
|
|
|
|
|
|
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 = 8;
|
|
|
|
RCC_OscInitStruct.PLL.PLLN = 336;
|
|
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
|
|
RCC_OscInitStruct.PLL.PLLQ = 7;
|
|
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LTDC;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIN = 260;
|
|
|
|
PeriphClkInitStruct.PLLSAI.PLLSAIR = 2;
|
|
|
|
PeriphClkInitStruct.PLLSAIDivR = RCC_PLLSAIDIVR_2;
|
|
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
|
|
{
|
|
|
|
Error_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
|
|
|
|
|
|
|
|
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
|
|
|
|
|
|
|
|
/* SysTick_IRQn interrupt configuration */
|
|
|
|
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
2016-08-19 00:35:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the timer interrupt service routine.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void SysTick_Handler(void)
|
|
|
|
{
|
|
|
|
/* enter interrupt */
|
|
|
|
rt_interrupt_enter();
|
2016-08-22 01:03:17 +08:00
|
|
|
/* tick for HAL Library */
|
|
|
|
HAL_IncTick();
|
2016-08-19 00:35:30 +08:00
|
|
|
rt_tick_increase();
|
|
|
|
|
|
|
|
/* leave interrupt */
|
|
|
|
rt_interrupt_leave();
|
|
|
|
}
|
|
|
|
|
2016-08-22 01:03:17 +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);
|
|
|
|
}
|
|
|
|
|
2016-08-19 00:35:30 +08:00
|
|
|
/**
|
|
|
|
* This function will initial STM32 board.
|
|
|
|
*/
|
|
|
|
void rt_hw_board_init()
|
|
|
|
{
|
2018-09-15 16:22:54 +08:00
|
|
|
#ifdef PKG_USING_GUIENGINE
|
|
|
|
rt_device_t lcd;
|
|
|
|
#endif
|
|
|
|
|
2016-08-22 01:03:17 +08:00
|
|
|
HAL_Init();
|
2016-08-19 00:35:30 +08:00
|
|
|
|
2016-08-22 01:03:17 +08:00
|
|
|
SystemClock_Config();
|
2016-08-19 00:35:30 +08:00
|
|
|
|
2016-08-20 18:27:07 +08:00
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
|
|
|
rt_components_board_init();
|
|
|
|
#else
|
2016-08-19 00:35:30 +08:00
|
|
|
stm32_hw_usart_init();
|
2016-08-20 18:27:07 +08:00
|
|
|
#endif
|
2018-09-14 20:30:09 +08:00
|
|
|
|
2016-08-19 00:35:30 +08:00
|
|
|
#ifdef RT_USING_CONSOLE
|
|
|
|
rt_console_set_device(CONSOLE_DEVICE);
|
|
|
|
#endif
|
2018-09-14 20:30:09 +08:00
|
|
|
|
2018-09-15 16:22:54 +08:00
|
|
|
#ifdef PKG_USING_GUIENGINE
|
|
|
|
lcd = rt_device_find("lcd");
|
2018-09-14 20:30:09 +08:00
|
|
|
rtgui_graphic_set_device(lcd);
|
|
|
|
#endif
|
|
|
|
|
2016-08-19 00:35:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|