Files
ETH_TCP_Demo/board/stm32f407ve/board.c
2026-03-09 15:34:18 +08:00

133 lines
3.4 KiB
C

/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-10-23 RealThread first version
*/
#include "board.h"
#include <rtthread.h>
#include "stm32f4xx_hal.h"
/* Forward declaration */
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth);
/* System Clock Configuration */
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Configure the main internal regulator output voltage
*/
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
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 = 336;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 7;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
while (1);
}
/** Initializes the CPU, AHB and APB buses 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;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
while (1);
}
}
UART_HandleTypeDef huart1;
I2C_HandleTypeDef hi2c1;
/* UART MSP初始化和反初始化已移至硬件抽象层实现 */
/* I2C MSP初始化和反初始化已移至硬件抽象层实现 */
/* Ethernet MSP初始化已移至硬件抽象层实现 */
/**
* This is the timer interrupt service routine.
*
*/
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();
HAL_IncTick();
rt_tick_increase();
/* leave interrupt */
rt_interrupt_leave();
}
/**
* This function will initial STM32 board.
*/
void rt_hw_board_init(void)
{
/* Use SysTick as time base source and configure 1ms tick (default is 1000Hz) */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Heap initialization */
#if defined(RT_USING_HEAP)
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
/* Pin driver initialization is handled by HAL_Init and MSP */
/* Console initialization (if using rt_kprintf) */
/* Note: You need to implement uart init and rt_hw_console_output if you want rt_kprintf */
}
/**
* Console Output
*/
#include "hal.h"
void rt_hw_console_output(const char *str)
{
/* 使用硬件抽象层的串口操作 */
rt_size_t i = 0, size = 0;
char a = '\r';
const hal_ops_t *ops = hal_get_ops();
size = rt_strlen(str);
for (i = 0; i < size; i++)
{
if (*(str + i) == '\n')
{
if (ops && ops->uart) {
ops->uart->send((uint8_t *)&a, 1);
}
}
if (ops && ops->uart) {
ops->uart->send((uint8_t *)(str + i), 1);
}
}
}