准备驱动移植适配Rust
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_board_manager.c
|
||||
* @brief : Board support package manager source file
|
||||
* @brief : 板级支持包管理器源文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -14,7 +14,7 @@
|
||||
extern const bsp_board_config_t stm32f407vet6_board_config;
|
||||
|
||||
/**
|
||||
* @brief List of supported board configurations
|
||||
* @brief 支持的板卡配置列表
|
||||
*/
|
||||
static const bsp_board_config_t* supported_boards[] = {
|
||||
&stm32f407vet6_board_config,
|
||||
@ -22,22 +22,22 @@ static const bsp_board_config_t* supported_boards[] = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Current board configuration index
|
||||
* @brief 当前板卡配置索引
|
||||
*/
|
||||
static uint8_t current_board_index = 0;
|
||||
|
||||
/**
|
||||
* @brief Get number of supported boards
|
||||
* @retval Number of supported boards
|
||||
* @brief 获取支持的板卡数量
|
||||
* @retval 支持的板卡数量
|
||||
*/
|
||||
uint8_t bsp_board_get_count(void) {
|
||||
return sizeof(supported_boards) / sizeof(supported_boards[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval Pointer to board configuration structure, NULL if invalid index
|
||||
* @brief 通过索引获取板卡配置
|
||||
* @param index: 板卡配置索引
|
||||
* @retval 指向板卡配置结构体的指针,无效索引返回 NULL
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_index(uint8_t index) {
|
||||
if (index < bsp_board_get_count()) {
|
||||
@ -47,9 +47,9 @@ const bsp_board_config_t* bsp_board_get_by_index(uint8_t index) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval Pointer to board configuration structure, NULL if not found
|
||||
* @brief 通过名称获取板卡配置
|
||||
* @param name: 板卡名称字符串
|
||||
* @retval 指向板卡配置结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_name(const char* name) {
|
||||
for (uint8_t i = 0; i < bsp_board_get_count(); i++) {
|
||||
@ -62,9 +62,9 @@ const bsp_board_config_t* bsp_board_get_by_name(const char* name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval HAL status code
|
||||
* @brief 通过索引设置当前板卡配置
|
||||
* @param index: 板卡配置索引
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_board_set_by_index(uint8_t index) {
|
||||
if (index < bsp_board_get_count()) {
|
||||
@ -75,9 +75,9 @@ hal_ret_t bsp_board_set_by_index(uint8_t index) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval HAL status code
|
||||
* @brief 通过名称设置当前板卡配置
|
||||
* @param name: 板卡名称字符串
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_board_set_by_name(const char* name) {
|
||||
if (name == NULL) {
|
||||
@ -95,16 +95,16 @@ hal_ret_t bsp_board_set_by_name(const char* name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to current board configuration structure
|
||||
* @brief 获取当前板卡配置
|
||||
* @retval 指向当前板卡配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void) {
|
||||
return supported_boards[current_board_index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current board index
|
||||
* @retval Current board index
|
||||
* @brief 获取当前板卡索引
|
||||
* @retval 当前板卡索引
|
||||
*/
|
||||
uint8_t bsp_board_get_current_index(void) {
|
||||
return current_board_index;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_config.c
|
||||
* @brief : Board support package configuration file source
|
||||
* @brief : 板级支持包配置文件源文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -14,7 +14,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
/**
|
||||
* @brief Configuration storage entry
|
||||
* @brief 配置存储条目
|
||||
*/
|
||||
typedef struct bsp_config_storage_entry {
|
||||
char section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH];
|
||||
@ -24,7 +24,7 @@ typedef struct bsp_config_storage_entry {
|
||||
} bsp_config_storage_entry_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration storage
|
||||
* @brief 配置存储
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_config_storage_entry_t* entries;
|
||||
@ -33,7 +33,7 @@ typedef struct {
|
||||
} bsp_config_storage_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration storage instance
|
||||
* @brief 配置存储实例
|
||||
*/
|
||||
static bsp_config_storage_t bsp_config_storage = {
|
||||
.entries = NULL,
|
||||
@ -42,9 +42,9 @@ static bsp_config_storage_t bsp_config_storage = {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Trim whitespace from a string
|
||||
* @param str: String to trim
|
||||
* @return Trimmed string
|
||||
* @brief 去除字符串中的空白字符
|
||||
* @param str: 要处理的字符串
|
||||
* @return 处理后的字符串
|
||||
*/
|
||||
static char* bsp_config_trim(char* str) {
|
||||
char* end;
|
||||
@ -71,10 +71,10 @@ static char* bsp_config_trim(char* str) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Open configuration file
|
||||
* @param filename: Configuration file name
|
||||
* @param parser: Parser context
|
||||
* @retval HAL status code
|
||||
* @brief 打开配置文件
|
||||
* @param filename: 配置文件名称
|
||||
* @param parser: 解析器上下文
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_file_open(const char* filename, bsp_config_parser_t* parser) {
|
||||
if (filename == NULL || parser == NULL) {
|
||||
@ -95,9 +95,9 @@ static hal_ret_t bsp_config_file_open(const char* filename, bsp_config_parser_t*
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Close configuration file
|
||||
* @param parser: Parser context
|
||||
* @retval HAL status code
|
||||
* @brief 关闭配置文件
|
||||
* @param parser: 解析器上下文
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_file_close(bsp_config_parser_t* parser) {
|
||||
if (parser == NULL || !parser->initialized) {
|
||||
@ -115,10 +115,10 @@ static hal_ret_t bsp_config_file_close(bsp_config_parser_t* parser) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read a configuration entry from file
|
||||
* @param parser: Parser context
|
||||
* @param entry: Configuration entry
|
||||
* @retval HAL status code
|
||||
* @brief 从文件读取配置条目
|
||||
* @param parser: 解析器上下文
|
||||
* @param entry: 配置条目
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_file_read_entry(bsp_config_parser_t* parser, bsp_config_entry_t* entry) {
|
||||
if (parser == NULL || entry == NULL || !parser->initialized) {
|
||||
@ -169,10 +169,10 @@ static hal_ret_t bsp_config_file_read_entry(bsp_config_parser_t* parser, bsp_con
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse integer value
|
||||
* @param value: String value to parse
|
||||
* @param result: Pointer to store result
|
||||
* @retval HAL status code
|
||||
* @brief 解析整数值
|
||||
* @param value: 要解析的字符串值
|
||||
* @param result: 存储结果的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_parse_int(const char* value, int* result) {
|
||||
if (value == NULL || result == NULL) {
|
||||
@ -192,10 +192,10 @@ static hal_ret_t bsp_config_parse_int(const char* value, int* result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse unsigned integer value
|
||||
* @param value: String value to parse
|
||||
* @param result: Pointer to store result
|
||||
* @retval HAL status code
|
||||
* @brief 解析无符号整数值
|
||||
* @param value: 要解析的字符串值
|
||||
* @param result: 存储结果的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_parse_uint(const char* value, uint32_t* result) {
|
||||
if (value == NULL || result == NULL) {
|
||||
@ -215,10 +215,10 @@ static hal_ret_t bsp_config_parse_uint(const char* value, uint32_t* result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse boolean value
|
||||
* @param value: String value to parse
|
||||
* @param result: Pointer to store result
|
||||
* @retval HAL status code
|
||||
* @brief 解析布尔值
|
||||
* @param value: 要解析的字符串值
|
||||
* @param result: 存储结果的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_parse_bool(const char* value, uint8_t* result) {
|
||||
if (value == NULL || result == NULL) {
|
||||
@ -241,11 +241,11 @@ static hal_ret_t bsp_config_parse_bool(const char* value, uint8_t* result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse string value
|
||||
* @param value: String value to parse
|
||||
* @param result: Pointer to store result
|
||||
* @param max_length: Maximum length of result buffer
|
||||
* @retval HAL status code
|
||||
* @brief 解析字符串值
|
||||
* @param value: 要解析的字符串值
|
||||
* @param result: 存储结果的指针
|
||||
* @param max_length: 结果缓冲区的最大长度
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_parse_string(const char* value, char* result, size_t max_length) {
|
||||
if (value == NULL || result == NULL) {
|
||||
@ -259,11 +259,11 @@ static hal_ret_t bsp_config_parse_string(const char* value, char* result, size_t
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a configuration entry to storage
|
||||
* @param section: Section name
|
||||
* @param key: Key name
|
||||
* @param value: Value
|
||||
* @retval HAL status code
|
||||
* @brief 添加配置条目到存储
|
||||
* @param section: 节名称
|
||||
* @param key: 键名称
|
||||
* @param value: 值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
static hal_ret_t bsp_config_storage_add(const char* section, const char* key, const char* value) {
|
||||
// Check if entry already exists
|
||||
@ -309,7 +309,7 @@ static hal_ret_t bsp_config_storage_add(const char* section, const char* key, co
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clear configuration storage
|
||||
* @brief 清空配置存储
|
||||
*/
|
||||
static void bsp_config_storage_clear(void) {
|
||||
bsp_config_storage_entry_t* entry = bsp_config_storage.entries;
|
||||
@ -324,8 +324,8 @@ static void bsp_config_storage_clear(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
* @brief 初始化 BSP 配置系统
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_init(void) {
|
||||
if (bsp_config_storage.initialized) {
|
||||
@ -339,8 +339,8 @@ hal_ret_t bsp_config_init(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize BSP configuration system
|
||||
* @retval HAL status code
|
||||
* @brief 反初始化 BSP 配置系统
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_deinit(void) {
|
||||
if (!bsp_config_storage.initialized) {
|
||||
@ -354,9 +354,9 @@ hal_ret_t bsp_config_deinit(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load BSP configuration from file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
* @brief 从文件加载 BSP 配置
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_load(const char* filename) {
|
||||
if (!bsp_config_storage.initialized) {
|
||||
@ -395,9 +395,9 @@ hal_ret_t bsp_config_load(const char* filename) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Save BSP configuration to file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
* @brief 保存 BSP 配置到文件
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_save(const char* filename) {
|
||||
if (!bsp_config_storage.initialized || bsp_config_storage.entry_count == 0) {
|
||||
@ -432,12 +432,12 @@ hal_ret_t bsp_config_save(const char* filename) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get configuration value
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store value
|
||||
* @param max_length: Maximum length of value buffer
|
||||
* @retval HAL status code
|
||||
* @brief 获取配置值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储值的指针
|
||||
* @param max_length: 值缓冲区的最大长度
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_get_value(const char* section, const char* key, char* value, size_t max_length) {
|
||||
if (!bsp_config_storage.initialized || section == NULL || key == NULL || value == NULL) {
|
||||
@ -458,11 +458,11 @@ hal_ret_t bsp_config_get_value(const char* section, const char* key, char* value
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set configuration value
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Configuration value
|
||||
* @retval HAL status code
|
||||
* @brief 设置配置值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 配置值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_set_value(const char* section, const char* key, const char* value) {
|
||||
if (!bsp_config_storage.initialized || section == NULL || key == NULL || value == NULL) {
|
||||
@ -473,11 +473,11 @@ hal_ret_t bsp_config_set_value(const char* section, const char* key, const char*
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store integer value
|
||||
* @retval HAL status code
|
||||
* @brief 获取配置值作为整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储整数值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_get_int(const char* section, const char* key, int* value) {
|
||||
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
|
||||
@ -490,11 +490,11 @@ hal_ret_t bsp_config_get_int(const char* section, const char* key, int* value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Integer value
|
||||
* @retval HAL status code
|
||||
* @brief 设置配置值作为整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 整数值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_set_int(const char* section, const char* key, int value) {
|
||||
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
|
||||
@ -503,11 +503,11 @@ hal_ret_t bsp_config_set_int(const char* section, const char* key, int value) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as unsigned integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store unsigned integer value
|
||||
* @retval HAL status code
|
||||
* @brief 获取配置值作为无符号整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储无符号整数值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* value) {
|
||||
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
|
||||
@ -520,11 +520,11 @@ hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* va
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as unsigned integer
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Unsigned integer value
|
||||
* @retval HAL status code
|
||||
* @brief 设置配置值作为无符号整数
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 无符号整数值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t value) {
|
||||
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
|
||||
@ -533,11 +533,11 @@ hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t val
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get configuration value as boolean
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Pointer to store boolean value
|
||||
* @retval HAL status code
|
||||
* @brief 获取配置值作为布尔值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 存储布尔值的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* value) {
|
||||
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
|
||||
@ -550,20 +550,20 @@ hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* val
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set configuration value as boolean
|
||||
* @param section: Configuration section name
|
||||
* @param key: Configuration key name
|
||||
* @param value: Boolean value
|
||||
* @retval HAL status code
|
||||
* @brief 设置配置值作为布尔值
|
||||
* @param section: 配置节名称
|
||||
* @param key: 配置键名称
|
||||
* @param value: 布尔值
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_set_bool(const char* section, const char* key, uint8_t value) {
|
||||
return bsp_config_set_value(section, key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Parse BSP modules from configuration
|
||||
* @param config: Pointer to BSP board configuration structure to fill
|
||||
* @retval HAL status code
|
||||
* @brief 从配置解析 BSP 模块
|
||||
* @param config: 指向要填充的 BSP 板卡配置结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_config_parse_modules(bsp_board_config_t* config) {
|
||||
if (config == NULL) {
|
||||
@ -578,9 +578,9 @@ hal_ret_t bsp_config_parse_modules(bsp_board_config_t* config) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP from configuration file
|
||||
* @param filename: Configuration file name
|
||||
* @retval HAL status code
|
||||
* @brief 从配置文件初始化 BSP
|
||||
* @param filename: 配置文件名称
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_init_from_config(const char* filename) {
|
||||
// Load configuration file
|
||||
|
||||
353
BSP/Src/bsp_eth.c
Normal file
353
BSP/Src/bsp_eth.c
Normal file
@ -0,0 +1,353 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_eth.c
|
||||
* @brief : Board support package Ethernet (LAN8720) driver implementation
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "bsp_eth.h"
|
||||
|
||||
/**
|
||||
* @brief Ethernet configuration
|
||||
*/
|
||||
static bsp_eth_config_t eth_config;
|
||||
static uint8_t eth_initialized = 0;
|
||||
|
||||
/**
|
||||
* @brief Initialize Ethernet (LAN8720) module
|
||||
* @param config: Pointer to Ethernet configuration structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_init(const bsp_eth_config_t* config)
|
||||
{
|
||||
if (!config) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (eth_initialized) {
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/* Store configuration */
|
||||
eth_config = *config;
|
||||
|
||||
/* Convert to HAL configuration */
|
||||
hal_eth_config_t hal_config;
|
||||
hal_config.enable = config->enable;
|
||||
hal_config.instance = config->instance;
|
||||
hal_config.mode = config->mode;
|
||||
hal_config.speed = config->speed;
|
||||
hal_config.phy_addr = config->phy_addr;
|
||||
hal_config.mac_addr = config->mac_addr;
|
||||
hal_config.auto_negotiation = config->auto_negotiation;
|
||||
hal_config.interrupt_enable = config->interrupt_enable;
|
||||
|
||||
/* Initialize HAL Ethernet */
|
||||
if (hal_eth_init(&hal_config) != HAL_RET_OK) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
/* Detect LAN8720 PHY */
|
||||
uint8_t detected;
|
||||
if (bsp_eth_detect_phy(&detected) != HAL_RET_OK) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (!detected) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
/* Configure PHY */
|
||||
if (bsp_eth_configure_phy(config->mode, config->speed, config->auto_negotiation) != HAL_RET_OK) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
eth_initialized = 1;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Deinitialize Ethernet (LAN8720) module
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_deinit(void)
|
||||
{
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
if (hal_eth_deinit(eth_config.instance) != HAL_RET_OK) {
|
||||
return HAL_RET_DEINIT_ERROR;
|
||||
}
|
||||
|
||||
eth_initialized = 0;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Ethernet (LAN8720) status
|
||||
* @param status: Pointer to Ethernet status structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_get_status(bsp_eth_status_t* status)
|
||||
{
|
||||
if (!status) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
/* Get HAL Ethernet status */
|
||||
hal_eth_status_t hal_status;
|
||||
if (hal_eth_get_status(eth_config.instance, &hal_status) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
/* Copy status */
|
||||
status->link_up = hal_status.link_up;
|
||||
status->duplex = hal_status.duplex;
|
||||
status->speed = hal_status.speed;
|
||||
status->rx_packets = hal_status.rx_packets;
|
||||
status->tx_packets = hal_status.tx_packets;
|
||||
status->rx_errors = hal_status.rx_errors;
|
||||
status->tx_errors = hal_status.tx_errors;
|
||||
|
||||
/* Get PHY identifiers */
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_PID1, &status->phy_id1) != HAL_RET_OK) {
|
||||
status->phy_id1 = 0;
|
||||
}
|
||||
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_PID2, &status->phy_id2) != HAL_RET_OK) {
|
||||
status->phy_id2 = 0;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set Ethernet MAC address
|
||||
* @param mac_addr: Pointer to MAC address structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_set_mac_addr(const hal_eth_mac_addr_t* mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_set_mac_addr(eth_config.instance, mac_addr) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
eth_config.mac_addr = *mac_addr;
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get Ethernet MAC address
|
||||
* @param mac_addr: Pointer to MAC address structure
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_get_mac_addr(hal_eth_mac_addr_t* mac_addr)
|
||||
{
|
||||
if (!mac_addr) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_get_mac_addr(eth_config.instance, mac_addr) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check Ethernet link status
|
||||
* @param link_up: Pointer to store link up status
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_check_link(uint8_t* link_up)
|
||||
{
|
||||
if (!link_up) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_check_link(eth_config.instance, link_up) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset Ethernet PHY (LAN8720)
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_reset_phy(void)
|
||||
{
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_reset_phy(eth_config.instance, eth_config.phy_addr) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read LAN8720 PHY register
|
||||
* @param reg_addr: Register address
|
||||
* @param value: Pointer to store register value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_read_phy_reg(uint16_t reg_addr, uint16_t* value)
|
||||
{
|
||||
if (!value) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_read_phy_reg(eth_config.instance, eth_config.phy_addr, reg_addr, value) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write LAN8720 PHY register
|
||||
* @param reg_addr: Register address
|
||||
* @param value: Register value
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_write_phy_reg(uint16_t reg_addr, uint16_t value)
|
||||
{
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (hal_eth_write_phy_reg(eth_config.instance, eth_config.phy_addr, reg_addr, value) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Detect LAN8720 PHY presence
|
||||
* @param detected: Pointer to store detection result
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_detect_phy(uint8_t* detected)
|
||||
{
|
||||
if (!detected) {
|
||||
return HAL_RET_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
/* Read PHY identifiers */
|
||||
uint16_t id1, id2;
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_PID1, &id1) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_PID2, &id2) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
/* Check if this is a LAN8720 PHY */
|
||||
if (id1 == LAN8720_PID1_VALUE && (id2 & 0xFFF0) == LAN8720_PID2_VALUE) {
|
||||
*detected = 1;
|
||||
} else {
|
||||
*detected = 0;
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure LAN8720 PHY
|
||||
* @param mode: Ethernet mode
|
||||
* @param speed: Ethernet speed
|
||||
* @param auto_neg: Auto-negotiation enable
|
||||
* @retval HAL status code
|
||||
*/
|
||||
hal_ret_t bsp_eth_configure_phy(hal_eth_mode_t mode, hal_eth_speed_t speed, uint8_t auto_neg)
|
||||
{
|
||||
if (!eth_initialized) {
|
||||
return HAL_RET_INIT_ERROR;
|
||||
}
|
||||
|
||||
/* Read current BCR register */
|
||||
uint16_t bcr;
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_BCR, &bcr) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
/* Clear relevant bits */
|
||||
bcr &= ~(LAN8720_BCR_AUTO_NEG_EN | LAN8720_BCR_SPEED_SELECT | LAN8720_BCR_DUPLEX_MODE);
|
||||
|
||||
if (auto_neg) {
|
||||
/* Enable auto-negotiation */
|
||||
bcr |= LAN8720_BCR_AUTO_NEG_EN;
|
||||
bcr |= LAN8720_BCR_RESTART_AN;
|
||||
} else {
|
||||
/* Manual configuration */
|
||||
if (speed == HAL_ETH_SPEED_100MBPS) {
|
||||
bcr |= LAN8720_BCR_SPEED_SELECT;
|
||||
}
|
||||
|
||||
if (mode == HAL_ETH_MODE_FULLDUPLEX) {
|
||||
bcr |= LAN8720_BCR_DUPLEX_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Write BCR register */
|
||||
if (bsp_eth_write_phy_reg(LAN8720_REG_BCR, bcr) != HAL_RET_OK) {
|
||||
return HAL_RET_ERROR;
|
||||
}
|
||||
|
||||
/* Wait for configuration to complete */
|
||||
if (auto_neg) {
|
||||
uint32_t timeout = 1000;
|
||||
uint16_t bsr;
|
||||
while (timeout--) {
|
||||
if (bsp_eth_read_phy_reg(LAN8720_REG_BSR, &bsr) == HAL_RET_OK) {
|
||||
if (bsr & LAN8720_BSR_AUTO_NEG_COMPLETE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
HAL_Delay(1);
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
return HAL_RET_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
return HAL_RET_OK;
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_init.c
|
||||
* @brief : Board support package initialization source file
|
||||
* @brief : 板级支持包初始化源文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -15,8 +15,8 @@
|
||||
#include "hal_uart.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize board support package
|
||||
* @retval HAL status code
|
||||
* @brief 初始化板级支持包
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_init(void) {
|
||||
/* Get board configuration */
|
||||
@ -137,8 +137,8 @@ hal_ret_t bsp_init(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize board GPIO using configuration
|
||||
* @retval HAL status code
|
||||
* @brief 使用配置初始化板卡 GPIO
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_gpio_init(void) {
|
||||
/* Get board configuration */
|
||||
@ -254,16 +254,16 @@ hal_ret_t bsp_gpio_init(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
* @retval Board name string
|
||||
* @brief 获取板卡名称
|
||||
* @retval 板卡名称字符串
|
||||
*/
|
||||
const char* bsp_get_board_name(void) {
|
||||
return bsp_board_get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
* @brief 获取当前板卡配置
|
||||
* @retval 指向板卡配置结构体的指针
|
||||
*/
|
||||
const bsp_board_config_t* bsp_get_board_config(void) {
|
||||
return bsp_board_get_config();
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_key.c
|
||||
* @brief : Board support package key driver implementation
|
||||
* @brief : 板级支持包按键驱动实现
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -15,7 +15,7 @@
|
||||
#include "hal_delay.h"
|
||||
|
||||
/**
|
||||
* @brief Key debounce configuration
|
||||
* @brief 按键防抖配置
|
||||
*/
|
||||
#define KEY_DEBOUNCE_COUNT 5 /* Debounce count (each update is ~10ms, so 50ms debounce) */
|
||||
#define KEY_LONG_PRESS_TIME 1000 /* Long press time in ms */
|
||||
@ -24,7 +24,7 @@
|
||||
#define KEY_UPDATE_INTERVAL 10 /* Update interval in ms */
|
||||
|
||||
/**
|
||||
* @brief Key configuration structure
|
||||
* @brief 按键配置结构体
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port;
|
||||
@ -33,7 +33,7 @@ typedef struct {
|
||||
} bsp_key_config_t;
|
||||
|
||||
/**
|
||||
* @brief Key state structure for debouncing and event detection
|
||||
* @brief 按键状态结构体,用于防抖和事件检测
|
||||
*/
|
||||
typedef struct {
|
||||
/* Debounce state */
|
||||
@ -63,12 +63,12 @@ typedef struct {
|
||||
} bsp_key_internal_state_t;
|
||||
|
||||
/**
|
||||
* @brief Key state table for debouncing and event detection
|
||||
* @brief 按键状态表,用于防抖和事件检测
|
||||
*/
|
||||
static bsp_key_internal_state_t key_state_table[BSP_KEY_ID_MAX] = {0};
|
||||
|
||||
/**
|
||||
* @brief Get current board button configuration
|
||||
* @brief 获取当前板卡按键配置
|
||||
*/
|
||||
static const bsp_button_config_t* bsp_key_get_button_config(bsp_key_id_t key_id) {
|
||||
const bsp_board_config_t* board_config = bsp_board_get_config();
|
||||
@ -79,9 +79,9 @@ static const bsp_button_config_t* bsp_key_get_button_config(bsp_key_id_t key_id)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read raw key state (without debounce)
|
||||
* @param key_id: Key ID
|
||||
* @retval Raw key state
|
||||
* @brief 读取原始按键状态(无防抖)
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 原始按键状态
|
||||
*/
|
||||
static bsp_key_state_t bsp_key_read_raw(bsp_key_id_t key_id) {
|
||||
bsp_key_state_t state;
|
||||
@ -107,8 +107,8 @@ static bsp_key_state_t bsp_key_read_raw(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get current system time in milliseconds
|
||||
* @retval Current time in ms
|
||||
* @brief 获取当前系统时间(毫秒)
|
||||
* @retval 当前时间(毫秒)
|
||||
*/
|
||||
static uint32_t bsp_key_get_time_ms(void) {
|
||||
/* Use HAL tick function */
|
||||
@ -116,7 +116,7 @@ static uint32_t bsp_key_get_time_ms(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize all keys
|
||||
* @brief 初始化所有按键
|
||||
*/
|
||||
void bsp_key_init(void) {
|
||||
uint8_t i;
|
||||
@ -162,7 +162,7 @@ void bsp_key_init(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update key state (call this function periodically, e.g. every 10ms)
|
||||
* @brief 更新按键状态(定期调用此函数,例如每 10ms)
|
||||
*/
|
||||
void bsp_key_update(void) {
|
||||
uint8_t i;
|
||||
@ -241,9 +241,9 @@ void bsp_key_update(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read debounced key state
|
||||
* @param key_id: Key ID
|
||||
* @retval Key state
|
||||
* @brief 读取防抖后的按键状态
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按键状态
|
||||
*/
|
||||
bsp_key_state_t bsp_key_read(bsp_key_id_t key_id) {
|
||||
if (key_id < BSP_KEY_ID_MAX) {
|
||||
@ -253,27 +253,27 @@ bsp_key_state_t bsp_key_read(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if key is pressed
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if pressed, 0 otherwise
|
||||
* @brief 检查按键是否按下
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按下返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_is_pressed(bsp_key_id_t key_id) {
|
||||
return (bsp_key_read(key_id) == BSP_KEY_STATE_PRESSED) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if key is released
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if released, 0 otherwise
|
||||
* @brief 检查按键是否释放
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 释放返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_is_released(bsp_key_id_t key_id) {
|
||||
return (bsp_key_read(key_id) == BSP_KEY_STATE_RELEASED) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for key press event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was pressed, 0 otherwise
|
||||
* @brief 检查按键按下事件(边沿检测)
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 按下事件返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_press_event(bsp_key_id_t key_id) {
|
||||
uint8_t event = 0;
|
||||
@ -287,9 +287,9 @@ uint8_t bsp_key_get_press_event(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for key release event (edge detection)
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was released, 0 otherwise
|
||||
* @brief 检查按键释放事件(边沿检测)
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 释放事件返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_release_event(bsp_key_id_t key_id) {
|
||||
uint8_t event = 0;
|
||||
@ -303,9 +303,9 @@ uint8_t bsp_key_get_release_event(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for key long pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was long pressed, 0 otherwise
|
||||
* @brief 检查按键长按事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 长按事件返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_long_press_event(bsp_key_id_t key_id) {
|
||||
uint8_t event = 0;
|
||||
@ -319,9 +319,9 @@ uint8_t bsp_key_get_long_press_event(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for key repeat event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key repeat event occurred, 0 otherwise
|
||||
* @brief 检查按键重复事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 重复事件返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_repeat_event(bsp_key_id_t key_id) {
|
||||
uint8_t event = 0;
|
||||
@ -335,9 +335,9 @@ uint8_t bsp_key_get_repeat_event(bsp_key_id_t key_id) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for key short pressed event
|
||||
* @param key_id: Key ID
|
||||
* @retval 1 if key was short pressed, 0 otherwise
|
||||
* @brief 检查按键短按事件
|
||||
* @param key_id: 按键 ID
|
||||
* @retval 短按事件返回 1,否则返回 0
|
||||
*/
|
||||
uint8_t bsp_key_get_short_press_event(bsp_key_id_t key_id) {
|
||||
uint8_t event = 0;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_module.c
|
||||
* @brief : Board support package module management source file
|
||||
* @brief : 板级支持包模块管理源文件
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
@ -11,13 +11,13 @@
|
||||
#include <string.h>
|
||||
|
||||
/**
|
||||
* @brief Module manager instance
|
||||
* @brief 模块管理器实例
|
||||
*/
|
||||
static bsp_module_manager_t bsp_module_manager;
|
||||
|
||||
/**
|
||||
* @brief Initialize BSP module manager
|
||||
* @retval HAL status code
|
||||
* @brief 初始化 BSP 模块管理器
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_manager_init(void) {
|
||||
/* Clear module manager */
|
||||
@ -35,9 +35,9 @@ hal_ret_t bsp_module_manager_init(void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Register a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注册一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_register(bsp_module_t* module) {
|
||||
if (module == NULL) {
|
||||
@ -102,9 +102,9 @@ hal_ret_t bsp_module_register(bsp_module_t* module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Unregister a BSP module
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 注销一个 BSP 模块
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_unregister(bsp_module_t* module) {
|
||||
if (module == NULL) {
|
||||
@ -146,10 +146,10 @@ hal_ret_t bsp_module_unregister(bsp_module_t* module) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get a specific BSP module
|
||||
* @param type: Module type
|
||||
* @param instance: Module instance
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 获取指定的 BSP 模块
|
||||
* @param type: 模块类型
|
||||
* @param instance: 模块实例
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get(bsp_module_type_t type, uint8_t instance) {
|
||||
if (type >= BSP_MODULE_TYPE_MAX) {
|
||||
@ -168,9 +168,9 @@ bsp_module_t* bsp_module_get(bsp_module_type_t type, uint8_t instance) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all modules of a specific type
|
||||
* @param type: Module type
|
||||
* @retval Pointer to module list, or NULL if no modules found
|
||||
* @brief 获取指定类型的所有模块
|
||||
* @param type: 模块类型
|
||||
* @retval 指向模块列表的指针,未找到模块返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_type(bsp_module_type_t type) {
|
||||
if (type >= BSP_MODULE_TYPE_MAX) {
|
||||
@ -181,9 +181,9 @@ bsp_module_t* bsp_module_get_by_type(bsp_module_type_t type) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get module by name
|
||||
* @param name: Module name
|
||||
* @retval Pointer to module structure, or NULL if not found
|
||||
* @brief 通过名称获取模块
|
||||
* @param name: 模块名称
|
||||
* @retval 指向模块结构体的指针,未找到返回 NULL
|
||||
*/
|
||||
bsp_module_t* bsp_module_get_by_name(const char* name) {
|
||||
if (name == NULL) {
|
||||
@ -202,9 +202,9 @@ bsp_module_t* bsp_module_get_by_name(const char* name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if all dependencies of a module are satisfied
|
||||
* @param module: Pointer to module structure
|
||||
* @retval HAL status code
|
||||
* @brief 检查模块的所有依赖是否满足
|
||||
* @param module: 指向模块结构体的指针
|
||||
* @retval HAL 状态码
|
||||
*/
|
||||
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module) {
|
||||
if (module == NULL) {
|
||||
|
||||
@ -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