准备驱动移植适配Rust
This commit is contained in:
@ -2,21 +2,23 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : stm32f407vet6_board.c
|
||||
* @brief : STM32F407VET6 board configuration implementation
|
||||
* @brief : STM32F407VET6 板卡配置实现
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "bsp_board.h"
|
||||
#include "bsp_config.h"
|
||||
#include "bsp_eth.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
#include "hal_spi.h"
|
||||
#include "hal_eth.h"
|
||||
|
||||
/**
|
||||
* @brief Default LED initialization function
|
||||
* @param config: LED configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 LED 初始化函数
|
||||
* @param config: LED 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_led_init(const void* config) {
|
||||
const bsp_led_config_t* led_config = (const bsp_led_config_t*)config;
|
||||
@ -31,9 +33,9 @@ static hal_ret_t default_led_init(const void* config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default button initialization function
|
||||
* @param config: Button configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认按键初始化函数
|
||||
* @param config: 按键配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_button_init(const void* config) {
|
||||
const bsp_buttons_config_t* buttons_config = (const bsp_buttons_config_t*)config;
|
||||
@ -59,9 +61,9 @@ static hal_ret_t default_button_init(const void* config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default UART initialization function
|
||||
* @param config: UART configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 UART 初始化函数
|
||||
* @param config: UART 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_uart_init(const void* config) {
|
||||
const bsp_uart_config_t* uart_config = (const bsp_uart_config_t*)config;
|
||||
@ -76,9 +78,9 @@ static hal_ret_t default_uart_init(const void* config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default SPI initialization function
|
||||
* @param config: SPI configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 SPI 初始化函数
|
||||
* @param config: SPI 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_spi_init(const void* config) {
|
||||
const bsp_spi_config_t* spi_config = (const bsp_spi_config_t*)config;
|
||||
@ -94,45 +96,48 @@ static hal_ret_t default_spi_init(const void* config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default I2C initialization function
|
||||
* @param config: I2C configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 I2C 初始化函数
|
||||
* @param config: I2C 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_i2c_init(const void* config) {
|
||||
/* TODO: Implement default I2C initialization */
|
||||
(void)config;
|
||||
/* TODO: 实现默认 I2C 初始化 */
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default CAN initialization function
|
||||
* @param config: CAN configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 CAN 初始化函数
|
||||
* @param config: CAN 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_can_init(const void* config) {
|
||||
/* TODO: Implement default CAN initialization */
|
||||
(void)config;
|
||||
/* TODO: 实现默认 CAN 初始化 */
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default ADC initialization function
|
||||
* @param config: ADC configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 ADC 初始化函数
|
||||
* @param config: ADC 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_adc_init(const void* config) {
|
||||
/* TODO: Implement default ADC initialization */
|
||||
(void)config;
|
||||
/* TODO: 实现默认 ADC 初始化 */
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Default W25QXX initialization function
|
||||
* @param config: W25QXX configuration structure
|
||||
* @retval HAL status code
|
||||
* @brief 默认 W25QXX 初始化函数
|
||||
* @param config: W25QXX 配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_w25qxx_init(const void* config) {
|
||||
const bsp_w25qxx_config_t* w25qxx_config = (const bsp_w25qxx_config_t*)config;
|
||||
hal_ret_t status = HAL_RET_OK;
|
||||
|
||||
/* Initialize CS pin */
|
||||
/* 初始化 CS 引脚 */
|
||||
hal_gpio_config_t gpio_config = {
|
||||
.port = w25qxx_config->cs_port,
|
||||
.pin = w25qxx_config->cs_pin,
|
||||
@ -145,21 +150,31 @@ static hal_ret_t default_w25qxx_init(const void* config) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Deselect chip initially */
|
||||
/* 初始时取消选择芯片 */
|
||||
status = hal_gpio_write_pin(w25qxx_config->cs_port, w25qxx_config->cs_pin, HAL_GPIO_PIN_SET);
|
||||
if (status != HAL_RET_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* SPI instance is now just an index, actual SPI initialization is handled separately */
|
||||
/* SPI 实例现在只是一个索引,实际的 SPI 初始化在别处处理 */
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board button configurations
|
||||
* @brief 默认以太网初始化函数
|
||||
* @param config: 以太网配置结构体
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t default_eth_init(const void* config) {
|
||||
const bsp_eth_config_t* eth_config = (const bsp_eth_config_t*)config;
|
||||
return bsp_eth_init(eth_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 板卡按键配置
|
||||
*/
|
||||
static const bsp_button_config_t stm32f407vet6_buttons[] = {
|
||||
/* KEY0 - PE4, active low */
|
||||
/* KEY0 - PE4, 低电平有效 */
|
||||
{
|
||||
.port = HAL_GPIO_PORT_E,
|
||||
.pin = HAL_GPIO_PIN_4,
|
||||
@ -168,7 +183,7 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
|
||||
.pull = HAL_GPIO_PULL_UP,
|
||||
.active_high = 0
|
||||
},
|
||||
/* KEY1 - PE3, active low */
|
||||
/* KEY1 - PE3, 低电平有效 */
|
||||
{
|
||||
.port = HAL_GPIO_PORT_E,
|
||||
.pin = HAL_GPIO_PIN_3,
|
||||
@ -177,7 +192,7 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
|
||||
.pull = HAL_GPIO_PULL_UP,
|
||||
.active_high = 0
|
||||
},
|
||||
/* WKUP - PA0, active high */
|
||||
/* WKUP - PA0, 高电平有效 */
|
||||
{
|
||||
.port = HAL_GPIO_PORT_A,
|
||||
.pin = HAL_GPIO_PIN_0,
|
||||
@ -189,7 +204,7 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 buttons configuration
|
||||
* @brief STM32F407VET6 按键配置
|
||||
*/
|
||||
static const bsp_buttons_config_t stm32f407vet6_buttons_config = {
|
||||
.enable = 1,
|
||||
@ -198,7 +213,7 @@ static const bsp_buttons_config_t stm32f407vet6_buttons_config = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board UART configurations
|
||||
* @brief STM32F407VET6 板卡 UART 配置
|
||||
*/
|
||||
static const bsp_uart_config_t stm32f407vet6_uarts[] = {
|
||||
/* USART1 - PA9(TX), PA10(RX) */
|
||||
@ -217,7 +232,7 @@ static const bsp_uart_config_t stm32f407vet6_uarts[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board SPI configurations
|
||||
* @brief STM32F407VET6 板卡 SPI 配置
|
||||
*/
|
||||
static const bsp_spi_config_t stm32f407vet6_spis[] = {
|
||||
/* SPI1 - PA5(SCK), PA6(MISO), PA7(MOSI) */
|
||||
@ -239,12 +254,12 @@ static const bsp_spi_config_t stm32f407vet6_spis[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board I2C configurations
|
||||
* @brief STM32F407VET6 板卡 I2C 配置
|
||||
*/
|
||||
static const bsp_i2c_config_t stm32f407vet6_i2cs[] = {
|
||||
/* I2C1 - PB6(SCL), PB7(SDA) */
|
||||
{
|
||||
.enable = 0, /* Disabled by default */
|
||||
.enable = 0, /* 默认禁用 */
|
||||
.instance = HAL_I2C_INSTANCE_1,
|
||||
.speed = HAL_I2C_SPEED_STANDARD,
|
||||
.address_mode = HAL_I2C_ADDRESS_7BIT,
|
||||
@ -258,12 +273,12 @@ static const bsp_i2c_config_t stm32f407vet6_i2cs[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board CAN configurations
|
||||
* @brief STM32F407VET6 板卡 CAN 配置
|
||||
*/
|
||||
static const bsp_can_config_t stm32f407vet6_cans[] = {
|
||||
/* CAN1 - PA11(RX), PA12(TX) */
|
||||
{
|
||||
.enable = 0, /* Disabled by default */
|
||||
.enable = 0, /* 默认禁用 */
|
||||
.instance = HAL_CAN_INSTANCE_1,
|
||||
.mode = HAL_CAN_MODE_NORMAL,
|
||||
.prescaler = 6, /* 168MHz / 6 = 28MHz */
|
||||
@ -278,12 +293,12 @@ static const bsp_can_config_t stm32f407vet6_cans[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board ADC channel configurations
|
||||
* @brief STM32F407VET6 板卡 ADC 通道配置
|
||||
*/
|
||||
static const bsp_adc_channel_config_t stm32f407vet6_adc_channels[] = {
|
||||
/* ADC1 Channel 0 - PA0 */
|
||||
{
|
||||
.enable = 0, /* Disabled by default */
|
||||
.enable = 0, /* 默认禁用 */
|
||||
.channel = HAL_ADC_CHANNEL_0,
|
||||
.sampletime = HAL_ADC_SAMPLETIME_56CYCLES,
|
||||
.rank = 1
|
||||
@ -291,12 +306,12 @@ static const bsp_adc_channel_config_t stm32f407vet6_adc_channels[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board ADC configurations
|
||||
* @brief STM32F407VET6 板卡 ADC 配置
|
||||
*/
|
||||
static const bsp_adc_config_t stm32f407vet6_adcs[] = {
|
||||
/* ADC1 */
|
||||
{
|
||||
.enable = 0, /* Disabled by default */
|
||||
.enable = 0, /* 默认禁用 */
|
||||
.instance = HAL_ADC_INSTANCE_1,
|
||||
.resolution = HAL_ADC_RESOLUTION_12B,
|
||||
.scan_conversion_mode = 0,
|
||||
@ -307,7 +322,7 @@ static const bsp_adc_config_t stm32f407vet6_adcs[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board LED configurations
|
||||
* @brief STM32F407VET6 板卡 LED 配置
|
||||
*/
|
||||
static const bsp_led_config_t stm32f407vet6_leds[] = {
|
||||
/* LED0 - PA6 */
|
||||
@ -331,19 +346,19 @@ static const bsp_led_config_t stm32f407vet6_leds[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board configuration
|
||||
* @brief STM32F407VET6 板卡配置
|
||||
*/
|
||||
const bsp_board_config_t stm32f407vet6_board_config = {
|
||||
.version = BSP_CONFIG_VERSION,
|
||||
.name = "STM32F407VET6",
|
||||
.description = "STM32F407VET6 Development Board",
|
||||
.description = "STM32F407VET6 开发板",
|
||||
.id = {
|
||||
.vendor_id = 0x0483, /* STMicroelectronics */
|
||||
.product_id = 0x374B, /* STM32F4 Series */
|
||||
.serial_number = 0x00000001 /* Default serial number */
|
||||
.product_id = 0x374B, /* STM32F4 系列 */
|
||||
.serial_number = 0x00000001 /* 默认序列号 */
|
||||
},
|
||||
|
||||
/* Board features */
|
||||
/* 板卡特性 */
|
||||
.features = (
|
||||
BSP_BOARD_FEATURE_LED |
|
||||
BSP_BOARD_FEATURE_BUTTON |
|
||||
@ -352,21 +367,22 @@ const bsp_board_config_t stm32f407vet6_board_config = {
|
||||
BSP_BOARD_FEATURE_I2C |
|
||||
BSP_BOARD_FEATURE_CAN |
|
||||
BSP_BOARD_FEATURE_ADC |
|
||||
BSP_BOARD_FEATURE_W25QXX
|
||||
BSP_BOARD_FEATURE_W25QXX |
|
||||
BSP_BOARD_FEATURE_ETH
|
||||
),
|
||||
|
||||
/* Hardware information */
|
||||
/* 硬件信息 */
|
||||
.hw_info = {
|
||||
.clock_speed = 168000000, /* 168 MHz */
|
||||
.flash_size = 512 * 1024, /* 512 KB */
|
||||
.ram_size = 192 * 1024, /* 192 KB */
|
||||
.eeprom_size = 0, /* No internal EEPROM */
|
||||
.eeprom_size = 0, /* 无内部 EEPROM */
|
||||
.sram_size = 64 * 1024, /* 64 KB SRAM */
|
||||
.cpu_core = 0x0F, /* Cortex-M4 */
|
||||
.cpu_bits = 32 /* 32-bit CPU */
|
||||
.cpu_bits = 32 /* 32位 CPU */
|
||||
},
|
||||
|
||||
/* Peripheral configurations */
|
||||
/* 外设配置 */
|
||||
.leds = {
|
||||
.enable = 1,
|
||||
.count = sizeof(stm32f407vet6_leds) / sizeof(bsp_led_config_t),
|
||||
@ -377,33 +393,45 @@ const bsp_board_config_t stm32f407vet6_board_config = {
|
||||
.enable = 1,
|
||||
.cs_port = HAL_GPIO_PORT_B,
|
||||
.cs_pin = HAL_GPIO_PIN_0,
|
||||
.spi_instance = 0 /* Use SPI instance 0 */
|
||||
.spi_instance = 0 /* 使用 SPI 实例 0 */
|
||||
},
|
||||
.eth = {
|
||||
.enable = 1,
|
||||
.instance = HAL_ETH_INSTANCE_1,
|
||||
.mode = HAL_ETH_MODE_FULLDUPLEX,
|
||||
.speed = HAL_ETH_SPEED_100MBPS,
|
||||
.phy_addr = LAN8720_PHY_ADDR,
|
||||
.mac_addr = {
|
||||
.byte = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
|
||||
},
|
||||
.auto_negotiation = 1,
|
||||
.interrupt_enable = 1
|
||||
},
|
||||
|
||||
/* Peripheral arrays */
|
||||
/* 外设数组 */
|
||||
.periphs = {
|
||||
/* UART configurations */
|
||||
/* UART 配置 */
|
||||
.uart_count = 1,
|
||||
.uarts = stm32f407vet6_uarts,
|
||||
|
||||
/* SPI configurations */
|
||||
/* SPI 配置 */
|
||||
.spi_count = 1,
|
||||
.spis = stm32f407vet6_spis,
|
||||
|
||||
/* I2C configurations */
|
||||
/* I2C 配置 */
|
||||
.i2c_count = 1,
|
||||
.i2cs = stm32f407vet6_i2cs,
|
||||
|
||||
/* CAN configurations */
|
||||
/* CAN 配置 */
|
||||
.can_count = 1,
|
||||
.cans = stm32f407vet6_cans,
|
||||
|
||||
/* ADC configurations */
|
||||
/* ADC 配置 */
|
||||
.adc_count = 1,
|
||||
.adcs = stm32f407vet6_adcs
|
||||
},
|
||||
|
||||
/* Initialization function pointers */
|
||||
/* 初始化函数指针 */
|
||||
.init_funcs = {
|
||||
.led_init = default_led_init,
|
||||
.button_init = default_button_init,
|
||||
@ -412,31 +440,32 @@ const bsp_board_config_t stm32f407vet6_board_config = {
|
||||
.i2c_init = default_i2c_init,
|
||||
.can_init = default_can_init,
|
||||
.adc_init = default_adc_init,
|
||||
.w25qxx_init = default_w25qxx_init
|
||||
.w25qxx_init = default_w25qxx_init,
|
||||
.eth_init = default_eth_init
|
||||
},
|
||||
|
||||
/* Additional board-specific configuration */
|
||||
/* 额外的板卡特定配置 */
|
||||
.custom_config = NULL,
|
||||
.custom_config_size = 0,
|
||||
|
||||
/* Board revision information */
|
||||
/* 板卡版本信息 */
|
||||
.major_rev = 1,
|
||||
.minor_rev = 0,
|
||||
.patch_rev = 0,
|
||||
.revision_desc = "Original release"
|
||||
.revision_desc = "初始版本"
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
* @retval Board name string
|
||||
* @brief 获取板卡名称
|
||||
* @retval 板卡名称字符串
|
||||
*/
|
||||
const char* bsp_board_get_name(void) {
|
||||
return stm32f407vet6_board_config.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
* @brief 获取板卡配置
|
||||
* @retval 指向板卡配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void) {
|
||||
return &stm32f407vet6_board_config;
|
||||
|
||||
Reference in New Issue
Block a user