进一步迭代优化统一管理

This commit is contained in:
冯佳
2026-01-23 14:35:51 +08:00
parent 988cc7ad4a
commit 075e8299cf
36 changed files with 6146 additions and 1590 deletions

View File

@ -0,0 +1,163 @@
# STM32F407项目优化计划
## 1. 项目现状分析
通过对代码的深入分析当前项目已经具备了基本的HAL硬件抽象层和BSP板级支持包分层设计但在以下方面还有很大的优化空间
### 1.1 HAL层现状
- 已实现GPIO、UART、SPI等基本外设的HAL驱动
- 采用了架构分离的设计通过HAL_TARGET_ARCH宏
- 缺少统一的错误处理机制
- 缺少统一的HAL模块管理机制
### 1.2 BSP层现状
- 实现了基本的板级初始化
- 采用了配置结构体的方式定义板级配置
- 缺少基于配置文件的初始化机制
- 模块化程度不够,外设驱动之间耦合度较高
## 2. 优化目标
### 2.1 HAL层优化目标
- 完善架构抽象,提高通用性
- 实现统一的错误处理机制
- 增加HAL模块管理机制
- 支持更多外设类型
### 2.2 BSP层优化目标
- 实现基于配置文件的BSP初始化
- 增加BSP层的模块化设计
- 优化板级配置结构体
- 支持动态扩展的外设配置
## 3. 具体实施步骤
### 3.1 HAL层优化
**3.1.1 完善HAL层架构抽象**
1. **修改`hal.h`**
- 增加HAL模块管理机制
- 定义统一的错误码枚举
- 增加HAL层版本信息
- 完善架构分离机制
2. **实现统一的HAL模块初始化**
- 创建`hal_module.h`定义HAL模块管理接口
- 实现HAL模块的注册、初始化和卸载功能
- 支持模块的依赖管理
**3.1.2 优化HAL层错误处理**
1. **定义统一的错误码**
```c
typedef enum {
HAL_OK = 0,
HAL_ERROR,
HAL_BUSY,
HAL_TIMEOUT,
HAL_INVALID_PARAM,
HAL_NOT_SUPPORTED,
// 更多错误码...
} hal_status_t;
```
2. **修改HAL函数签名**
- 将所有HAL函数改为返回`hal_status_t`
- 增加错误信息传递机制
- 实现错误日志记录功能
3. **实现错误处理工具函数**
- 编写`hal_error.h`,提供错误码转换和处理工具
- 支持错误信息的格式化输出
### 3.2 BSP层优化
**3.2.1 实现基于配置文件的BSP初始化**
1. **设计配置文件格式**
- 采用JSON或二进制格式存储配置
- 支持分层配置结构
- 实现配置版本管理
2. **实现配置文件解析器**
- 创建`bsp_config_parser.c`,实现配置文件解析功能
- 支持从Flash或文件系统加载配置
- 实现配置的验证和默认值填充
3. **修改BSP初始化流程**
- 修改`bsp_init.c`,支持从配置文件加载配置
- 实现配置的动态应用
- 增加配置变更通知机制
**3.2.2 增加BSP层模块化设计**
1. **实现外设驱动模块化**
- 为每个外设驱动创建独立的模块
- 实现模块的注册和初始化机制
- 支持模块的动态加载和卸载
2. **创建BSP模块管理机制**
- 编写`bsp_module.h`定义BSP模块管理接口
- 实现模块的依赖管理
- 支持模块的优先级管理
3. **优化外设驱动之间的交互**
- 采用事件驱动机制,减少外设驱动之间的耦合
- 实现外设驱动的异步操作支持
- 增加外设驱动的状态管理
**3.2.3 优化板级配置结构体**
1. **修改`bsp_board.h`**
- 增加配置结构体的版本字段
- 支持配置的动态扩展
- 实现配置的默认值机制
2. **设计灵活的配置扩展机制**
- 采用链表或数组方式存储扩展配置
- 支持配置项的动态添加和删除
- 实现配置的序列化和反序列化
3. **实现配置的校验机制**
- 增加配置项的合法性校验
- 支持配置的完整性检查
- 实现配置的自动修复功能
## 4. 预期成果
通过本次优化,项目将实现:
- **更完善的HAL层**:具有统一的错误处理机制和模块管理,提高了通用性和可维护性
- **更灵活的BSP层**:支持基于配置文件的初始化,模块化程度更高,外设驱动之间耦合度更低
- **更优化的板级配置**:支持动态扩展和版本管理,配置更加灵活和可靠
- **更好的可扩展性**:便于添加新的外设驱动和支持新的硬件平台
- **更好的可维护性**:代码结构更清晰,错误处理更完善,便于调试和维护
## 5. 实施顺序
1. 首先优化HAL层的错误处理机制
2. 然后完善HAL层的架构抽象
3. 接着优化板级配置结构体
4. 然后实现BSP层的模块化设计
5. 最后实现基于配置文件的BSP初始化
## 6. 风险评估
- **风险1**修改HAL函数签名可能导致现有代码无法编译
- **应对措施**:采用渐进式修改,先添加错误码返回,保持向后兼容
- **风险2**:配置文件解析可能增加系统开销
- **应对措施**:优化解析算法,采用高效的解析库,支持配置的缓存机制
- **风险3**:模块化设计可能增加代码复杂度
- **应对措施**:保持模块接口的简洁性,提供详细的文档和示例代码
## 7. 测试计划
- 单元测试测试每个HAL函数的错误处理功能
- 集成测试测试HAL模块管理机制
- 系统测试测试基于配置文件的BSP初始化
- 回归测试:确保现有功能不受影响
通过以上优化,项目将在架构设计、代码质量和可维护性方面得到显著提升,为后续的功能扩展和平台移植奠定坚实的基础。

View File

@ -11,39 +11,53 @@
#define BSP_BOARD_H #define BSP_BOARD_H
#include <stdint.h> #include <stdint.h>
#include "hal.h"
#include "hal_gpio.h" #include "hal_gpio.h"
#include "hal_uart.h" #include "hal_uart.h"
#include "hal_spi.h" #include "hal_spi.h"
#include "hal_i2c.h"
#include "hal_can.h"
#include "hal_adc.h"
/**
* @brief BSP configuration version
*/
#define BSP_CONFIG_VERSION_MAJOR 1
#define BSP_CONFIG_VERSION_MINOR 0
#define BSP_CONFIG_VERSION_PATCH 0
#define BSP_CONFIG_VERSION (BSP_CONFIG_VERSION_MAJOR << 16 | BSP_CONFIG_VERSION_MINOR << 8 | BSP_CONFIG_VERSION_PATCH)
/** /**
* @brief Board LED configuration structure * @brief Board LED configuration structure
*/ */
typedef struct { typedef struct {
hal_gpio_port_t port; uint8_t enable; /*!< LED enable flag */
hal_gpio_pin_t pin; hal_gpio_port_t port; /*!< LED GPIO port */
hal_gpio_mode_t mode; hal_gpio_pin_t pin; /*!< LED GPIO pin */
hal_gpio_speed_t speed; hal_gpio_mode_t mode; /*!< LED GPIO mode */
hal_gpio_pull_t pull; hal_gpio_speed_t speed; /*!< LED GPIO speed */
hal_gpio_pull_t pull; /*!< LED GPIO pull configuration */
} bsp_led_config_t; } bsp_led_config_t;
/** /**
* @brief Board button configuration structure * @brief Board button configuration structure
*/ */
typedef struct { typedef struct {
hal_gpio_port_t port; hal_gpio_port_t port; /*!< Button GPIO port */
hal_gpio_pin_t pin; hal_gpio_pin_t pin; /*!< Button GPIO pin */
hal_gpio_mode_t mode; hal_gpio_mode_t mode; /*!< Button GPIO mode */
hal_gpio_speed_t speed; hal_gpio_speed_t speed; /*!< Button GPIO speed */
hal_gpio_pull_t pull; hal_gpio_pull_t pull; /*!< Button GPIO pull configuration */
uint8_t active_high; uint8_t active_high; /*!< Button active high flag */
} bsp_button_config_t; } bsp_button_config_t;
/** /**
* @brief Board buttons configuration structure * @brief Board buttons configuration structure
*/ */
typedef struct { typedef struct {
uint8_t count; uint8_t enable; /*!< Buttons enable flag */
const bsp_button_config_t* buttons; uint8_t count; /*!< Number of buttons */
const bsp_button_config_t* buttons; /*!< Pointer to buttons configuration array */
} bsp_buttons_config_t; } bsp_buttons_config_t;
/** /**
@ -63,62 +77,226 @@ typedef enum {
* @brief Board UART configuration structure * @brief Board UART configuration structure
*/ */
typedef struct { typedef struct {
bsp_uart_instance_t instance; uint8_t enable; /*!< UART enable flag */
uint32_t baudrate; bsp_uart_instance_t instance; /*!< UART instance */
hal_uart_parity_t parity; uint32_t baudrate; /*!< UART baudrate */
hal_uart_stopbits_t stopbits; hal_uart_parity_t parity; /*!< UART parity */
hal_uart_databits_t databits; hal_uart_stopbits_t stopbits; /*!< UART stop bits */
hal_gpio_port_t tx_port; hal_uart_databits_t databits; /*!< UART data bits */
hal_gpio_pin_t tx_pin; hal_gpio_port_t tx_port; /*!< UART TX port */
hal_gpio_port_t rx_port; hal_gpio_pin_t tx_pin; /*!< UART TX pin */
hal_gpio_pin_t rx_pin; hal_gpio_port_t rx_port; /*!< UART RX port */
hal_gpio_pin_t rx_pin; /*!< UART RX pin */
} bsp_uart_config_t; } bsp_uart_config_t;
/** /**
* @brief Board SPI configuration structure * @brief Board SPI configuration structure
*/ */
typedef struct { typedef struct {
hal_spi_instance_t instance; uint8_t enable; /*!< SPI enable flag */
hal_spi_mode_t mode; hal_spi_instance_t instance; /*!< SPI instance */
uint32_t baudrate; hal_spi_mode_t mode; /*!< SPI mode */
hal_spi_polarity_t polarity; uint32_t baudrate; /*!< SPI baudrate */
hal_spi_phase_t phase; hal_spi_polarity_t polarity; /*!< SPI clock polarity */
hal_spi_databits_t databits; hal_spi_phase_t phase; /*!< SPI clock phase */
hal_spi_databits_t databits; /*!< SPI data bits */
hal_gpio_port_t sck_port; /*!< SPI SCK port */
hal_gpio_pin_t sck_pin; /*!< SPI SCK pin */
hal_gpio_port_t miso_port; /*!< SPI MISO port */
hal_gpio_pin_t miso_pin; /*!< SPI MISO pin */
hal_gpio_port_t mosi_port; /*!< SPI MOSI port */
hal_gpio_pin_t mosi_pin; /*!< SPI MOSI pin */
} bsp_spi_config_t; } bsp_spi_config_t;
/**
* @brief Board I2C configuration structure
*/
typedef struct {
uint8_t enable; /*!< I2C enable flag */
hal_i2c_instance_t instance; /*!< I2C instance */
hal_i2c_speed_t speed; /*!< I2C speed */
hal_i2c_address_mode_t address_mode; /*!< I2C address mode */
hal_i2c_dutycycle_t dutycycle; /*!< I2C duty cycle */
uint16_t own_address1; /*!< I2C own address 1 */
hal_gpio_port_t scl_port; /*!< I2C SCL port */
hal_gpio_pin_t scl_pin; /*!< I2C SCL pin */
hal_gpio_port_t sda_port; /*!< I2C SDA port */
hal_gpio_pin_t sda_pin; /*!< I2C SDA pin */
} bsp_i2c_config_t;
/**
* @brief Board CAN configuration structure
*/
typedef struct {
uint8_t enable; /*!< CAN enable flag */
hal_can_instance_t instance; /*!< CAN instance */
hal_can_mode_t mode; /*!< CAN mode */
uint32_t prescaler; /*!< CAN prescaler */
uint8_t sync_jump_width; /*!< CAN sync jump width */
uint8_t time_segment1; /*!< CAN time segment 1 */
uint8_t time_segment2; /*!< CAN time segment 2 */
hal_gpio_port_t rx_port; /*!< CAN RX port */
hal_gpio_pin_t rx_pin; /*!< CAN RX pin */
hal_gpio_port_t tx_port; /*!< CAN TX port */
hal_gpio_pin_t tx_pin; /*!< CAN TX pin */
} bsp_can_config_t;
/**
* @brief Board ADC channel configuration structure
*/
typedef struct {
uint8_t enable; /*!< ADC channel enable flag */
hal_adc_channel_t channel; /*!< ADC channel */
hal_adc_sampletime_t sampletime; /*!< ADC sample time */
uint8_t rank; /*!< ADC channel rank */
} bsp_adc_channel_config_t;
/**
* @brief Board ADC configuration structure
*/
typedef struct {
uint8_t enable; /*!< ADC enable flag */
hal_adc_instance_t instance; /*!< ADC instance */
hal_adc_resolution_t resolution; /*!< ADC resolution */
uint8_t scan_conversion_mode; /*!< ADC scan conversion mode */
uint8_t continuous_conversion_mode; /*!< ADC continuous conversion mode */
uint8_t channel_count; /*!< Number of ADC channels */
const bsp_adc_channel_config_t* channels; /*!< Pointer to ADC channels configuration array */
} bsp_adc_config_t;
/** /**
* @brief Board W25QXX configuration structure * @brief Board W25QXX configuration structure
*/ */
typedef struct { typedef struct {
hal_gpio_port_t cs_port; uint8_t enable; /*!< W25QXX enable flag */
hal_gpio_pin_t cs_pin; hal_gpio_port_t cs_port; /*!< W25QXX CS port */
bsp_spi_config_t spi_config; hal_gpio_pin_t cs_pin; /*!< W25QXX CS pin */
uint8_t spi_instance; /*!< SPI instance used by W25QXX */
} bsp_w25qxx_config_t; } bsp_w25qxx_config_t;
/** /**
* @brief Board peripheral initialization function type * @brief Board peripheral initialization function type
*/ */
typedef void (*bsp_periph_init_func_t)(const void* config); typedef hal_ret_t (*bsp_periph_init_func_t)(const void* config);
/**
* @brief Board ID structure
*/
typedef struct {
uint16_t vendor_id; /*!< Board vendor ID */
uint16_t product_id; /*!< Board product ID */
uint32_t serial_number; /*!< Board serial number */
} bsp_board_id_t;
/**
* @brief Board feature flags
*/
typedef enum {
BSP_BOARD_FEATURE_LED = (1 << 0), /*!< Board has LED support */
BSP_BOARD_FEATURE_BUTTON = (1 << 1), /*!< Board has button support */
BSP_BOARD_FEATURE_UART = (1 << 2), /*!< Board has UART support */
BSP_BOARD_FEATURE_SPI = (1 << 3), /*!< Board has SPI support */
BSP_BOARD_FEATURE_I2C = (1 << 4), /*!< Board has I2C support */
BSP_BOARD_FEATURE_CAN = (1 << 5), /*!< Board has CAN support */
BSP_BOARD_FEATURE_ADC = (1 << 6), /*!< Board has ADC support */
BSP_BOARD_FEATURE_DAC = (1 << 7), /*!< Board has DAC support */
BSP_BOARD_FEATURE_TIMER = (1 << 8), /*!< Board has TIMER support */
BSP_BOARD_FEATURE_RTC = (1 << 9), /*!< Board has RTC support */
BSP_BOARD_FEATURE_W25QXX = (1 << 10), /*!< Board has W25QXX support */
BSP_BOARD_FEATURE_DMA = (1 << 11), /*!< Board has DMA support */
BSP_BOARD_FEATURE_ETH = (1 << 12), /*!< Board has ETH support */
BSP_BOARD_FEATURE_USB = (1 << 13), /*!< Board has USB support */
BSP_BOARD_FEATURE_SDIO = (1 << 14), /*!< Board has SDIO support */
BSP_BOARD_FEATURE_FSMC = (1 << 15), /*!< Board has FSMC support */
} bsp_board_feature_t;
/**
* @brief Board hardware information structure
*/
typedef struct {
uint32_t clock_speed; /*!< Board clock speed */
uint32_t flash_size; /*!< Flash size in bytes */
uint32_t ram_size; /*!< RAM size in bytes */
uint32_t eeprom_size; /*!< EEPROM size in bytes */
uint32_t sram_size; /*!< SRAM size in bytes */
uint8_t cpu_core; /*!< CPU core type */
uint8_t cpu_bits; /*!< CPU bits (32 or 64) */
} bsp_board_hw_info_t;
/**
* @brief Board peripheral configuration structure
*/
typedef struct {
/* UART configurations */
uint8_t uart_count; /*!< Number of UARTs */
const bsp_uart_config_t* uarts; /*!< Pointer to UARTs configuration array */
/* SPI configurations */
uint8_t spi_count; /*!< Number of SPIs */
const bsp_spi_config_t* spis; /*!< Pointer to SPIs configuration array */
/* I2C configurations */
uint8_t i2c_count; /*!< Number of I2Cs */
const bsp_i2c_config_t* i2cs; /*!< Pointer to I2Cs configuration array */
/* CAN configurations */
uint8_t can_count; /*!< Number of CANs */
const bsp_can_config_t* cans; /*!< Pointer to CANs configuration array */
/* ADC configurations */
uint8_t adc_count; /*!< Number of ADCs */
const bsp_adc_config_t* adcs; /*!< Pointer to ADCs configuration array */
} bsp_board_periph_config_t;
/**
* @brief Board initialization function pointers structure
*/
typedef struct {
bsp_periph_init_func_t led_init; /*!< LED initialization function */
bsp_periph_init_func_t button_init; /*!< Button initialization function */
bsp_periph_init_func_t uart_init; /*!< UART initialization function */
bsp_periph_init_func_t spi_init; /*!< SPI initialization function */
bsp_periph_init_func_t i2c_init; /*!< I2C initialization function */
bsp_periph_init_func_t can_init; /*!< CAN initialization function */
bsp_periph_init_func_t adc_init; /*!< ADC initialization function */
bsp_periph_init_func_t w25qxx_init; /*!< W25QXX initialization function */
} bsp_board_init_funcs_t;
/** /**
* @brief Board configuration structure * @brief Board configuration structure
*/ */
typedef struct { typedef struct {
const char* name; uint32_t version; /*!< Configuration version */
bsp_led_config_t led; const char* name; /*!< Board name */
bsp_buttons_config_t buttons; const char* description; /*!< Board description */
bsp_uart_config_t uart; bsp_board_id_t id; /*!< Board ID information */
bsp_w25qxx_config_t w25qxx;
/* Initialization function pointers */ /* Board features */
bsp_periph_init_func_t led_init; uint32_t features; /*!< Board feature flags */
bsp_periph_init_func_t button_init;
bsp_periph_init_func_t uart_init; /* Hardware information */
bsp_periph_init_func_t w25qxx_init; bsp_board_hw_info_t hw_info; /*!< Hardware information */
/* Peripheral configurations */
bsp_led_config_t led; /*!< LED configuration */
bsp_buttons_config_t buttons; /*!< Buttons configuration */
bsp_w25qxx_config_t w25qxx; /*!< W25QXX configuration */
/* Peripheral arrays */
bsp_board_periph_config_t periphs; /*!< Peripheral configurations */
/* Initialization functions */
bsp_board_init_funcs_t init_funcs; /*!< Initialization function pointers */
/* Additional board-specific configuration */ /* Additional board-specific configuration */
uint32_t clock_speed; void* custom_config; /*!< Custom board configuration pointer */
uint8_t uart_count; size_t custom_config_size; /*!< Custom board configuration size */
/* Board revision information */
uint8_t major_rev; /*!< Major revision */
uint8_t minor_rev; /*!< Minor revision */
uint8_t patch_rev; /*!< Patch revision */
const char* revision_desc; /*!< Revision description */
} bsp_board_config_t; } bsp_board_config_t;
/** /**
@ -128,8 +306,9 @@ extern const bsp_board_config_t stm32f407vet6_board_config;
/** /**
* @brief Board hardware initialization * @brief Board hardware initialization
* @retval HAL status code
*/ */
void bsp_board_init(void); hal_ret_t bsp_board_init(void);
/** /**
* @brief Get board name * @brief Get board name
@ -137,4 +316,10 @@ void bsp_board_init(void);
*/ */
const char* bsp_board_get_name(void); const char* bsp_board_get_name(void);
/**
* @brief Get board configuration
* @retval Pointer to board configuration structure
*/
const bsp_board_config_t* bsp_board_get_config(void);
#endif /* BSP_BOARD_H */ #endif /* BSP_BOARD_H */

View File

@ -37,16 +37,16 @@ const bsp_board_config_t* bsp_board_get_by_name(const char* name);
/** /**
* @brief Set current board configuration by index * @brief Set current board configuration by index
* @param index: Board configuration index * @param index: Board configuration index
* @retval 0 if successful, -1 if invalid index * @retval HAL status code
*/ */
int8_t bsp_board_set_by_index(uint8_t index); hal_ret_t bsp_board_set_by_index(uint8_t index);
/** /**
* @brief Set current board configuration by name * @brief Set current board configuration by name
* @param name: Board name string * @param name: Board name string
* @retval 0 if successful, -1 if not found * @retval HAL status code
*/ */
int8_t bsp_board_set_by_name(const char* name); hal_ret_t bsp_board_set_by_name(const char* name);
/** /**
* @brief Get current board configuration * @brief Get current board configuration

View File

@ -2,7 +2,7 @@
/** /**
****************************************************************************** ******************************************************************************
* @file : bsp_config.h * @file : bsp_config.h
* @brief : Board support package configuration file * @brief : Board support package configuration file header
****************************************************************************** ******************************************************************************
*/ */
/* USER CODE END Header */ /* USER CODE END Header */
@ -10,42 +10,175 @@
#ifndef BSP_CONFIG_H #ifndef BSP_CONFIG_H
#define BSP_CONFIG_H #define BSP_CONFIG_H
#include "hal_gpio.h" #include <stdio.h>
#include "hal_uart.h" #include "bsp_module.h"
#include "bsp_board.h"
#include "hal.h"
/** /**
* @brief Board name definition * @brief BSP configuration file format definitions
*/ */
#define BOARD_NAME "STM32F407VET6" #define BSP_CONFIG_FILE_VERSION "1.0.0"
#define BSP_CONFIG_MAX_LINE_LENGTH 256
#define BSP_CONFIG_MAX_SECTION_NAME_LENGTH 32
#define BSP_CONFIG_MAX_KEY_NAME_LENGTH 32
#define BSP_CONFIG_MAX_VALUE_LENGTH 128
/** /**
* @brief LED hardware configuration * @brief BSP configuration section type
*/ */
#define BSP_LED_PORT HAL_GPIO_PORT_A typedef enum {
#define BSP_LED_PIN HAL_GPIO_PIN_6 BSP_CONFIG_SECTION_NONE = 0,
BSP_CONFIG_SECTION_BOARD,
BSP_CONFIG_SECTION_MODULE,
BSP_CONFIG_SECTION_PERIPH,
BSP_CONFIG_SECTION_MAX
} bsp_config_section_t;
/** /**
* @brief Button hardware configuration * @brief BSP configuration entry
*/ */
/* KEY0 - PE4, active low */ typedef struct {
#define BSP_KEY0_PORT HAL_GPIO_PORT_E const char* section;
#define BSP_KEY0_PIN HAL_GPIO_PIN_4 const char* key;
const char* value;
/* KEY1 - PE3, active low */ } bsp_config_entry_t;
#define BSP_KEY1_PORT HAL_GPIO_PORT_E
#define BSP_KEY1_PIN HAL_GPIO_PIN_3
/* WK_UP - PA0, active high */
#define BSP_WKUP_PORT HAL_GPIO_PORT_A
#define BSP_WKUP_PIN HAL_GPIO_PIN_0
/** /**
* @brief UART hardware configuration * @brief BSP configuration parser context
*/ */
#define BSP_UART_INSTANCE BSP_UART_INSTANCE_1 typedef struct {
#define BSP_UART_BAUDRATE 115200 FILE* file;
#define BSP_UART_PARITY HAL_UART_PARITY_NONE char current_section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH];
#define BSP_UART_STOPBITS HAL_UART_STOPBITS_1 char buffer[BSP_CONFIG_MAX_LINE_LENGTH];
#define BSP_UART_DATABITS HAL_UART_DATABITS_8 uint32_t line_number;
uint8_t initialized;
} bsp_config_parser_t;
/**
* @brief BSP configuration file operations
*/
typedef struct {
hal_ret_t (*open)(const char* filename, bsp_config_parser_t* parser);
hal_ret_t (*close)(bsp_config_parser_t* parser);
hal_ret_t (*read_entry)(bsp_config_parser_t* parser, bsp_config_entry_t* entry);
hal_ret_t (*parse_int)(const char* value, int* result);
hal_ret_t (*parse_uint)(const char* value, uint32_t* result);
hal_ret_t (*parse_bool)(const char* value, uint8_t* result);
hal_ret_t (*parse_string)(const char* value, char* result, size_t max_length);
} bsp_config_ops_t;
/**
* @brief Initialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_init(void);
/**
* @brief Deinitialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_deinit(void);
/**
* @brief Load BSP configuration from file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_config_load(const char* filename);
/**
* @brief Save BSP configuration to file
* @param filename: Configuration file name
* @retval HAL status code
*/
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
*/
hal_ret_t bsp_config_get_value(const char* section, const char* key, char* value, size_t max_length);
/**
* @brief Set configuration value
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Configuration value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_value(const char* section, const char* key, const char* value);
/**
* @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
*/
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
*/
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
*/
hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* value);
/**
* @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
*/
hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t value);
/**
* @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
*/
hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* value);
/**
* @brief Set configuration value as boolean
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Boolean value
* @retval HAL status code
*/
hal_ret_t bsp_config_set_bool(const char* section, const char* key, uint8_t value);
/**
* @brief Parse BSP modules from configuration
* @param config: Pointer to BSP board configuration structure to fill
* @retval HAL status code
*/
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
*/
hal_ret_t bsp_init_from_config(const char* filename);
#endif /* BSP_CONFIG_H */ #endif /* BSP_CONFIG_H */

View File

@ -14,13 +14,15 @@
/** /**
* @brief Initialize board support package * @brief Initialize board support package
* @retval HAL status code
*/ */
void bsp_init(void); hal_ret_t bsp_init(void);
/** /**
* @brief Initialize board GPIO * @brief Initialize board GPIO
* @retval HAL status code
*/ */
void bsp_gpio_init(void); hal_ret_t bsp_gpio_init(void);
/** /**
* @brief Get board name * @brief Get board name

401
BSP/Inc/bsp_module.h Normal file
View File

@ -0,0 +1,401 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : bsp_module.h
* @brief : Board support package module management header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef BSP_MODULE_H
#define BSP_MODULE_H
#include "hal.h"
/**
* @brief BSP module type definitions
*/
typedef enum {
BSP_MODULE_TYPE_LED = 0,
BSP_MODULE_TYPE_BUTTON,
BSP_MODULE_TYPE_UART,
BSP_MODULE_TYPE_SPI,
BSP_MODULE_TYPE_I2C,
BSP_MODULE_TYPE_CAN,
BSP_MODULE_TYPE_ADC,
BSP_MODULE_TYPE_DAC,
BSP_MODULE_TYPE_TIMER,
BSP_MODULE_TYPE_RTC,
BSP_MODULE_TYPE_W25QXX,
BSP_MODULE_TYPE_MAX
} bsp_module_type_t;
/**
* @brief BSP module state definitions
*/
typedef enum {
BSP_MODULE_STATE_UNINIT = 0,
BSP_MODULE_STATE_INIT,
BSP_MODULE_STATE_CONFIGURED,
BSP_MODULE_STATE_RUNNING,
BSP_MODULE_STATE_ERROR
} bsp_module_state_t;
/**
* @brief BSP module priority definitions
*/
typedef enum {
BSP_MODULE_PRIORITY_HIGHEST = 0,
BSP_MODULE_PRIORITY_HIGH,
BSP_MODULE_PRIORITY_MEDIUM,
BSP_MODULE_PRIORITY_LOW,
BSP_MODULE_PRIORITY_LOWEST
} bsp_module_priority_t;
/**
* @brief BSP module configuration structure
*/
typedef struct bsp_module_config {
bsp_module_type_t type; /*!< Module type */
const char* name; /*!< Module name */
bsp_module_priority_t priority; /*!< Module priority */
uint32_t version; /*!< Module version */
uint8_t instance; /*!< Module instance */
uint8_t enable; /*!< Module enable flag */
void* config_data; /*!< Module configuration data */
size_t config_size; /*!< Module configuration size */
uint32_t dependencies; /*!< Module dependencies bitmask */
} bsp_module_config_t;
/**
* @brief BSP module operations structure
*/
typedef struct {
hal_ret_t (*init)(void* config); /*!< Module initialization function */
hal_ret_t (*deinit)(void); /*!< Module deinitialization function */
hal_ret_t (*configure)(void* config); /*!< Module configuration function */
hal_ret_t (*start)(void); /*!< Module start function */
hal_ret_t (*stop)(void); /*!< Module stop function */
hal_ret_t (*reset)(void); /*!< Module reset function */
bsp_module_state_t (*get_state)(void); /*!< Module get state function */
hal_ret_t (*control)(uint32_t cmd, void* param); /*!< Module control function */
} bsp_module_ops_t;
/**
* @brief BSP module version structure
*/
typedef struct {
uint8_t major;
uint8_t minor;
uint8_t patch;
} bsp_module_version_t;
/**
* @brief Forward declaration of bsp_module_t
*/
typedef struct bsp_module bsp_module_t;
/**
* @brief BSP module event callback type
*/
typedef hal_ret_t (*bsp_module_event_callback_t)(const bsp_module_t* sender, uint32_t event, void* data);
/**
* @brief BSP module structure
*/
typedef struct bsp_module {
bsp_module_config_t config; /*!< Module configuration */
bsp_module_ops_t ops; /*!< Module operations */
bsp_module_state_t state; /*!< Module state */
bsp_module_version_t version; /*!< Module version */
struct bsp_module* next; /*!< Pointer to next module in the list */
struct bsp_module* prev; /*!< Pointer to previous module in the list */
void* private_data; /*!< Module private data */
bsp_module_event_callback_t event_callback; /*!< Event callback */
} bsp_module_t;
/**
* @brief BSP module event definitions
*/
#define BSP_MODULE_EVENT_INIT (1 << 0) /*!< Module initialized */
#define BSP_MODULE_EVENT_DEINIT (1 << 1) /*!< Module deinitialized */
#define BSP_MODULE_EVENT_START (1 << 2) /*!< Module started */
#define BSP_MODULE_EVENT_STOP (1 << 3) /*!< Module stopped */
#define BSP_MODULE_EVENT_ERROR (1 << 4) /*!< Module error */
#define BSP_MODULE_EVENT_CONFIG (1 << 5) /*!< Module configured */
#define BSP_MODULE_EVENT_CUSTOM (1 << 8) /*!< Custom module event base */
/**
* @brief BSP module auto-registration macros
*/
#define BSP_MODULE_REGISTER(module) \
static const bsp_module_config_t __bsp_module_##module##_config = { \
.type = BSP_MODULE_TYPE_##module, \
.name = #module, \
.priority = BSP_MODULE_PRIORITY_MEDIUM, \
.version = 1, \
.instance = 0, \
.enable = 1, \
.config_data = NULL, \
.config_size = 0, \
.dependencies = 0 \
}; \
static bsp_module_t __bsp_module_##module = { \
.config = __bsp_module_##module##_config, \
.state = BSP_MODULE_STATE_UNINIT, \
.version = {1, 0, 0}, \
.event_callback = NULL \
};
#define BSP_MODULE_REGISTER_FULL(module, type, priority, instance, deps) \
static const bsp_module_config_t __bsp_module_##module##_config = { \
.type = (type), \
.name = #module, \
.priority = (priority), \
.version = 1, \
.instance = (instance), \
.enable = 1, \
.config_data = NULL, \
.config_size = 0, \
.dependencies = (deps) \
}; \
static bsp_module_t __bsp_module_##module = { \
.config = __bsp_module_##module##_config, \
.state = BSP_MODULE_STATE_UNINIT, \
.version = {1, 0, 0}, \
.event_callback = NULL \
};
#define BSP_MODULE_REGISTER_AT_STARTUP(module) \
BSP_MODULE_REGISTER(module) \
__attribute__((constructor)) static void __bsp_register_##module##_at_startup(void) { \
bsp_module_register(&__bsp_module_##module); \
}
/**
* @brief BSP module manager structure
*/
typedef struct {
bsp_module_t* modules[BSP_MODULE_TYPE_MAX]; /*!< Modules by type */
bsp_module_t* module_list; /*!< Linked list of all modules */
uint32_t module_count; /*!< Total number of modules */
} bsp_module_manager_t;
/**
* @brief Initialize BSP module manager
* @retval HAL status code
*/
hal_ret_t bsp_module_manager_init(void);
/**
* @brief Register a BSP module
* @param module: Pointer to module structure
* @retval HAL status code
*/
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
*/
hal_ret_t bsp_module_unregister(bsp_module_t* module);
/**
* @brief Initialize all registered BSP modules
* @retval HAL status code
*/
hal_ret_t bsp_module_init_all(void);
/**
* @brief Deinitialize all registered BSP modules
* @retval HAL status code
*/
hal_ret_t bsp_module_deinit_all(void);
/**
* @brief Start all registered BSP modules
* @retval HAL status code
*/
hal_ret_t bsp_module_start_all(void);
/**
* @brief Stop all registered BSP modules
* @retval HAL status code
*/
hal_ret_t bsp_module_stop_all(void);
/**
* @brief Initialize a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_init(bsp_module_type_t type, uint8_t instance);
/**
* @brief Deinitialize a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_deinit(bsp_module_type_t type, uint8_t instance);
/**
* @brief Configure a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param config: Module configuration data
* @param size: Module configuration size
* @retval HAL status code
*/
hal_ret_t bsp_module_configure(bsp_module_type_t type, uint8_t instance, void* config, size_t size);
/**
* @brief Start a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_start(bsp_module_type_t type, uint8_t instance);
/**
* @brief Stop a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_stop(bsp_module_type_t type, uint8_t instance);
/**
* @brief Reset a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_reset(bsp_module_type_t type, uint8_t instance);
/**
* @brief Get state of a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param state: Pointer to store module state
* @retval HAL status code
*/
hal_ret_t bsp_module_get_state(bsp_module_type_t type, uint8_t instance, bsp_module_state_t* state);
/**
* @brief Control a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param cmd: Control command
* @param param: Control parameter
* @retval HAL status code
*/
hal_ret_t bsp_module_control(bsp_module_type_t type, uint8_t instance, uint32_t cmd, void* param);
/**
* @brief Get a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval Pointer to module structure, or NULL if not found
*/
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
*/
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
*/
bsp_module_t* bsp_module_get_by_name(const char* name);
/**
* @brief Get total number of registered modules
* @retval Number of registered modules
*/
uint32_t bsp_module_get_count(void);
/**
* @brief Check if all dependencies of a module are satisfied
* @param module: Pointer to module structure
* @retval HAL status code
*/
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module);
/**
* @brief Get module manager instance
* @retval Pointer to module manager structure
*/
bsp_module_manager_t* bsp_module_get_manager(void);
/**
* @brief Register a module event callback
* @param type: Module type
* @param instance: Module instance
* @param callback: Event callback function
* @retval HAL status code
*/
hal_ret_t bsp_module_register_event_callback(bsp_module_type_t type, uint8_t instance, bsp_module_event_callback_t callback);
/**
* @brief Trigger a module event
* @param module: Pointer to module structure
* @param event: Event to trigger
* @param data: Event data
* @retval HAL status code
*/
hal_ret_t bsp_module_trigger_event(const bsp_module_t* module, uint32_t event, void* data);
/**
* @brief Find modules by priority range
* @param min_priority: Minimum priority
* @param max_priority: Maximum priority
* @param count: Pointer to store number of modules found
* @retval Pointer to array of module pointers, or NULL if no modules found
*/
bsp_module_t** bsp_module_find_by_priority_range(bsp_module_priority_t min_priority, bsp_module_priority_t max_priority, uint32_t* count);
/**
* @brief Set module enable/disable state
* @param type: Module type
* @param instance: Module instance
* @param enable: Enable flag
* @retval HAL status code
*/
hal_ret_t bsp_module_set_enable(bsp_module_type_t type, uint8_t instance, uint8_t enable);
/**
* @brief Check if module is enabled
* @param type: Module type
* @param instance: Module instance
* @param enable: Pointer to store enable state
* @retval HAL status code
*/
hal_ret_t bsp_module_is_enabled(bsp_module_type_t type, uint8_t instance, uint8_t* enable);
/**
* @brief Set module priority
* @param type: Module type
* @param instance: Module instance
* @param priority: New priority
* @retval HAL status code
*/
hal_ret_t bsp_module_set_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t priority);
/**
* @brief Get module priority
* @param type: Module type
* @param instance: Module instance
* @param priority: Pointer to store priority
* @retval HAL return code
*/
hal_ret_t bsp_module_get_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t* priority);
#endif /* BSP_MODULE_H */

View File

@ -64,30 +64,34 @@ const bsp_board_config_t* bsp_board_get_by_name(const char* name) {
/** /**
* @brief Set current board configuration by index * @brief Set current board configuration by index
* @param index: Board configuration index * @param index: Board configuration index
* @retval 0 if successful, -1 if invalid index * @retval HAL status code
*/ */
int8_t bsp_board_set_by_index(uint8_t index) { hal_ret_t bsp_board_set_by_index(uint8_t index) {
if (index < bsp_board_get_count()) { if (index < bsp_board_get_count()) {
current_board_index = index; current_board_index = index;
return 0; return HAL_RET_OK;
} }
return -1; return HAL_RET_INVALID_PARAM;
} }
/** /**
* @brief Set current board configuration by name * @brief Set current board configuration by name
* @param name: Board name string * @param name: Board name string
* @retval 0 if successful, -1 if not found * @retval HAL status code
*/ */
int8_t bsp_board_set_by_name(const char* name) { hal_ret_t bsp_board_set_by_name(const char* name) {
if (name == NULL) {
return HAL_RET_INVALID_PARAM;
}
for (uint8_t i = 0; i < bsp_board_get_count(); i++) { for (uint8_t i = 0; i < bsp_board_get_count(); i++) {
if (supported_boards[i]->name != NULL && if (supported_boards[i]->name != NULL &&
strcmp(supported_boards[i]->name, name) == 0) { strcmp(supported_boards[i]->name, name) == 0) {
current_board_index = i; current_board_index = i;
return 0; return HAL_RET_OK;
} }
} }
return -1; return HAL_RET_ERROR;
} }
/** /**

653
BSP/Src/bsp_config.c Normal file
View File

@ -0,0 +1,653 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : bsp_config.c
* @brief : Board support package configuration file source
******************************************************************************
*/
/* USER CODE END Header */
#include "bsp_config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/**
* @brief Configuration storage entry
*/
typedef struct bsp_config_storage_entry {
char section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH];
char key[BSP_CONFIG_MAX_KEY_NAME_LENGTH];
char value[BSP_CONFIG_MAX_VALUE_LENGTH];
struct bsp_config_storage_entry* next;
} bsp_config_storage_entry_t;
/**
* @brief Configuration storage
*/
typedef struct {
bsp_config_storage_entry_t* entries;
uint32_t entry_count;
uint8_t initialized;
} bsp_config_storage_t;
/**
* @brief Configuration storage instance
*/
static bsp_config_storage_t bsp_config_storage = {
.entries = NULL,
.entry_count = 0,
.initialized = 0
};
/**
* @brief Trim whitespace from a string
* @param str: String to trim
* @return Trimmed string
*/
static char* bsp_config_trim(char* str) {
char* end;
// Trim leading whitespace
while (isspace((unsigned char)*str)) {
str++;
}
if (*str == 0) {
return str;
}
// Trim trailing whitespace
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) {
end--;
}
// Null terminate
*(end + 1) = 0;
return str;
}
/**
* @brief Open configuration file
* @param filename: Configuration file name
* @param parser: Parser context
* @retval HAL status code
*/
static hal_ret_t bsp_config_file_open(const char* filename, bsp_config_parser_t* parser) {
if (filename == NULL || parser == NULL) {
return HAL_INVALID_PARAM;
}
parser->file = fopen(filename, "r");
if (parser->file == NULL) {
return HAL_ERROR;
}
memset(parser->current_section, 0, sizeof(parser->current_section));
memset(parser->buffer, 0, sizeof(parser->buffer));
parser->line_number = 0;
parser->initialized = 1;
return HAL_OK;
}
/**
* @brief Close configuration file
* @param parser: Parser context
* @retval HAL status code
*/
static hal_ret_t bsp_config_file_close(bsp_config_parser_t* parser) {
if (parser == NULL || !parser->initialized) {
return HAL_INVALID_PARAM;
}
if (parser->file != NULL) {
fclose(parser->file);
parser->file = NULL;
}
parser->initialized = 0;
return HAL_OK;
}
/**
* @brief Read a configuration entry from file
* @param parser: Parser context
* @param entry: Configuration entry
* @retval HAL status code
*/
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) {
return HAL_INVALID_PARAM;
}
if (parser->file == NULL) {
return HAL_ERROR;
}
while (fgets(parser->buffer, sizeof(parser->buffer), parser->file) != NULL) {
parser->line_number++;
char* line = bsp_config_trim(parser->buffer);
size_t len = strlen(line);
// Skip empty lines and comments
if (len == 0 || line[0] == '#') {
continue;
}
// Check for section header
if (line[0] == '[' && line[len - 1] == ']') {
// Extract section name
memset(parser->current_section, 0, sizeof(parser->current_section));
strncpy(parser->current_section, line + 1, len - 2);
parser->current_section[len - 2] = '\0';
continue;
}
// Check for key-value pair
char* equals = strchr(line, '=');
if (equals != NULL) {
// Extract key and value
*equals = '\0';
char* key = bsp_config_trim(line);
char* value = bsp_config_trim(equals + 1);
entry->section = parser->current_section;
entry->key = key;
entry->value = value;
return HAL_OK;
}
}
return HAL_TIMEOUT;
}
/**
* @brief Parse integer value
* @param value: String value to parse
* @param result: Pointer to store result
* @retval HAL status code
*/
static hal_ret_t bsp_config_parse_int(const char* value, int* result) {
if (value == NULL || result == NULL) {
return HAL_INVALID_PARAM;
}
char* endptr;
long val = strtol(value, &endptr, 0);
if (*endptr != '\0') {
return HAL_ERROR;
}
*result = (int)val;
return HAL_OK;
}
/**
* @brief Parse unsigned integer value
* @param value: String value to parse
* @param result: Pointer to store result
* @retval HAL status code
*/
static hal_ret_t bsp_config_parse_uint(const char* value, uint32_t* result) {
if (value == NULL || result == NULL) {
return HAL_INVALID_PARAM;
}
char* endptr;
unsigned long val = strtoul(value, &endptr, 0);
if (*endptr != '\0') {
return HAL_ERROR;
}
*result = (uint32_t)val;
return HAL_OK;
}
/**
* @brief Parse boolean value
* @param value: String value to parse
* @param result: Pointer to store result
* @retval HAL status code
*/
static hal_ret_t bsp_config_parse_bool(const char* value, uint8_t* result) {
if (value == NULL || result == NULL) {
return HAL_INVALID_PARAM;
}
if (strcmp(value, "true") == 0 || strcmp(value, "TRUE") == 0 ||
strcmp(value, "1") == 0 || strcmp(value, "yes") == 0 ||
strcmp(value, "YES") == 0) {
*result = 1;
return HAL_OK;
} else if (strcmp(value, "false") == 0 || strcmp(value, "FALSE") == 0 ||
strcmp(value, "0") == 0 || strcmp(value, "no") == 0 ||
strcmp(value, "NO") == 0) {
*result = 0;
return HAL_OK;
}
return HAL_ERROR;
}
/**
* @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
*/
static hal_ret_t bsp_config_parse_string(const char* value, char* result, size_t max_length) {
if (value == NULL || result == NULL) {
return HAL_INVALID_PARAM;
}
strncpy(result, value, max_length - 1);
result[max_length - 1] = '\0';
return HAL_OK;
}
/**
* @brief Add a configuration entry to storage
* @param section: Section name
* @param key: Key name
* @param value: Value
* @retval HAL status code
*/
static hal_ret_t bsp_config_storage_add(const char* section, const char* key, const char* value) {
// Check if entry already exists
bsp_config_storage_entry_t* entry = bsp_config_storage.entries;
while (entry != NULL) {
if (strcmp(entry->section, section) == 0 && strcmp(entry->key, key) == 0) {
// Update existing entry
strncpy(entry->value, value, sizeof(entry->value) - 1);
entry->value[sizeof(entry->value) - 1] = '\0';
return HAL_OK;
}
entry = entry->next;
}
// Create new entry
bsp_config_storage_entry_t* new_entry = malloc(sizeof(bsp_config_storage_entry_t));
if (new_entry == NULL) {
return HAL_OUT_OF_MEMORY;
}
strncpy(new_entry->section, section, sizeof(new_entry->section) - 1);
strncpy(new_entry->key, key, sizeof(new_entry->key) - 1);
strncpy(new_entry->value, value, sizeof(new_entry->value) - 1);
new_entry->section[sizeof(new_entry->section) - 1] = '\0';
new_entry->key[sizeof(new_entry->key) - 1] = '\0';
new_entry->value[sizeof(new_entry->value) - 1] = '\0';
new_entry->next = NULL;
// Add to list
if (bsp_config_storage.entries == NULL) {
bsp_config_storage.entries = new_entry;
} else {
entry = bsp_config_storage.entries;
while (entry->next != NULL) {
entry = entry->next;
}
entry->next = new_entry;
}
bsp_config_storage.entry_count++;
return HAL_OK;
}
/**
* @brief Clear configuration storage
*/
static void bsp_config_storage_clear(void) {
bsp_config_storage_entry_t* entry = bsp_config_storage.entries;
while (entry != NULL) {
bsp_config_storage_entry_t* next = entry->next;
free(entry);
entry = next;
}
bsp_config_storage.entries = NULL;
bsp_config_storage.entry_count = 0;
}
/**
* @brief Initialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_init(void) {
if (bsp_config_storage.initialized) {
return HAL_OK;
}
bsp_config_storage_clear();
bsp_config_storage.initialized = 1;
return HAL_OK;
}
/**
* @brief Deinitialize BSP configuration system
* @retval HAL status code
*/
hal_ret_t bsp_config_deinit(void) {
if (!bsp_config_storage.initialized) {
return HAL_OK;
}
bsp_config_storage_clear();
bsp_config_storage.initialized = 0;
return HAL_OK;
}
/**
* @brief Load BSP configuration from file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_config_load(const char* filename) {
if (!bsp_config_storage.initialized) {
hal_ret_t status = bsp_config_init();
if (status != HAL_OK) {
return status;
}
}
bsp_config_parser_t parser;
hal_ret_t status = bsp_config_file_open(filename, &parser);
if (status != HAL_OK) {
return status;
}
bsp_config_entry_t entry;
while ((status = bsp_config_file_read_entry(&parser, &entry)) == HAL_OK) {
status = bsp_config_storage_add(entry.section, entry.key, entry.value);
if (status != HAL_OK) {
bsp_config_file_close(&parser);
return status;
}
}
if (status != HAL_TIMEOUT) {
bsp_config_file_close(&parser);
return status;
}
status = bsp_config_file_close(&parser);
if (status != HAL_OK) {
return status;
}
return HAL_OK;
}
/**
* @brief Save BSP configuration to file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_config_save(const char* filename) {
if (!bsp_config_storage.initialized || bsp_config_storage.entry_count == 0) {
return HAL_OK;
}
FILE* file = fopen(filename, "w");
if (file == NULL) {
return HAL_ERROR;
}
fprintf(file, "# BSP Configuration File\n");
fprintf(file, "# Version: %s\n\n", BSP_CONFIG_FILE_VERSION);
char current_section[BSP_CONFIG_MAX_SECTION_NAME_LENGTH] = "";
bsp_config_storage_entry_t* entry = bsp_config_storage.entries;
while (entry != NULL) {
if (strcmp(entry->section, current_section) != 0) {
// New section
strncpy(current_section, entry->section, sizeof(current_section) - 1);
fprintf(file, "[%s]\n", current_section);
}
fprintf(file, "%s=%s\n", entry->key, entry->value);
entry = entry->next;
}
fclose(file);
return HAL_OK;
}
/**
* @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
*/
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) {
return HAL_INVALID_PARAM;
}
bsp_config_storage_entry_t* entry = bsp_config_storage.entries;
while (entry != NULL) {
if (strcmp(entry->section, section) == 0 && strcmp(entry->key, key) == 0) {
strncpy(value, entry->value, max_length - 1);
value[max_length - 1] = '\0';
return HAL_OK;
}
entry = entry->next;
}
return HAL_NOT_SUPPORTED;
}
/**
* @brief Set configuration value
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Configuration value
* @retval HAL status code
*/
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) {
return HAL_INVALID_PARAM;
}
return bsp_config_storage_add(section, key, value);
}
/**
* @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
*/
hal_ret_t bsp_config_get_int(const char* section, const char* key, int* value) {
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
hal_ret_t status = bsp_config_get_value(section, key, str_value, sizeof(str_value));
if (status != HAL_OK) {
return status;
}
return bsp_config_parse_int(str_value, 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
*/
hal_ret_t bsp_config_set_int(const char* section, const char* key, int value) {
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
snprintf(str_value, sizeof(str_value), "%d", value);
return bsp_config_set_value(section, key, str_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
*/
hal_ret_t bsp_config_get_uint(const char* section, const char* key, uint32_t* value) {
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
hal_status_t status = bsp_config_get_value(section, key, str_value, sizeof(str_value));
if (status != HAL_OK) {
return status;
}
return bsp_config_parse_uint(str_value, value);
}
/**
* @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
*/
hal_ret_t bsp_config_set_uint(const char* section, const char* key, uint32_t value) {
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
snprintf(str_value, sizeof(str_value), "%lu", (unsigned long)value);
return bsp_config_set_value(section, key, str_value);
}
/**
* @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
*/
hal_ret_t bsp_config_get_bool(const char* section, const char* key, uint8_t* value) {
char str_value[BSP_CONFIG_MAX_VALUE_LENGTH];
hal_status_t status = bsp_config_get_value(section, key, str_value, sizeof(str_value));
if (status != HAL_OK) {
return status;
}
return bsp_config_parse_bool(str_value, value);
}
/**
* @brief Set configuration value as boolean
* @param section: Configuration section name
* @param key: Configuration key name
* @param value: Boolean value
* @retval HAL status code
*/
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
*/
hal_ret_t bsp_config_parse_modules(bsp_board_config_t* config) {
if (config == NULL) {
return HAL_INVALID_PARAM;
}
// TODO: Implement module parsing logic
// This will depend on the specific configuration file format
// and how modules are defined in the configuration
return HAL_OK;
}
/**
* @brief Initialize BSP from configuration file
* @param filename: Configuration file name
* @retval HAL status code
*/
hal_ret_t bsp_init_from_config(const char* filename) {
// Load configuration file
hal_ret_t status = bsp_config_load(filename);
if (status != HAL_OK) {
return status;
}
// Initialize HAL layer
status = hal_init();
if (status != HAL_OK) {
return status;
}
// Initialize BSP module manager
status = bsp_module_manager_init();
if (status != HAL_OK) {
return status;
}
// Create board configuration from file
bsp_board_config_t board_config;
memset(&board_config, 0, sizeof(board_config));
// Parse board information
char board_name[64];
status = bsp_config_get_value("board", "name", board_name, sizeof(board_name));
if (status == HAL_OK) {
board_config.name = strdup(board_name);
} else {
board_config.name = "Unknown";
}
uint32_t version = BSP_CONFIG_VERSION;
status = bsp_config_get_uint("board", "version", &version);
if (status == HAL_OK) {
board_config.version = version;
} else {
board_config.version = BSP_CONFIG_VERSION;
}
// Parse modules from configuration
status = bsp_config_parse_modules(&board_config);
if (status != HAL_OK) {
return status;
}
// Initialize board
status = bsp_board_init();
if (status != HAL_OK) {
return status;
}
// Initialize all modules
status = bsp_module_init_all();
if (status != HAL_OK) {
return status;
}
// Configure all modules
// TODO: Implement module configuration from file
// Start all modules
status = bsp_module_start_all();
if (status != HAL_OK) {
return status;
}
return HAL_OK;
}

View File

@ -16,20 +16,29 @@
/** /**
* @brief Initialize board support package * @brief Initialize board support package
* @retval HAL status code
*/ */
void bsp_init(void) { hal_ret_t bsp_init(void) {
/* Get board configuration */ /* Get board configuration */
const bsp_board_config_t* board_config = bsp_board_get_config(); const bsp_board_config_t* board_config = bsp_board_get_config();
hal_ret_t status = HAL_RET_OK;
uint8_t i;
/* Initialize HAL layer */ /* Initialize HAL layer */
hal_init(); status = hal_init();
if (status != HAL_RET_OK) {
return status;
}
/* Initialize peripherals based on configuration */ /* Initialize peripherals based on configuration */
/* Initialize LED */ /* Initialize LED */
if (board_config->led_init != NULL) { if (board_config->led.enable && board_config->init_funcs.led_init != NULL) {
board_config->led_init(&board_config->led); status = board_config->init_funcs.led_init(&board_config->led);
} else { if (status != HAL_RET_OK) {
return status;
}
} else if (board_config->led.enable) {
/* Use default initialization if no function provided */ /* Use default initialization if no function provided */
hal_gpio_config_t gpio_config = { hal_gpio_config_t gpio_config = {
.port = board_config->led.port, .port = board_config->led.port,
@ -38,34 +47,103 @@ void bsp_init(void) {
.speed = board_config->led.speed, .speed = board_config->led.speed,
.pull = board_config->led.pull .pull = board_config->led.pull
}; };
hal_gpio_configure_pin(&gpio_config); status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
} }
/* Initialize Buttons */ /* Initialize Buttons */
if (board_config->button_init != NULL) { if (board_config->buttons.enable && board_config->init_funcs.button_init != NULL) {
board_config->button_init(&board_config->buttons); status = board_config->init_funcs.button_init(&board_config->buttons);
if (status != HAL_RET_OK) {
return status;
}
} }
/* Initialize UART */ /* Initialize UARTs */
if (board_config->uart_init != NULL) { if (board_config->init_funcs.uart_init != NULL) {
board_config->uart_init(&board_config->uart); for (i = 0; i < board_config->periphs.uart_count; i++) {
if (board_config->periphs.uarts[i].enable) {
status = board_config->init_funcs.uart_init(&board_config->periphs.uarts[i]);
if (status != HAL_RET_OK) {
return status;
}
}
}
} }
/* Initialize W25QXX if available */ /* Initialize SPIs */
if (board_config->w25qxx_init != NULL) { if (board_config->init_funcs.spi_init != NULL) {
board_config->w25qxx_init(&board_config->w25qxx); for (i = 0; i < board_config->periphs.spi_count; i++) {
if (board_config->periphs.spis[i].enable) {
status = board_config->init_funcs.spi_init(&board_config->periphs.spis[i]);
if (status != HAL_RET_OK) {
return status;
} }
}
}
}
/* Initialize I2Cs */
if (board_config->init_funcs.i2c_init != NULL) {
for (i = 0; i < board_config->periphs.i2c_count; i++) {
if (board_config->periphs.i2cs[i].enable) {
status = board_config->init_funcs.i2c_init(&board_config->periphs.i2cs[i]);
if (status != HAL_RET_OK) {
return status;
}
}
}
}
/* Initialize CANs */
if (board_config->init_funcs.can_init != NULL) {
for (i = 0; i < board_config->periphs.can_count; i++) {
if (board_config->periphs.cans[i].enable) {
status = board_config->init_funcs.can_init(&board_config->periphs.cans[i]);
if (status != HAL_RET_OK) {
return status;
}
}
}
}
/* Initialize ADCs */
if (board_config->init_funcs.adc_init != NULL) {
for (i = 0; i < board_config->periphs.adc_count; i++) {
if (board_config->periphs.adcs[i].enable) {
status = board_config->init_funcs.adc_init(&board_config->periphs.adcs[i]);
if (status != HAL_RET_OK) {
return status;
}
}
}
}
/* Initialize W25QXX if available and enabled */
if (board_config->w25qxx.enable && board_config->init_funcs.w25qxx_init != NULL) {
status = board_config->init_funcs.w25qxx_init(&board_config->w25qxx);
if (status != HAL_RET_OK) {
return status;
}
}
return status;
} }
/** /**
* @brief Initialize board GPIO using configuration * @brief Initialize board GPIO using configuration
* @retval HAL status code
*/ */
void bsp_gpio_init(void) { hal_ret_t bsp_gpio_init(void) {
/* Get board configuration */ /* Get board configuration */
const bsp_board_config_t* board_config = bsp_board_get_config(); const bsp_board_config_t* board_config = bsp_board_get_config();
hal_ret_t status = HAL_RET_OK;
uint8_t i; uint8_t i;
/* Initialize LED GPIO */ /* Initialize LED GPIO */
if (board_config->led.enable) {
hal_gpio_config_t gpio_config = { hal_gpio_config_t gpio_config = {
.port = board_config->led.port, .port = board_config->led.port,
.pin = board_config->led.pin, .pin = board_config->led.pin,
@ -73,18 +151,100 @@ void bsp_gpio_init(void) {
.speed = board_config->led.speed, .speed = board_config->led.speed,
.pull = board_config->led.pull .pull = board_config->led.pull
}; };
hal_gpio_configure_pin(&gpio_config); status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
}
/* Initialize Buttons GPIO */ /* Initialize Buttons GPIO */
if (board_config->buttons.enable) {
for (i = 0; i < board_config->buttons.count; i++) { for (i = 0; i < board_config->buttons.count; i++) {
const bsp_button_config_t* button = &board_config->buttons.buttons[i]; const bsp_button_config_t* button = &board_config->buttons.buttons[i];
gpio_config.port = button->port; hal_gpio_config_t gpio_config = {
gpio_config.pin = button->pin; .port = button->port,
gpio_config.mode = button->mode; .pin = button->pin,
gpio_config.speed = button->speed; .mode = button->mode,
gpio_config.pull = button->pull; .speed = button->speed,
hal_gpio_configure_pin(&gpio_config); .pull = button->pull
};
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
} }
}
}
/* Initialize UART GPIOs */
for (i = 0; i < board_config->periphs.uart_count; i++) {
if (board_config->periphs.uarts[i].enable) {
/* Initialize TX pin */
hal_gpio_config_t gpio_config = {
.port = board_config->periphs.uarts[i].tx_port,
.pin = board_config->periphs.uarts[i].tx_pin,
.mode = HAL_GPIO_MODE_AF_PP,
.speed = HAL_GPIO_SPEED_HIGH,
.pull = HAL_GPIO_PULL_NO
};
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
/* Initialize RX pin */
gpio_config.port = board_config->periphs.uarts[i].rx_port;
gpio_config.pin = board_config->periphs.uarts[i].rx_pin;
gpio_config.mode = HAL_GPIO_MODE_AF_PP;
gpio_config.speed = HAL_GPIO_SPEED_HIGH;
gpio_config.pull = HAL_GPIO_PULL_UP;
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
}
}
/* Initialize SPI GPIOs */
for (i = 0; i < board_config->periphs.spi_count; i++) {
if (board_config->periphs.spis[i].enable) {
/* Initialize SCK pin */
hal_gpio_config_t gpio_config = {
.port = board_config->periphs.spis[i].sck_port,
.pin = board_config->periphs.spis[i].sck_pin,
.mode = HAL_GPIO_MODE_AF_PP,
.speed = HAL_GPIO_SPEED_HIGH,
.pull = HAL_GPIO_PULL_NO
};
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
/* Initialize MISO pin */
gpio_config.port = board_config->periphs.spis[i].miso_port;
gpio_config.pin = board_config->periphs.spis[i].miso_pin;
gpio_config.mode = HAL_GPIO_MODE_AF_PP;
gpio_config.speed = HAL_GPIO_SPEED_HIGH;
gpio_config.pull = HAL_GPIO_PULL_UP;
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
/* Initialize MOSI pin */
gpio_config.port = board_config->periphs.spis[i].mosi_port;
gpio_config.pin = board_config->periphs.spis[i].mosi_pin;
gpio_config.mode = HAL_GPIO_MODE_AF_PP;
gpio_config.speed = HAL_GPIO_SPEED_HIGH;
gpio_config.pull = HAL_GPIO_PULL_NO;
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
return status;
}
}
}
return status;
} }
/** /**

View File

@ -156,8 +156,8 @@ void bsp_key_init(void) {
} }
/* Call board-specific button initialization if available */ /* Call board-specific button initialization if available */
if (board_config && board_config->button_init) { if (board_config && board_config->init_funcs.button_init) {
board_config->button_init(&board_config->buttons); board_config->init_funcs.button_init(&board_config->buttons);
} }
} }

795
BSP/Src/bsp_module.c Normal file
View File

@ -0,0 +1,795 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : bsp_module.c
* @brief : Board support package module management source file
******************************************************************************
*/
/* USER CODE END Header */
#include "bsp_module.h"
#include <string.h>
/**
* @brief Module manager instance
*/
static bsp_module_manager_t bsp_module_manager;
/**
* @brief Initialize BSP module manager
* @retval HAL status code
*/
hal_ret_t bsp_module_manager_init(void) {
/* Clear module manager */
memset(&bsp_module_manager, 0, sizeof(bsp_module_manager));
/* Initialize module arrays */
for (uint8_t i = 0; i < BSP_MODULE_TYPE_MAX; i++) {
bsp_module_manager.modules[i] = NULL;
}
bsp_module_manager.module_list = NULL;
bsp_module_manager.module_count = 0;
return HAL_RET_OK;
}
/**
* @brief Register a BSP module
* @param module: Pointer to module structure
* @retval HAL status code
*/
hal_ret_t bsp_module_register(bsp_module_t* module) {
if (module == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (module->config.type >= BSP_MODULE_TYPE_MAX) {
return HAL_INVALID_PARAM;
}
/* Check if module already exists */
if (bsp_module_get(module->config.type, module->config.instance) != NULL) {
return HAL_RESOURCE_LOCKED;
}
/* Initialize module state */
module->state = BSP_MODULE_STATE_UNINIT;
module->next = NULL;
module->prev = NULL;
/* Add module to the linked list */
if (bsp_module_manager.module_list == NULL) {
bsp_module_manager.module_list = module;
} else {
/* Insert module at the end of the list */
bsp_module_t* current = bsp_module_manager.module_list;
while (current->next != NULL) {
current = current->next;
}
current->next = module;
module->prev = current;
}
/* Add module to the type-specific list */
if (bsp_module_manager.modules[module->config.type] == NULL) {
bsp_module_manager.modules[module->config.type] = module;
} else {
/* Insert module at the end of the type-specific list */
bsp_module_t* current = bsp_module_manager.modules[module->config.type];
while (current->next != NULL && current->config.type == module->config.type) {
current = current->next;
}
if (current->config.type == module->config.type) {
current->next = module;
module->prev = current;
} else {
/* Insert between current->prev and current */
if (current->prev != NULL) {
current->prev->next = module;
} else {
bsp_module_manager.modules[module->config.type] = module;
}
module->prev = current->prev;
module->next = current;
current->prev = module;
}
}
bsp_module_manager.module_count++;
return HAL_OK;
}
/**
* @brief Unregister a BSP module
* @param module: Pointer to module structure
* @retval HAL status code
*/
hal_ret_t bsp_module_unregister(bsp_module_t* module) {
if (module == NULL) {
return HAL_INVALID_PARAM;
}
/* Deinitialize module if it's initialized */
if (module->state != BSP_MODULE_STATE_UNINIT) {
if (module->ops.deinit != NULL) {
module->ops.deinit();
}
module->state = BSP_MODULE_STATE_UNINIT;
}
/* Remove module from linked list */
if (module->prev != NULL) {
module->prev->next = module->next;
} else {
/* Module is first in the list */
bsp_module_manager.module_list = module->next;
}
if (module->next != NULL) {
module->next->prev = module->prev;
}
/* Remove module from type-specific list */
if (bsp_module_manager.modules[module->config.type] == module) {
bsp_module_manager.modules[module->config.type] = module->next;
}
/* Reset module pointers */
module->next = NULL;
module->prev = NULL;
bsp_module_manager.module_count--;
return HAL_OK;
}
/**
* @brief Get a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval Pointer to module structure, or NULL if not found
*/
bsp_module_t* bsp_module_get(bsp_module_type_t type, uint8_t instance) {
if (type >= BSP_MODULE_TYPE_MAX) {
return NULL;
}
bsp_module_t* current = bsp_module_manager.modules[type];
while (current != NULL && current->config.type == type) {
if (current->config.instance == instance) {
return current;
}
current = current->next;
}
return NULL;
}
/**
* @brief Get all modules of a specific type
* @param type: Module type
* @retval Pointer to module list, or NULL if no modules found
*/
bsp_module_t* bsp_module_get_by_type(bsp_module_type_t type) {
if (type >= BSP_MODULE_TYPE_MAX) {
return NULL;
}
return bsp_module_manager.modules[type];
}
/**
* @brief Get module by name
* @param name: Module name
* @retval Pointer to module structure, or NULL if not found
*/
bsp_module_t* bsp_module_get_by_name(const char* name) {
if (name == NULL) {
return NULL;
}
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.name != NULL && strcmp(current->config.name, name) == 0) {
return current;
}
current = current->next;
}
return NULL;
}
/**
* @brief Check if all dependencies of a module are satisfied
* @param module: Pointer to module structure
* @retval HAL status code
*/
hal_ret_t bsp_module_check_dependencies(const bsp_module_t* module) {
if (module == NULL) {
return HAL_INVALID_PARAM;
}
/* Check if dependencies are satisfied */
if (module->config.dependencies == 0) {
/* No dependencies */
return HAL_OK;
}
/* Check each dependency bit */
for (uint8_t i = 0; i < BSP_MODULE_TYPE_MAX; i++) {
if (module->config.dependencies & (1 << i)) {
/* Check if dependency module exists and is initialized */
bsp_module_t* dep_module = bsp_module_manager.modules[i];
if (dep_module == NULL) {
return HAL_RET_ERROR;
}
/* Check if at least one instance is initialized */
bsp_module_t* current = dep_module;
uint8_t dep_found = 0;
while (current != NULL && current->config.type == i) {
if (current->state >= BSP_MODULE_STATE_INIT) {
dep_found = 1;
break;
}
current = current->next;
}
if (!dep_found) {
return HAL_ERROR;
}
}
}
return HAL_OK;
}
/**
* @brief Initialize a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_init(bsp_module_type_t type, uint8_t instance) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is already initialized */
if (module->state != BSP_MODULE_STATE_UNINIT) {
return HAL_OK;
}
/* Check dependencies */
hal_ret_t status = bsp_module_check_dependencies(module);
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
/* Initialize module */
if (module->ops.init != NULL) {
status = module->ops.init(module->config.config_data);
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
}
module->state = BSP_MODULE_STATE_INIT;
return HAL_OK;
}
/**
* @brief Deinitialize a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_deinit(bsp_module_type_t type, uint8_t instance) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is already uninitialized */
if (module->state == BSP_MODULE_STATE_UNINIT) {
return HAL_OK;
}
/* Stop module if it's running */
if (module->state == BSP_MODULE_STATE_RUNNING && module->ops.stop != NULL) {
module->ops.stop();
}
/* Deinitialize module */
if (module->ops.deinit != NULL) {
hal_ret_t status = module->ops.deinit();
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
}
module->state = BSP_MODULE_STATE_UNINIT;
return HAL_OK;
}
/**
* @brief Configure a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param config: Module configuration data
* @param size: Module configuration size
* @retval HAL status code
*/
hal_ret_t bsp_module_configure(bsp_module_type_t type, uint8_t instance, void* config, size_t size) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is initialized */
if (module->state < BSP_MODULE_STATE_INIT) {
return HAL_ERROR;
}
/* Configure module */
if (module->ops.configure != NULL) {
hal_ret_t status = module->ops.configure(config);
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
}
module->state = BSP_MODULE_STATE_CONFIGURED;
return HAL_OK;
}
/**
* @brief Start a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_start(bsp_module_type_t type, uint8_t instance) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is configured */
if (module->state < BSP_MODULE_STATE_CONFIGURED) {
return HAL_ERROR;
}
/* Start module */
if (module->ops.start != NULL) {
hal_ret_t status = module->ops.start();
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
}
module->state = BSP_MODULE_STATE_RUNNING;
return HAL_OK;
}
/**
* @brief Stop a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_stop(bsp_module_type_t type, uint8_t instance) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is running */
if (module->state != BSP_MODULE_STATE_RUNNING) {
return HAL_OK;
}
/* Stop module */
if (module->ops.stop != NULL) {
hal_ret_t status = module->ops.stop();
if (status != HAL_OK) {
module->state = BSP_MODULE_STATE_ERROR;
return status;
}
}
module->state = BSP_MODULE_STATE_CONFIGURED;
return HAL_OK;
}
/**
* @brief Reset a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @retval HAL status code
*/
hal_ret_t bsp_module_reset(bsp_module_type_t type, uint8_t instance) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Stop module if it's running */
hal_ret_t status = bsp_module_stop(type, instance);
if (status != HAL_OK) {
return status;
}
/* Deinitialize module */
status = bsp_module_deinit(type, instance);
if (status != HAL_OK) {
return status;
}
/* Reinitialize module */
status = bsp_module_init(type, instance);
if (status != HAL_OK) {
return status;
}
/* Configure module */
if (module->config.config_data != NULL) {
status = bsp_module_configure(type, instance, module->config.config_data, module->config.config_size);
if (status != HAL_OK) {
return status;
}
}
/* Start module */
status = bsp_module_start(type, instance);
if (status != HAL_OK) {
return status;
}
return HAL_OK;
}
/**
* @brief Get state of a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param state: Pointer to store module state
* @retval HAL status code
*/
hal_ret_t bsp_module_get_state(bsp_module_type_t type, uint8_t instance, bsp_module_state_t* state) {
if (state == NULL) {
return HAL_INVALID_PARAM;
}
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
*state = BSP_MODULE_STATE_UNINIT;
return HAL_ERROR;
}
*state = module->state;
return HAL_OK;
}
/**
* @brief Control a specific BSP module
* @param type: Module type
* @param instance: Module instance
* @param cmd: Control command
* @param param: Control parameter
* @retval HAL status code
*/
hal_ret_t bsp_module_control(bsp_module_type_t type, uint8_t instance, uint32_t cmd, void* param) {
/* Get module */
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
/* Check if module is initialized */
if (module->state < BSP_MODULE_STATE_INIT) {
return HAL_ERROR;
}
/* Control module */
if (module->ops.control != NULL) {
return module->ops.control(cmd, param);
}
return HAL_RET_NOT_SUPPORTED;
}
/**
* @brief Initialize all registered BSP modules in priority order
* @retval HAL status code
*/
hal_ret_t bsp_module_init_all(void) {
hal_ret_t status = HAL_RET_OK;
/* Initialize modules by priority */
for (uint8_t priority = BSP_MODULE_PRIORITY_HIGHEST; priority <= BSP_MODULE_PRIORITY_LOWEST; priority++) {
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.priority == priority) {
status = bsp_module_init(current->config.type, current->config.instance);
if (status != HAL_OK) {
return status;
}
}
current = current->next;
}
}
return status;
}
/**
* @brief Deinitialize all registered BSP modules in reverse priority order
* @retval HAL status code
*/
hal_ret_t bsp_module_deinit_all(void) {
hal_status_t status = HAL_OK;
/* Deinitialize modules by reverse priority */
for (int8_t priority = BSP_MODULE_PRIORITY_LOWEST; priority >= BSP_MODULE_PRIORITY_HIGHEST; priority--) {
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.priority == priority) {
status = bsp_module_deinit(current->config.type, current->config.instance);
if (status != HAL_OK) {
return status;
}
}
current = current->next;
}
}
return status;
}
/**
* @brief Start all registered BSP modules in priority order
* @retval HAL status code
*/
hal_ret_t bsp_module_start_all(void) {
hal_status_t status = HAL_OK;
/* Start modules by priority */
for (uint8_t priority = BSP_MODULE_PRIORITY_HIGHEST; priority <= BSP_MODULE_PRIORITY_LOWEST; priority++) {
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.priority == priority && current->state >= BSP_MODULE_STATE_CONFIGURED) {
status = bsp_module_start(current->config.type, current->config.instance);
if (status != HAL_OK) {
return status;
}
}
current = current->next;
}
}
return status;
}
/**
* @brief Stop all registered BSP modules in reverse priority order
* @retval HAL status code
*/
hal_ret_t bsp_module_stop_all(void) {
hal_status_t status = HAL_OK;
/* Stop modules by reverse priority */
for (int8_t priority = BSP_MODULE_PRIORITY_LOWEST; priority >= BSP_MODULE_PRIORITY_HIGHEST; priority--) {
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.priority == priority && current->state == BSP_MODULE_STATE_RUNNING) {
status = bsp_module_stop(current->config.type, current->config.instance);
if (status != HAL_OK) {
return status;
}
}
current = current->next;
}
}
return status;
}
/**
* @brief Get total number of registered modules
* @retval Number of registered modules
*/
uint32_t bsp_module_get_count(void) {
return bsp_module_manager.module_count;
}
/**
* @brief Get module manager instance
* @retval Pointer to module manager structure
*/
bsp_module_manager_t* bsp_module_get_manager(void) {
return &bsp_module_manager;
}
/**
* @brief Register a module event callback
* @param type: Module type
* @param instance: Module instance
* @param callback: Event callback function
* @retval HAL status code
*/
hal_ret_t bsp_module_register_event_callback(bsp_module_type_t type, uint8_t instance, bsp_module_event_callback_t callback) {
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
module->event_callback = callback;
return HAL_OK;
}
/**
* @brief Trigger a module event
* @param module: Pointer to module structure
* @param event: Event to trigger
* @param data: Event data
* @retval HAL status code
*/
hal_ret_t bsp_module_trigger_event(const bsp_module_t* module, uint32_t event, void* data) {
if (module == NULL) {
return HAL_INVALID_PARAM;
}
// Check if module has an event callback registered
if (module->event_callback != NULL) {
return module->event_callback(module, event, data);
}
return HAL_OK;
}
/**
* @brief Find modules by priority range
* @param min_priority: Minimum priority
* @param max_priority: Maximum priority
* @param count: Pointer to store number of modules found
* @retval Pointer to array of module pointers, or NULL if no modules found
*/
bsp_module_t** bsp_module_find_by_priority_range(bsp_module_priority_t min_priority, bsp_module_priority_t max_priority, uint32_t* count) {
if (count == NULL) {
return NULL;
}
// First pass: count matching modules
uint32_t module_count = 0;
bsp_module_t* current = bsp_module_manager.module_list;
while (current != NULL) {
if (current->config.priority >= min_priority && current->config.priority <= max_priority) {
module_count++;
}
current = current->next;
}
if (module_count == 0) {
*count = 0;
return NULL;
}
// Second pass: allocate and fill array
bsp_module_t** modules = (bsp_module_t**)malloc(module_count * sizeof(bsp_module_t*));
if (modules == NULL) {
*count = 0;
return NULL;
}
uint32_t index = 0;
current = bsp_module_manager.module_list;
while (current != NULL && index < module_count) {
if (current->config.priority >= min_priority && current->config.priority <= max_priority) {
modules[index++] = current;
}
current = current->next;
}
*count = module_count;
return modules;
}
/**
* @brief Set module enable/disable state
* @param type: Module type
* @param instance: Module instance
* @param enable: Enable flag
* @retval HAL status code
*/
hal_ret_t bsp_module_set_enable(bsp_module_type_t type, uint8_t instance, uint8_t enable) {
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
module->config.enable = enable;
return HAL_OK;
}
/**
* @brief Check if module is enabled
* @param type: Module type
* @param instance: Module instance
* @param enable: Pointer to store enable state
* @retval HAL status code
*/
hal_ret_t bsp_module_is_enabled(bsp_module_type_t type, uint8_t instance, uint8_t* enable) {
if (enable == NULL) {
return HAL_INVALID_PARAM;
}
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
*enable = 0;
return HAL_ERROR;
}
*enable = module->config.enable;
return HAL_OK;
}
/**
* @brief Set module priority
* @param type: Module type
* @param instance: Module instance
* @param priority: New priority
* @retval HAL status code
*/
hal_ret_t bsp_module_set_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t priority) {
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
return HAL_ERROR;
}
module->config.priority = priority;
return HAL_OK;
}
/**
* @brief Get module priority
* @param type: Module type
* @param instance: Module instance
* @param priority: Pointer to store priority
* @retval HAL status code
*/
hal_ret_t bsp_module_get_priority(bsp_module_type_t type, uint8_t instance, bsp_module_priority_t* priority) {
if (priority == NULL) {
return HAL_INVALID_PARAM;
}
bsp_module_t* module = bsp_module_get(type, instance);
if (module == NULL) {
*priority = BSP_MODULE_PRIORITY_MEDIUM;
return HAL_ERROR;
}
*priority = module->config.priority;
return HAL_OK;
}

View File

@ -17,7 +17,7 @@
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
static bool w25qxx_spi_send(const uint8_t *data, uint16_t size) { static bool w25qxx_spi_send(const uint8_t *data, uint16_t size) {
return hal_spi_transmit(W25QXX_SPI_INSTANCE, data, size); return hal_spi_transmit(W25QXX_SPI_INSTANCE, data, size) == HAL_RET_OK;
} }
/** /**
@ -27,7 +27,7 @@ static bool w25qxx_spi_send(const uint8_t *data, uint16_t size) {
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
static bool w25qxx_spi_receive(uint8_t *data, uint16_t size) { static bool w25qxx_spi_receive(uint8_t *data, uint16_t size) {
return hal_spi_receive(W25QXX_SPI_INSTANCE, data, size); return hal_spi_receive(W25QXX_SPI_INSTANCE, data, size) == HAL_RET_OK;
} }
/** /**
@ -38,7 +38,7 @@ static bool w25qxx_spi_receive(uint8_t *data, uint16_t size) {
* @return true if successful, false otherwise * @return true if successful, false otherwise
*/ */
static bool w25qxx_spi_transceive(const uint8_t *tx_data, uint8_t *rx_data, uint16_t size) { static bool w25qxx_spi_transceive(const uint8_t *tx_data, uint8_t *rx_data, uint16_t size) {
return hal_spi_transmit_receive(W25QXX_SPI_INSTANCE, tx_data, rx_data, size); return hal_spi_transmit_receive(W25QXX_SPI_INSTANCE, tx_data, rx_data, size) == HAL_RET_OK;
} }
/** /**
@ -96,7 +96,7 @@ bool bsp_w25qxx_init(void) {
.databits = HAL_SPI_DATABITS_8 .databits = HAL_SPI_DATABITS_8
}; };
if (!hal_spi_init(W25QXX_SPI_INSTANCE, &spi_config)) { if (hal_spi_init(W25QXX_SPI_INSTANCE, &spi_config) != HAL_RET_OK) {
return false; return false;
} }

View File

@ -16,8 +16,9 @@
/** /**
* @brief Default LED initialization function * @brief Default LED initialization function
* @param config: LED configuration structure * @param config: LED configuration structure
* @retval HAL status code
*/ */
static void default_led_init(const void* config) { static hal_ret_t default_led_init(const void* config) {
const bsp_led_config_t* led_config = (const bsp_led_config_t*)config; const bsp_led_config_t* led_config = (const bsp_led_config_t*)config;
hal_gpio_config_t gpio_config = { hal_gpio_config_t gpio_config = {
.port = led_config->port, .port = led_config->port,
@ -26,7 +27,132 @@ static void default_led_init(const void* config) {
.speed = led_config->speed, .speed = led_config->speed,
.pull = led_config->pull .pull = led_config->pull
}; };
hal_gpio_configure_pin(&gpio_config); return hal_gpio_configure_pin(&gpio_config);
}
/**
* @brief Default button initialization function
* @param config: Button configuration structure
* @retval HAL status code
*/
static hal_ret_t default_button_init(const void* config) {
const bsp_buttons_config_t* buttons_config = (const bsp_buttons_config_t*)config;
uint8_t i;
hal_ret_t status = HAL_RET_OK;
for (i = 0; i < buttons_config->count; i++) {
const bsp_button_config_t* button_config = &buttons_config->buttons[i];
hal_gpio_config_t gpio_config = {
.port = button_config->port,
.pin = button_config->pin,
.mode = button_config->mode,
.speed = button_config->speed,
.pull = button_config->pull
};
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
break;
}
}
return status;
}
/**
* @brief Default UART initialization function
* @param config: UART configuration structure
* @retval HAL status code
*/
static hal_ret_t default_uart_init(const void* config) {
const bsp_uart_config_t* uart_config = (const bsp_uart_config_t*)config;
hal_uart_config_t uart_cfg = {
.instance = (hal_uart_instance_t)uart_config->instance,
.baudrate = uart_config->baudrate,
.parity = uart_config->parity,
.stopbits = uart_config->stopbits,
.databits = uart_config->databits
};
return hal_uart_config(&uart_cfg);
}
/**
* @brief Default SPI initialization function
* @param config: SPI configuration structure
* @retval HAL status code
*/
static hal_ret_t default_spi_init(const void* config) {
const bsp_spi_config_t* spi_config = (const bsp_spi_config_t*)config;
hal_spi_config_t spi_cfg = {
.instance = spi_config->instance,
.mode = spi_config->mode,
.baudrate = spi_config->baudrate,
.polarity = spi_config->polarity,
.phase = spi_config->phase,
.databits = spi_config->databits
};
return hal_spi_init(spi_config->instance, &spi_cfg);
}
/**
* @brief Default I2C initialization function
* @param config: I2C configuration structure
* @retval HAL status code
*/
static hal_ret_t default_i2c_init(const void* config) {
/* TODO: Implement default I2C initialization */
return HAL_RET_OK;
}
/**
* @brief Default CAN initialization function
* @param config: CAN configuration structure
* @retval HAL status code
*/
static hal_ret_t default_can_init(const void* config) {
/* TODO: Implement default CAN initialization */
return HAL_RET_OK;
}
/**
* @brief Default ADC initialization function
* @param config: ADC configuration structure
* @retval HAL status code
*/
static hal_ret_t default_adc_init(const void* config) {
/* TODO: Implement default ADC initialization */
return HAL_RET_OK;
}
/**
* @brief Default W25QXX initialization function
* @param config: W25QXX configuration structure
* @retval HAL status code
*/
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 */
hal_gpio_config_t gpio_config = {
.port = w25qxx_config->cs_port,
.pin = w25qxx_config->cs_pin,
.mode = HAL_GPIO_MODE_OUTPUT_PP,
.speed = HAL_GPIO_SPEED_HIGH,
.pull = HAL_GPIO_PULL_NO
};
status = hal_gpio_configure_pin(&gpio_config);
if (status != HAL_RET_OK) {
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 */
return status;
} }
/** /**
@ -35,8 +161,8 @@ static void default_led_init(const void* config) {
static const bsp_button_config_t stm32f407vet6_buttons[] = { static const bsp_button_config_t stm32f407vet6_buttons[] = {
/* KEY0 - PE4, active low */ /* KEY0 - PE4, active low */
{ {
.port = BSP_KEY0_PORT, .port = HAL_GPIO_PORT_E,
.pin = BSP_KEY0_PIN, .pin = HAL_GPIO_PIN_4,
.mode = HAL_GPIO_MODE_INPUT, .mode = HAL_GPIO_MODE_INPUT,
.speed = HAL_GPIO_SPEED_LOW, .speed = HAL_GPIO_SPEED_LOW,
.pull = HAL_GPIO_PULL_UP, .pull = HAL_GPIO_PULL_UP,
@ -44,8 +170,8 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
}, },
/* KEY1 - PE3, active low */ /* KEY1 - PE3, active low */
{ {
.port = BSP_KEY1_PORT, .port = HAL_GPIO_PORT_E,
.pin = BSP_KEY1_PIN, .pin = HAL_GPIO_PIN_3,
.mode = HAL_GPIO_MODE_INPUT, .mode = HAL_GPIO_MODE_INPUT,
.speed = HAL_GPIO_SPEED_LOW, .speed = HAL_GPIO_SPEED_LOW,
.pull = HAL_GPIO_PULL_UP, .pull = HAL_GPIO_PULL_UP,
@ -53,8 +179,8 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
}, },
/* WKUP - PA0, active high */ /* WKUP - PA0, active high */
{ {
.port = BSP_WKUP_PORT, .port = HAL_GPIO_PORT_A,
.pin = BSP_WKUP_PIN, .pin = HAL_GPIO_PIN_0,
.mode = HAL_GPIO_MODE_INPUT, .mode = HAL_GPIO_MODE_INPUT,
.speed = HAL_GPIO_SPEED_LOW, .speed = HAL_GPIO_SPEED_LOW,
.pull = HAL_GPIO_PULL_DOWN, .pull = HAL_GPIO_PULL_DOWN,
@ -66,121 +192,217 @@ static const bsp_button_config_t stm32f407vet6_buttons[] = {
* @brief STM32F407VET6 buttons configuration * @brief STM32F407VET6 buttons configuration
*/ */
static const bsp_buttons_config_t stm32f407vet6_buttons_config = { static const bsp_buttons_config_t stm32f407vet6_buttons_config = {
.enable = 1,
.count = sizeof(stm32f407vet6_buttons) / sizeof(bsp_button_config_t), .count = sizeof(stm32f407vet6_buttons) / sizeof(bsp_button_config_t),
.buttons = stm32f407vet6_buttons .buttons = stm32f407vet6_buttons
}; };
/** /**
* @brief Default button initialization function * @brief STM32F407VET6 board UART configurations
* @param config: Button configuration structure
*/ */
static void default_button_init(const void* config) { static const bsp_uart_config_t stm32f407vet6_uarts[] = {
const bsp_buttons_config_t* buttons_config = (const bsp_buttons_config_t*)config; /* USART1 - PA9(TX), PA10(RX) */
uint8_t i; {
.enable = 1,
for (i = 0; i < buttons_config->count; i++) { .instance = BSP_UART_INSTANCE_1,
const bsp_button_config_t* button_config = &buttons_config->buttons[i]; .baudrate = 115200,
hal_gpio_config_t gpio_config = { .parity = HAL_UART_PARITY_NONE,
.port = button_config->port, .stopbits = HAL_UART_STOPBITS_1,
.pin = button_config->pin, .databits = HAL_UART_DATABITS_8,
.mode = button_config->mode,
.speed = button_config->speed,
.pull = button_config->pull
};
hal_gpio_configure_pin(&gpio_config);
}
}
/**
* @brief Default UART initialization function
* @param config: UART configuration structure
*/
static void default_uart_init(const void* config) {
const bsp_uart_config_t* uart_config = (const bsp_uart_config_t*)config;
hal_uart_config_t uart_cfg = {
.instance = (hal_uart_instance_t)uart_config->instance,
.baudrate = uart_config->baudrate,
.parity = uart_config->parity,
.stopbits = uart_config->stopbits,
.databits = uart_config->databits
};
hal_uart_config(&uart_cfg);
}
/**
* @brief Default W25QXX initialization function
* @param config: W25QXX configuration structure
*/
static void default_w25qxx_init(const void* config) {
const bsp_w25qxx_config_t* w25qxx_config = (const bsp_w25qxx_config_t*)config;
/* Initialize CS pin */
hal_gpio_config_t gpio_config = {
.port = w25qxx_config->cs_port,
.pin = w25qxx_config->cs_pin,
.mode = HAL_GPIO_MODE_OUTPUT_PP,
.speed = HAL_GPIO_SPEED_HIGH,
.pull = HAL_GPIO_PULL_NO
};
hal_gpio_configure_pin(&gpio_config);
/* Deselect chip initially */
hal_gpio_write_pin(w25qxx_config->cs_port, w25qxx_config->cs_pin, HAL_GPIO_PIN_SET);
/* Initialize SPI */
hal_spi_config_t spi_config = {
.instance = w25qxx_config->spi_config.instance,
.mode = w25qxx_config->spi_config.mode,
.baudrate = w25qxx_config->spi_config.baudrate,
.polarity = w25qxx_config->spi_config.polarity,
.phase = w25qxx_config->spi_config.phase,
.databits = w25qxx_config->spi_config.databits
};
hal_spi_init(w25qxx_config->spi_config.instance, &spi_config);
}
/**
* @brief STM32F407VET6 board configuration
*/
const bsp_board_config_t stm32f407vet6_board_config = {
.name = BOARD_NAME,
.led = {
.port = BSP_LED_PORT,
.pin = BSP_LED_PIN,
.mode = HAL_GPIO_MODE_OUTPUT_PP,
.speed = HAL_GPIO_SPEED_MEDIUM,
.pull = HAL_GPIO_PULL_NO
},
.buttons = stm32f407vet6_buttons_config,
.uart = {
.instance = BSP_UART_INSTANCE,
.baudrate = BSP_UART_BAUDRATE,
.parity = BSP_UART_PARITY,
.stopbits = BSP_UART_STOPBITS,
.databits = BSP_UART_DATABITS,
.tx_port = HAL_GPIO_PORT_A, /* USART1_TX - PA9 */ .tx_port = HAL_GPIO_PORT_A, /* USART1_TX - PA9 */
.tx_pin = HAL_GPIO_PIN_9, .tx_pin = HAL_GPIO_PIN_9,
.rx_port = HAL_GPIO_PORT_A, /* USART1_RX - PA10 */ .rx_port = HAL_GPIO_PORT_A, /* USART1_RX - PA10 */
.rx_pin = HAL_GPIO_PIN_10 .rx_pin = HAL_GPIO_PIN_10
}, }
.w25qxx = { };
.cs_port = HAL_GPIO_PORT_B,
.cs_pin = HAL_GPIO_PIN_0, /**
.spi_config = { * @brief STM32F407VET6 board SPI configurations
*/
static const bsp_spi_config_t stm32f407vet6_spis[] = {
/* SPI1 - PA5(SCK), PA6(MISO), PA7(MOSI) */
{
.enable = 1,
.instance = HAL_SPI_INSTANCE_1, .instance = HAL_SPI_INSTANCE_1,
.mode = HAL_SPI_MODE_MASTER, .mode = HAL_SPI_MODE_MASTER,
.baudrate = 1000000, /* 1 MHz */ .baudrate = 1000000, /* 1 MHz */
.polarity = HAL_SPI_POLARITY_LOW, .polarity = HAL_SPI_POLARITY_LOW,
.phase = HAL_SPI_PHASE_1EDGE, .phase = HAL_SPI_PHASE_1EDGE,
.databits = HAL_SPI_DATABITS_8 .databits = HAL_SPI_DATABITS_8,
.sck_port = HAL_GPIO_PORT_A,
.sck_pin = HAL_GPIO_PIN_5,
.miso_port = HAL_GPIO_PORT_A,
.miso_pin = HAL_GPIO_PIN_6,
.mosi_port = HAL_GPIO_PORT_A,
.mosi_pin = HAL_GPIO_PIN_7
} }
};
/**
* @brief STM32F407VET6 board I2C configurations
*/
static const bsp_i2c_config_t stm32f407vet6_i2cs[] = {
/* I2C1 - PB6(SCL), PB7(SDA) */
{
.enable = 0, /* Disabled by default */
.instance = HAL_I2C_INSTANCE_1,
.speed = HAL_I2C_SPEED_STANDARD,
.address_mode = HAL_I2C_ADDRESS_7BIT,
.dutycycle = HAL_I2C_DUTYCYCLE_2,
.own_address1 = 0x00,
.scl_port = HAL_GPIO_PORT_B,
.scl_pin = HAL_GPIO_PIN_6,
.sda_port = HAL_GPIO_PORT_B,
.sda_pin = HAL_GPIO_PIN_7
}
};
/**
* @brief STM32F407VET6 board CAN configurations
*/
static const bsp_can_config_t stm32f407vet6_cans[] = {
/* CAN1 - PA11(RX), PA12(TX) */
{
.enable = 0, /* Disabled by default */
.instance = HAL_CAN_INSTANCE_1,
.mode = HAL_CAN_MODE_NORMAL,
.prescaler = 6, /* 168MHz / 6 = 28MHz */
.sync_jump_width = 1,
.time_segment1 = 13,
.time_segment2 = 2,
.rx_port = HAL_GPIO_PORT_A,
.rx_pin = HAL_GPIO_PIN_11,
.tx_port = HAL_GPIO_PORT_A,
.tx_pin = HAL_GPIO_PIN_12
}
};
/**
* @brief STM32F407VET6 board ADC channel configurations
*/
static const bsp_adc_channel_config_t stm32f407vet6_adc_channels[] = {
/* ADC1 Channel 0 - PA0 */
{
.enable = 0, /* Disabled by default */
.channel = HAL_ADC_CHANNEL_0,
.sampletime = HAL_ADC_SAMPLETIME_56CYCLES,
.rank = 1
}
};
/**
* @brief STM32F407VET6 board ADC configurations
*/
static const bsp_adc_config_t stm32f407vet6_adcs[] = {
/* ADC1 */
{
.enable = 0, /* Disabled by default */
.instance = HAL_ADC_INSTANCE_1,
.resolution = HAL_ADC_RESOLUTION_12B,
.scan_conversion_mode = 0,
.continuous_conversion_mode = 0,
.channel_count = sizeof(stm32f407vet6_adc_channels) / sizeof(bsp_adc_channel_config_t),
.channels = stm32f407vet6_adc_channels
}
};
/**
* @brief STM32F407VET6 board configuration
*/
const bsp_board_config_t stm32f407vet6_board_config = {
.version = BSP_CONFIG_VERSION,
.name = "STM32F407VET6",
.description = "STM32F407VET6 Development Board",
.id = {
.vendor_id = 0x0483, /* STMicroelectronics */
.product_id = 0x374B, /* STM32F4 Series */
.serial_number = 0x00000001 /* Default serial number */
}, },
/* Board features */
.features = (
BSP_BOARD_FEATURE_LED |
BSP_BOARD_FEATURE_BUTTON |
BSP_BOARD_FEATURE_UART |
BSP_BOARD_FEATURE_SPI |
BSP_BOARD_FEATURE_I2C |
BSP_BOARD_FEATURE_CAN |
BSP_BOARD_FEATURE_ADC |
BSP_BOARD_FEATURE_W25QXX
),
/* 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 */
.sram_size = 64 * 1024, /* 64 KB SRAM */
.cpu_core = 0x0F, /* Cortex-M4 */
.cpu_bits = 32 /* 32-bit CPU */
},
/* Peripheral configurations */
.led = {
.enable = 1,
.port = HAL_GPIO_PORT_E,
.pin = HAL_GPIO_PIN_5,
.mode = HAL_GPIO_MODE_OUTPUT_PP,
.speed = HAL_GPIO_SPEED_MEDIUM,
.pull = HAL_GPIO_PULL_NO
},
.buttons = stm32f407vet6_buttons_config,
.w25qxx = {
.enable = 1,
.cs_port = HAL_GPIO_PORT_B,
.cs_pin = HAL_GPIO_PIN_0,
.spi_instance = 0 /* Use SPI instance 0 */
},
/* Peripheral arrays */
.periphs = {
/* UART configurations */
.uart_count = 1,
.uarts = stm32f407vet6_uarts,
/* SPI configurations */
.spi_count = 1,
.spis = stm32f407vet6_spis,
/* I2C configurations */
.i2c_count = 1,
.i2cs = stm32f407vet6_i2cs,
/* CAN configurations */
.can_count = 1,
.cans = stm32f407vet6_cans,
/* ADC configurations */
.adc_count = 1,
.adcs = stm32f407vet6_adcs
},
/* Initialization function pointers */
.init_funcs = {
.led_init = default_led_init, .led_init = default_led_init,
.button_init = default_button_init, .button_init = default_button_init,
.uart_init = default_uart_init, .uart_init = default_uart_init,
.w25qxx_init = default_w25qxx_init, .spi_init = default_spi_init,
.clock_speed = 168000000, /* 168 MHz */ .i2c_init = default_i2c_init,
.uart_count = 6 .can_init = default_can_init,
.adc_init = default_adc_init,
.w25qxx_init = default_w25qxx_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"
}; };
/** /**
@ -190,3 +412,11 @@ const bsp_board_config_t stm32f407vet6_board_config = {
const char* bsp_board_get_name(void) { const char* bsp_board_get_name(void) {
return stm32f407vet6_board_config.name; return stm32f407vet6_board_config.name;
} }
/**
* @brief Get board configuration
* @retval Pointer to board configuration structure
*/
const bsp_board_config_t* bsp_board_get_config(void) {
return &stm32f407vet6_board_config;
}

View File

@ -49,12 +49,6 @@
/* Private variables ---------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */ /* USER CODE BEGIN PV */
/* LED configuration */
static led_config_t led_config = {
.gpio_port = BSP_LED_PORT,
.gpio_pin = BSP_LED_PIN
};
/* LED instance */ /* LED instance */
static led_t led; static led_t led;
@ -105,10 +99,17 @@ int main(void)
bsp_init(); bsp_init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
/* Initialize modules */ /* Initialize modules */
led_init(&led, &led_config);
delay_init(); delay_init();
logging_init(); logging_init();
/* Get LED configuration from board config */
const bsp_board_config_t* board_config = bsp_get_board_config();
led_config_t led_config = {
.gpio_port = board_config->led.port,
.gpio_pin = board_config->led.pin
};
led_init(&led, &led_config);
/* Initialize keys */ /* Initialize keys */
bsp_key_init(); bsp_key_init();

View File

@ -14,9 +14,9 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
/* Include common HAL headers */ /* Include common HAL headers */
#include "../../hal_delay.h"
#include "../../hal_gpio.h" #include "../../hal_gpio.h"
#include "../../hal_uart.h" #include "../../hal_uart.h"
#include "../../hal_delay.h"
/** /**
* @brief STM32F4 specific initialization * @brief STM32F4 specific initialization

View File

@ -10,6 +10,14 @@
#ifndef HAL_H #ifndef HAL_H
#define HAL_H #define HAL_H
#include <stdint.h>
/* HAL version definitions */
#define HAL_VERSION_MAJOR 1
#define HAL_VERSION_MINOR 0
#define HAL_VERSION_PATCH 0
#define HAL_VERSION_STRING "1.0.0"
/* Define supported architectures */ /* Define supported architectures */
#define HAL_ARCH_STM32F1 0 #define HAL_ARCH_STM32F1 0
#define HAL_ARCH_STM32F4 1 #define HAL_ARCH_STM32F4 1
@ -21,27 +29,339 @@
#define HAL_TARGET_ARCH HAL_ARCH_STM32F4 #define HAL_TARGET_ARCH HAL_ARCH_STM32F4
#endif #endif
/* Include architecture specific headers */ /* Architecture specific functions will be included in implementation files */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
#include "arch/stm32f1/hal_stm32f1.h"
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
#include "arch/stm32f4/hal_stm32f4.h"
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
#include "arch/stm32f7/hal_stm32f7.h"
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
#include "arch/stm32l4/hal_stm32l4.h"
#else
#error "Unsupported HAL architecture: " #HAL_TARGET_ARCH
#endif
/* Architecture compatibility check */ /* Architecture compatibility check */
#if HAL_TARGET_ARCH < HAL_ARCH_STM32F1 || HAL_TARGET_ARCH > HAL_ARCH_STM32L4 #if HAL_TARGET_ARCH < HAL_ARCH_STM32F1 || HAL_TARGET_ARCH > HAL_ARCH_STM32L4
#error "Invalid HAL architecture selection" #error "Invalid HAL architecture selection"
#endif #endif
/**
* @brief HAL status return codes - renamed to avoid conflict with STM32 HAL
*/
typedef enum {
HAL_RET_OK = 0x00U, /*!< Operation completed successfully */
HAL_RET_ERROR = 0x01U, /*!< Generic operation failed */
HAL_RET_BUSY = 0x02U, /*!< Peripheral or resource busy */
HAL_RET_TIMEOUT = 0x03U, /*!< Operation timed out */
HAL_RET_INVALID_PARAM = 0x04U, /*!< Invalid parameter */
HAL_RET_NOT_SUPPORTED = 0x05U, /*!< Operation not supported */
HAL_RET_OUT_OF_MEMORY = 0x06U, /*!< Out of memory */
HAL_RET_INTERNAL_ERROR = 0x07U, /*!< Internal error */
HAL_RET_RESOURCE_LOCKED = 0x08U, /*!< Resource locked */
HAL_RET_RESOURCE_ERROR = 0x09U, /*!< Resource error */
HAL_RET_COMM_ERROR = 0x0AU, /*!< Communication error */
HAL_RET_CONFIG_ERROR = 0x0BU, /*!< Configuration error */
HAL_RET_INIT_ERROR = 0x0CU, /*!< Initialization error */
HAL_RET_DEINIT_ERROR = 0x0DU, /*!< Deinitialization error */
HAL_RET_IO_ERROR = 0x0EU, /*!< I/O operation error */
HAL_RET_OVERRUN_ERROR = 0x0FU, /*!< Overrun error */
HAL_RET_UNDERRUN_ERROR = 0x10U, /*!< Underrun error */
HAL_RET_PARITY_ERROR = 0x11U, /*!< Parity error */
HAL_RET_FRAMING_ERROR = 0x12U, /*!< Framing error */
HAL_RET_NOISE_ERROR = 0x13U /*!< Noise error */
} hal_ret_t;
/**
* @brief HAL error category definitions
*/
typedef enum {
HAL_ERR_CAT_COMMON = 0x00U, /*!< Common error category */
HAL_ERR_CAT_GPIO = 0x10U, /*!< GPIO error category */
HAL_ERR_CAT_UART = 0x20U, /*!< UART error category */
HAL_ERR_CAT_SPI = 0x30U, /*!< SPI error category */
HAL_ERR_CAT_I2C = 0x40U, /*!< I2C error category */
HAL_ERR_CAT_CAN = 0x50U, /*!< CAN error category */
HAL_ERR_CAT_ADC = 0x60U, /*!< ADC error category */
HAL_ERR_CAT_DMA = 0x70U, /*!< DMA error category */
HAL_ERR_CAT_RTC = 0x80U, /*!< RTC error category */
HAL_ERR_CAT_MODULE = 0x90U, /*!< Module management error category */
HAL_ERR_CAT_ARCH = 0xA0U, /*!< Architecture specific error category */
HAL_ERR_CAT_MAX = 0xFFU /*!< Maximum error category */
} hal_error_category_t;
/**
* @brief HAL extended error code structure
*/
typedef struct {
hal_ret_t status; /*!< HAL status code */
hal_error_category_t category; /*!< Error category */
uint32_t specific_error; /*!< Specific error code (category dependent) */
const char* file; /*!< File where error occurred */
uint32_t line; /*!< Line number where error occurred */
const char* function; /*!< Function where error occurred */
uint32_t timestamp; /*!< Error timestamp */
} hal_error_t;
/**
* @brief HAL error callback type
*/
typedef void (*hal_error_callback_t)(const hal_error_t* error);
/**
* @brief HAL error information context
*/
typedef struct {
hal_error_callback_t callback; /*!< Error callback function */
hal_error_t last_error; /*!< Last error information */
uint32_t error_count; /*!< Total error count */
uint8_t enabled; /*!< Error logging enabled flag */
} hal_error_context_t;
/**
* @brief HAL module types
*/
typedef enum {
HAL_MODULE_GPIO = 0,
HAL_MODULE_UART,
HAL_MODULE_SPI,
HAL_MODULE_I2C,
HAL_MODULE_CAN,
HAL_MODULE_ADC,
HAL_MODULE_DAC,
HAL_MODULE_TIMER,
HAL_MODULE_RTC,
HAL_MODULE_DMA,
HAL_MODULE_MAX
} hal_module_type_t;
/**
* @brief HAL handle structure - base for all HAL peripherals
*/
typedef struct {
void* instance;
void* config;
hal_ret_t status;
uint32_t lock;
void* user_data;
} hal_handle_t;
/**
* @brief HAL module operations structure - unified API for all modules
*/
typedef struct {
hal_ret_t (*init)(hal_handle_t* handle);
hal_ret_t (*deinit)(hal_handle_t* handle);
hal_ret_t (*configure)(hal_handle_t* handle, void* config);
hal_ret_t (*control)(hal_handle_t* handle, uint32_t cmd, void* param);
hal_ret_t (*get_status)(hal_handle_t* handle, uint32_t* status);
} hal_module_ops_t;
/**
* @brief HAL module configuration structure
*/
typedef struct {
hal_module_type_t type;
const char* name;
uint32_t version;
hal_module_ops_t ops;
void* default_config;
} hal_module_config_t;
/**
* @brief HAL initialization structure
*/
typedef struct {
uint32_t module_count;
const hal_module_config_t* modules;
uint32_t flags;
} hal_init_t;
/**
* @brief HAL flags definitions
*/
#define HAL_INIT_FLAG_DEBUG (1 << 0) /*!< Enable debug mode */
#define HAL_INIT_FLAG_NO_CACHE (1 << 1) /*!< Disable cache */
#define HAL_INIT_FLAG_SAFE_MODE (1 << 2) /*!< Enable safe mode */
/**
* @brief HAL peripheral state definitions
*/
typedef enum {
HAL_PERIPH_STATE_RESET = 0,
HAL_PERIPH_STATE_READY,
HAL_PERIPH_STATE_BUSY,
HAL_PERIPH_STATE_TIMEOUT,
HAL_PERIPH_STATE_ERROR
} hal_periph_state_t;
/**
* @brief HAL lock/unlock macros
*/
#define HAL_LOCK(handle) do { while((handle)->lock); (handle)->lock = 1; } while(0)
#define HAL_UNLOCK(handle) do { (handle)->lock = 0; } while(0)
/**
* @brief HAL handle initialization macro
*/
#define HAL_HANDLE_INIT(handle) \
do { \
memset((handle), 0, sizeof(hal_handle_t)); \
(handle)->status = HAL_RET_OK; \
(handle)->lock = 0; \
} while(0)
/**
* @brief HAL module registration macro
*/
#define HAL_MODULE_REGISTER(module) \
static const hal_module_config_t __hal_module_##module##_config = { \
.type = HAL_MODULE_##module, \
.name = #module, \
.version = 1, \
.ops = __hal_##module##_ops, \
.default_config = &__hal_##module##_default_config \
};
/**
* @brief HAL module registration at startup
*/
#define HAL_MODULE_REGISTER_STARTUP(module) \
HAL_MODULE_REGISTER(module) \
__attribute__((constructor)) static void __hal_register_##module##_at_startup(void) { \
hal_module_register(&__hal_module_##module##_config); \
}
/** /**
* @brief HAL module initialization * @brief HAL module initialization
*/ */
void hal_init(void); hal_ret_t hal_init(void);
/**
* @brief Register a HAL module
* @param module_config: Module configuration
* @retval HAL status code
*/
hal_ret_t hal_module_register(const hal_module_config_t* module_config);
/**
* @brief Initialize a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @retval HAL status code
*/
hal_ret_t hal_module_init(hal_module_type_t module_type, hal_handle_t* handle);
/**
* @brief Deinitialize a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @retval HAL status code
*/
hal_ret_t hal_module_deinit(hal_module_type_t module_type, hal_handle_t* handle);
/**
* @brief Configure a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param config: Module configuration data
* @retval HAL status code
*/
hal_ret_t hal_module_configure(hal_module_type_t module_type, hal_handle_t* handle, void* config);
/**
* @brief Control a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param cmd: Control command
* @param param: Control parameter
* @retval HAL status code
*/
hal_ret_t hal_module_control(hal_module_type_t module_type, hal_handle_t* handle, uint32_t cmd, void* param);
/**
* @brief Get status of a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param status: Pointer to store module status
* @retval HAL status code
*/
hal_ret_t hal_module_get_status(hal_module_type_t module_type, hal_handle_t* handle, uint32_t* status);
/**
* @brief Get default configuration for a module
* @param module_type: Module type
* @return Pointer to default configuration, or NULL if not available
*/
void* hal_module_get_default_config(hal_module_type_t module_type);
/**
* @brief Get HAL version information
* @param major: Pointer to store major version
* @param minor: Pointer to store minor version
* @param patch: Pointer to store patch version
* @retval HAL status code
*/
hal_ret_t hal_get_version(uint8_t* major, uint8_t* minor, uint8_t* patch);
/**
* @brief Get HAL version string
* @retval Version string
*/
const char* hal_get_version_string(void);
/**
* @brief Get HAL module count
* @retval Number of registered HAL modules
*/
uint32_t hal_get_module_count(void);
/**
* @brief Get HAL module configuration
* @param module_type: Module type
* @retval Pointer to module configuration, or NULL if not found
*/
const hal_module_config_t* hal_get_module_config(hal_module_type_t module_type);
/**
* @brief Initialize HAL error handling system
* @retval HAL status code
*/
hal_ret_t hal_error_init(void);
/**
* @brief Deinitialize HAL error handling system
* @retval HAL status code
*/
hal_ret_t hal_error_deinit(void);
/**
* @brief Register an error callback function
* @param callback: Error callback function
* @retval HAL status code
*/
hal_ret_t hal_error_register_callback(hal_error_callback_t callback);
/**
* @brief Record an error
* @param error: Pointer to error information
* @retval HAL status code
*/
hal_ret_t hal_error_record(const hal_error_t* error);
/**
* @brief Get last error information
* @retval Pointer to last error information
*/
const hal_error_t* hal_error_get_last(void);
/**
* @brief Get total error count
* @retval Total error count
*/
uint32_t hal_error_get_count(void);
/**
* @brief Clear error information
* @retval HAL status code
*/
hal_ret_t hal_error_clear(void);
/**
* @brief Enable/disable error logging
* @param enable: Enable flag (1 to enable, 0 to disable)
* @retval HAL status code
*/
hal_ret_t hal_error_enable(uint8_t enable);
#endif /* HAL_H */ #endif /* HAL_H */

175
HAL/Inc/hal_adc.h Normal file
View File

@ -0,0 +1,175 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_adc.h
* @brief : ADC hardware abstraction layer header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef HAL_ADC_H
#define HAL_ADC_H
#include <stdint.h>
#include <stddef.h>
#include "hal.h"
/**
* @brief ADC instance identifier definitions
*/
typedef enum {
HAL_ADC_INSTANCE_1 = 0,
HAL_ADC_INSTANCE_2,
HAL_ADC_INSTANCE_3,
HAL_ADC_INSTANCE_MAX
} hal_adc_instance_t;
/**
* @brief ADC resolution definitions
*/
typedef enum {
HAL_ADC_RESOLUTION_12B = 0,
HAL_ADC_RESOLUTION_10B,
HAL_ADC_RESOLUTION_8B,
HAL_ADC_RESOLUTION_6B
} hal_adc_resolution_t;
/**
* @brief ADC channel definitions
*/
typedef enum {
HAL_ADC_CHANNEL_0 = 0,
HAL_ADC_CHANNEL_1,
HAL_ADC_CHANNEL_2,
HAL_ADC_CHANNEL_3,
HAL_ADC_CHANNEL_4,
HAL_ADC_CHANNEL_5,
HAL_ADC_CHANNEL_6,
HAL_ADC_CHANNEL_7,
HAL_ADC_CHANNEL_8,
HAL_ADC_CHANNEL_9,
HAL_ADC_CHANNEL_10,
HAL_ADC_CHANNEL_11,
HAL_ADC_CHANNEL_12,
HAL_ADC_CHANNEL_13,
HAL_ADC_CHANNEL_14,
HAL_ADC_CHANNEL_15,
HAL_ADC_CHANNEL_16,
HAL_ADC_CHANNEL_17,
HAL_ADC_CHANNEL_18,
HAL_ADC_CHANNEL_MAX
} hal_adc_channel_t;
/**
* @brief ADC sample time definitions
*/
typedef enum {
HAL_ADC_SAMPLETIME_3CYCLES = 0,
HAL_ADC_SAMPLETIME_15CYCLES,
HAL_ADC_SAMPLETIME_28CYCLES,
HAL_ADC_SAMPLETIME_56CYCLES,
HAL_ADC_SAMPLETIME_84CYCLES,
HAL_ADC_SAMPLETIME_112CYCLES,
HAL_ADC_SAMPLETIME_144CYCLES,
HAL_ADC_SAMPLETIME_480CYCLES
} hal_adc_sampletime_t;
/**
* @brief ADC channel configuration structure
*/
typedef struct {
hal_adc_channel_t channel;
hal_adc_sampletime_t sampletime;
uint8_t rank;
uint8_t enable;
} hal_adc_channel_config_t;
/**
* @brief ADC configuration structure
*/
typedef struct {
hal_adc_instance_t instance;
hal_adc_resolution_t resolution;
uint8_t scan_conversion_mode;
uint8_t continuous_conversion_mode;
uint8_t discontinuous_conversion_mode;
uint8_t discontinuous_number_of_conversions;
uint8_t nbr_of_conversions;
uint8_t channel_count;
const hal_adc_channel_config_t* channels;
uint32_t timeout;
} hal_adc_config_t;
/**
* @brief Initialize ADC hardware
* @param config: ADC configuration structure
* @retval HAL status code
*/
hal_ret_t hal_adc_init(const hal_adc_config_t *config);
/**
* @brief Deinitialize ADC hardware
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_deinit(hal_adc_instance_t instance);
/**
* @brief Start ADC conversion
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_start(hal_adc_instance_t instance);
/**
* @brief Stop ADC conversion
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_stop(hal_adc_instance_t instance);
/**
* @brief Get ADC conversion value
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @param value: Pointer to store conversion value
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_adc_get_value(hal_adc_instance_t instance, hal_adc_channel_t channel, uint16_t *value, uint32_t timeout);
/**
* @brief Get multiple ADC conversion values
* @param instance: ADC instance identifier
* @param values: Pointer to store conversion values
* @param length: Number of values to get
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_adc_get_values(hal_adc_instance_t instance, uint16_t *values, uint8_t length, uint32_t timeout);
/**
* @brief Configure ADC channel
* @param instance: ADC instance identifier
* @param config: ADC channel configuration structure
* @retval HAL status code
*/
hal_ret_t hal_adc_configure_channel(hal_adc_instance_t instance, const hal_adc_channel_config_t *config);
/**
* @brief Enable ADC channel
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @retval HAL status code
*/
hal_ret_t hal_adc_enable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel);
/**
* @brief Disable ADC channel
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @retval HAL status code
*/
hal_ret_t hal_adc_disable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel);
#endif /* HAL_ADC_H */

180
HAL/Inc/hal_can.h Normal file
View File

@ -0,0 +1,180 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_can.h
* @brief : CAN hardware abstraction layer header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef HAL_CAN_H
#define HAL_CAN_H
#include <stdint.h>
#include <stddef.h>
#include "hal.h"
/**
* @brief CAN instance identifier definitions
*/
typedef enum {
HAL_CAN_INSTANCE_1 = 0,
HAL_CAN_INSTANCE_2,
HAL_CAN_INSTANCE_MAX
} hal_can_instance_t;
/**
* @brief CAN mode definitions
*/
typedef enum {
HAL_CAN_MODE_NORMAL = 0,
HAL_CAN_MODE_LOOPBACK,
HAL_CAN_MODE_SILENT,
HAL_CAN_MODE_SILENT_LOOPBACK
} hal_can_mode_t;
/**
* @brief CAN filter mode definitions
*/
typedef enum {
HAL_CAN_FILTER_MODE_IDMASK = 0,
HAL_CAN_FILTER_MODE_IDLIST
} hal_can_filter_mode_t;
/**
* @brief CAN filter scale definitions
*/
typedef enum {
HAL_CAN_FILTER_SCALE_16BIT = 0,
HAL_CAN_FILTER_SCALE_32BIT
} hal_can_filter_scale_t;
/**
* @brief CAN filter fifo assignment definitions
*/
typedef enum {
HAL_CAN_FILTER_FIFO0 = 0,
HAL_CAN_FILTER_FIFO1
} hal_can_filter_fifo_t;
/**
* @brief CAN frame format definitions
*/
typedef enum {
HAL_CAN_FRAME_STANDARD = 0,
HAL_CAN_FRAME_EXTENDED
} hal_can_frame_format_t;
/**
* @brief CAN frame type definitions
*/
typedef enum {
HAL_CAN_FRAME_DATA = 0,
HAL_CAN_FRAME_REMOTE
} hal_can_frame_type_t;
/**
* @brief CAN filter configuration structure
*/
typedef struct {
uint8_t filter_id;
hal_can_filter_mode_t mode;
hal_can_filter_scale_t scale;
hal_can_filter_fifo_t fifo_assignment;
uint32_t filter_mask_id_high;
uint32_t filter_mask_id_low;
uint32_t filter_id_high;
uint32_t filter_id_low;
uint8_t filter_enable;
} hal_can_filter_config_t;
/**
* @brief CAN configuration structure
*/
typedef struct {
hal_can_instance_t instance;
hal_can_mode_t mode;
uint32_t prescaler;
uint8_t sync_jump_width;
uint8_t time_segment1;
uint8_t time_segment2;
uint8_t filter_count;
const hal_can_filter_config_t* filters;
} hal_can_config_t;
/**
* @brief CAN message structure
*/
typedef struct {
hal_can_frame_format_t format;
hal_can_frame_type_t type;
uint32_t id;
uint8_t dlc;
uint8_t data[8];
} hal_can_message_t;
/**
* @brief Initialize CAN hardware
* @param config: CAN configuration structure
* @retval HAL status code
*/
hal_ret_t hal_can_init(const hal_can_config_t *config);
/**
* @brief Deinitialize CAN hardware
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_ret_t hal_can_deinit(hal_can_instance_t instance);
/**
* @brief Start CAN peripheral
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_ret_t hal_can_start(hal_can_instance_t instance);
/**
* @brief Stop CAN peripheral
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_ret_t hal_can_stop(hal_can_instance_t instance);
/**
* @brief Send CAN message
* @param instance: CAN instance identifier
* @param message: Pointer to CAN message structure
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_can_send(hal_can_instance_t instance, const hal_can_message_t *message, uint32_t timeout);
/**
* @brief Receive CAN message
* @param instance: CAN instance identifier
* @param fifo: FIFO number (0 or 1)
* @param message: Pointer to CAN message structure
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_can_receive(hal_can_instance_t instance, uint8_t fifo, hal_can_message_t *message, uint32_t timeout);
/**
* @brief Get CAN receive FIFO message pending count
* @param instance: CAN instance identifier
* @param fifo: FIFO number (0 or 1)
* @param count: Pointer to store pending message count
* @retval HAL status code
*/
hal_ret_t hal_can_get_pending_count(hal_can_instance_t instance, uint8_t fifo, uint8_t *count);
/**
* @brief Configure CAN filter
* @param instance: CAN instance identifier
* @param filter_config: Pointer to CAN filter configuration structure
* @retval HAL status code
*/
hal_ret_t hal_can_configure_filter(hal_can_instance_t instance, const hal_can_filter_config_t *filter_config);
#endif /* HAL_CAN_H */

View File

@ -10,6 +10,8 @@
#ifndef HAL_GPIO_H #ifndef HAL_GPIO_H
#define HAL_GPIO_H #define HAL_GPIO_H
#include "hal.h"
/** /**
* @brief GPIO pin state definitions * @brief GPIO pin state definitions
*/ */
@ -105,29 +107,33 @@ typedef struct {
/** /**
* @brief Initialize GPIO hardware * @brief Initialize GPIO hardware
* @retval HAL status code
*/ */
void hal_gpio_init(void); hal_ret_t hal_gpio_init(void);
/** /**
* @brief Configure GPIO pin * @brief Configure GPIO pin
* @param config: GPIO configuration structure * @param config: GPIO configuration structure
* @retval HAL status code
*/ */
void hal_gpio_configure_pin(const hal_gpio_config_t *config); hal_ret_t hal_gpio_configure_pin(const hal_gpio_config_t *config);
/** /**
* @brief Write GPIO pin state * @brief Write GPIO pin state
* @param port: GPIO port * @param port: GPIO port
* @param pin: GPIO pin * @param pin: GPIO pin
* @param state: GPIO pin state * @param state: GPIO pin state
* @retval HAL status code
*/ */
void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state); hal_ret_t hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state);
/** /**
* @brief Toggle GPIO pin state * @brief Toggle GPIO pin state
* @param port: GPIO port * @param port: GPIO port
* @param pin: GPIO pin * @param pin: GPIO pin
* @retval HAL status code
*/ */
void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin); hal_ret_t hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin);
/** /**
* @brief Read GPIO pin state * @brief Read GPIO pin state

125
HAL/Inc/hal_i2c.h Normal file
View File

@ -0,0 +1,125 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_i2c.h
* @brief : I2C hardware abstraction layer header file
******************************************************************************
*/
/* USER CODE END Header */
#ifndef HAL_I2C_H
#define HAL_I2C_H
#include <stdint.h>
#include <stddef.h>
#include "hal.h"
/**
* @brief I2C instance identifier definitions
*/
typedef enum {
HAL_I2C_INSTANCE_1 = 0,
HAL_I2C_INSTANCE_2,
HAL_I2C_INSTANCE_3,
HAL_I2C_INSTANCE_4,
HAL_I2C_INSTANCE_MAX
} hal_i2c_instance_t;
/**
* @brief I2C clock speed definitions
*/
typedef enum {
HAL_I2C_SPEED_STANDARD = 100000U, /*!< Standard speed (100 kHz) */
HAL_I2C_SPEED_FAST = 400000U, /*!< Fast speed (400 kHz) */
HAL_I2C_SPEED_FAST_PLUS = 1000000U, /*!< Fast plus speed (1 MHz) */
HAL_I2C_SPEED_HIGH = 3400000U /*!< High speed (3.4 MHz) */
} hal_i2c_speed_t;
/**
* @brief I2C address mode definitions
*/
typedef enum {
HAL_I2C_ADDRESS_7BIT = 0,
HAL_I2C_ADDRESS_10BIT
} hal_i2c_address_mode_t;
/**
* @brief I2C duty cycle definitions
*/
typedef enum {
HAL_I2C_DUTYCYCLE_2 = 0,
HAL_I2C_DUTYCYCLE_16_9
} hal_i2c_dutycycle_t;
/**
* @brief I2C configuration structure
*/
typedef struct {
hal_i2c_instance_t instance;
hal_i2c_speed_t speed;
hal_i2c_address_mode_t address_mode;
hal_i2c_dutycycle_t dutycycle;
uint16_t own_address1;
uint32_t timeout;
} hal_i2c_config_t;
/**
* @brief Initialize I2C hardware
* @param config: I2C configuration structure
* @retval HAL status code
*/
hal_ret_t hal_i2c_init(const hal_i2c_config_t *config);
/**
* @brief Deinitialize I2C hardware
* @param instance: I2C instance identifier
* @retval HAL status code
*/
hal_ret_t hal_i2c_deinit(hal_i2c_instance_t instance);
/**
* @brief Transmit data to I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param data: Pointer to data buffer
* @param length: Data length in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_i2c_master_transmit(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *data, uint16_t length, uint32_t timeout);
/**
* @brief Receive data from I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param data: Pointer to data buffer
* @param length: Data length to receive in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_i2c_master_receive(hal_i2c_instance_t instance, uint16_t dev_address, uint8_t *data, uint16_t length, uint32_t timeout);
/**
* @brief Transmit and receive data from I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param tx_data: Pointer to transmit data buffer
* @param tx_length: Transmit data length in bytes
* @param rx_data: Pointer to receive data buffer
* @param rx_length: Receive data length in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_i2c_master_transmit_receive(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *tx_data, uint16_t tx_length, uint8_t *rx_data, uint16_t rx_length, uint32_t timeout);
/**
* @brief Check if I2C bus is ready
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param trials: Number of trials
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_i2c_is_device_ready(hal_i2c_instance_t instance, uint16_t dev_address, uint32_t trials, uint32_t timeout);
#endif /* HAL_I2C_H */

View File

@ -13,6 +13,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include "hal.h"
/** /**
* @brief SPI instance identifier definitions * @brief SPI instance identifier definitions
@ -75,34 +76,34 @@ typedef struct {
* @brief Initialize SPI hardware * @brief Initialize SPI hardware
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @param config SPI configuration structure * @param config SPI configuration structure
* @return true if initialization is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config); hal_ret_t hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config);
/** /**
* @brief Deinitialize SPI hardware * @brief Deinitialize SPI hardware
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @return true if deinitialization is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_deinit(hal_spi_instance_t instance); hal_ret_t hal_spi_deinit(hal_spi_instance_t instance);
/** /**
* @brief Transmit data over specific SPI instance * @brief Transmit data over specific SPI instance
* @param instance: SPI instance identifier * @param instance: SPI instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param size: Data length in bytes * @param size: Data length in bytes
* @return true if transmission is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *data, uint16_t size); hal_ret_t hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *data, uint16_t size);
/** /**
* @brief Receive data from specific SPI instance * @brief Receive data from specific SPI instance
* @param instance: SPI instance identifier * @param instance: SPI instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param size: Data length to receive in bytes * @param size: Data length to receive in bytes
* @return true if reception is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *data, uint16_t size); hal_ret_t hal_spi_receive(hal_spi_instance_t instance, uint8_t *data, uint16_t size);
/** /**
* @brief Transmit and receive data simultaneously over specific SPI instance * @brief Transmit and receive data simultaneously over specific SPI instance
@ -110,8 +111,8 @@ bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *data, uint16_t size);
* @param tx_data: Pointer to transmit data buffer * @param tx_data: Pointer to transmit data buffer
* @param rx_data: Pointer to receive data buffer * @param rx_data: Pointer to receive data buffer
* @param size: Data length in bytes * @param size: Data length in bytes
* @return true if transmission and reception are successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *tx_data, uint8_t *rx_data, uint16_t size); hal_ret_t hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *tx_data, uint8_t *rx_data, uint16_t size);
#endif /* HAL_SPI_H */ #endif /* HAL_SPI_H */

View File

@ -12,6 +12,7 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include "hal.h"
/** /**
* @brief UART parity definitions * @brief UART parity definitions
@ -64,44 +65,50 @@ typedef struct {
/** /**
* @brief Initialize UART hardware * @brief Initialize UART hardware
* @retval HAL status code
*/ */
void hal_uart_init(void); hal_ret_t hal_uart_init(void);
/** /**
* @brief Configure UART parameters for specific instance * @brief Configure UART parameters for specific instance
* @param config: UART configuration structure * @param config: UART configuration structure
* @retval HAL status code
*/ */
void hal_uart_config(const hal_uart_config_t *config); hal_ret_t hal_uart_config(const hal_uart_config_t *config);
/** /**
* @brief Send data over specific UART instance * @brief Send data over specific UART instance
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param length: Data length in bytes * @param length: Data length in bytes
* @retval HAL status code
*/ */
void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length); hal_ret_t hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length);
/** /**
* @brief Receive data from specific UART instance * @brief Receive data from specific UART instance
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param length: Data length to receive in bytes * @param length: Data length to receive in bytes
* @retval Number of bytes received * @param received: Pointer to store number of bytes received
* @retval HAL status code
*/ */
size_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length); hal_ret_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length, size_t *received);
/** /**
* @brief Check if specific UART instance is ready to send * @brief Check if specific UART instance is ready to send
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @retval 1 if ready, 0 otherwise * @param ready: Pointer to store ready status (1 if ready, 0 otherwise)
* @retval HAL status code
*/ */
uint8_t hal_uart_is_tx_ready(hal_uart_instance_t instance); hal_ret_t hal_uart_is_tx_ready(hal_uart_instance_t instance, uint8_t *ready);
/** /**
* @brief Check if specific UART instance has data to receive * @brief Check if specific UART instance has data to receive
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @retval 1 if data available, 0 otherwise * @param ready: Pointer to store ready status (1 if data available, 0 otherwise)
* @retval HAL status code
*/ */
uint8_t hal_uart_is_rx_ready(hal_uart_instance_t instance); hal_ret_t hal_uart_is_rx_ready(hal_uart_instance_t instance, uint8_t *ready);
#endif /* HAL_UART_H */ #endif /* HAL_UART_H */

View File

@ -8,15 +8,343 @@
/* USER CODE END Header */ /* USER CODE END Header */
#include "hal.h" #include "hal.h"
#include <string.h>
/**
* @brief HAL module registry
*/
static hal_module_config_t hal_module_registry[HAL_MODULE_MAX];
static uint32_t hal_module_count = 0;
/**
* @brief HAL error context
*/
static hal_error_context_t hal_error_ctx = {
.callback = NULL,
.error_count = 0,
.enabled = 1
};
/** /**
* @brief HAL module initialization * @brief HAL module initialization
* @retval HAL status code
*/ */
void hal_init(void) { hal_ret_t hal_init(void) {
hal_ret_t status = HAL_RET_OK;
/* Clear module registry */
memset(hal_module_registry, 0, sizeof(hal_module_registry));
hal_module_count = 0;
/* Initialize error handling system */
status = hal_error_init();
if (status != HAL_RET_OK) {
return status;
}
/* Call architecture specific initialization */ /* Call architecture specific initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_init();
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
hal_stm32f4_init(); hal_stm32f4_init();
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
hal_stm32f7_init();
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
hal_stm32l4_init();
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
}
/**
* @brief Register a HAL module
* @param module_config: Module configuration
* @retval HAL status code
*/
hal_ret_t hal_module_register(const hal_module_config_t* module_config) {
if (module_config == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (module_config->type >= HAL_MODULE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Check if module already registered */
if (hal_module_registry[module_config->type].ops.init != NULL) {
return HAL_RET_RESOURCE_LOCKED;
}
/* Register the module */
memcpy(&hal_module_registry[module_config->type], module_config, sizeof(hal_module_config_t));
hal_module_count++;
return HAL_RET_OK;
}
/**
* @brief Initialize a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @retval HAL status code
*/
hal_ret_t hal_module_init(hal_module_type_t module_type, hal_handle_t* handle) {
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (hal_module_registry[module_type].ops.init == NULL) {
return HAL_RET_NOT_SUPPORTED;
}
/* Initialize handle if not already initialized */
if (handle->status == HAL_PERIPH_STATE_RESET) {
HAL_HANDLE_INIT(handle);
handle->status = HAL_PERIPH_STATE_READY;
}
return hal_module_registry[module_type].ops.init(handle);
}
/**
* @brief Deinitialize a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @retval HAL status code
*/
hal_ret_t hal_module_deinit(hal_module_type_t module_type, hal_handle_t* handle) {
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (hal_module_registry[module_type].ops.deinit == NULL) {
return HAL_RET_NOT_SUPPORTED;
}
hal_ret_t status = hal_module_registry[module_type].ops.deinit(handle);
if (status == HAL_RET_OK) {
handle->status = HAL_PERIPH_STATE_RESET;
}
return status;
}
/**
* @brief Configure a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param config: Module configuration data
* @retval HAL status code
*/
hal_ret_t hal_module_configure(hal_module_type_t module_type, hal_handle_t* handle, void* config) {
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (hal_module_registry[module_type].ops.configure == NULL) {
return HAL_RET_NOT_SUPPORTED;
}
return hal_module_registry[module_type].ops.configure(handle, config);
}
/**
* @brief Control a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param cmd: Control command
* @param param: Control parameter
* @retval HAL status code
*/
hal_ret_t hal_module_control(hal_module_type_t module_type, hal_handle_t* handle, uint32_t cmd, void* param) {
if (module_type >= HAL_MODULE_MAX || handle == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (hal_module_registry[module_type].ops.control == NULL) {
return HAL_RET_NOT_SUPPORTED;
}
return hal_module_registry[module_type].ops.control(handle, cmd, param);
}
/**
* @brief Get status of a specific HAL module
* @param module_type: Module type
* @param handle: HAL handle for the module
* @param status: Pointer to store module status
* @retval HAL status code
*/
hal_ret_t hal_module_get_status(hal_module_type_t module_type, hal_handle_t* handle, uint32_t* status) {
if (module_type >= HAL_MODULE_MAX || handle == NULL || status == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (hal_module_registry[module_type].ops.get_status == NULL) {
return HAL_RET_NOT_SUPPORTED;
}
return hal_module_registry[module_type].ops.get_status(handle, status);
}
/**
* @brief Get default configuration for a module
* @param module_type: Module type
* @return Pointer to default configuration, or NULL if not available
*/
void* hal_module_get_default_config(hal_module_type_t module_type) {
if (module_type >= HAL_MODULE_MAX) {
return NULL;
}
return hal_module_registry[module_type].default_config;
}
/**
* @brief Get HAL version information
* @param major: Pointer to store major version
* @param minor: Pointer to store minor version
* @param patch: Pointer to store patch version
* @retval HAL status code
*/
hal_ret_t hal_get_version(uint8_t* major, uint8_t* minor, uint8_t* patch) {
if (major == NULL || minor == NULL || patch == NULL) {
return HAL_RET_INVALID_PARAM;
}
*major = HAL_VERSION_MAJOR;
*minor = HAL_VERSION_MINOR;
*patch = HAL_VERSION_PATCH;
return HAL_RET_OK;
}
/**
* @brief Get HAL version string
* @retval Version string
*/
const char* hal_get_version_string(void) {
return HAL_VERSION_STRING;
}
/**
* @brief Get HAL module count
* @retval Number of registered HAL modules
*/
uint32_t hal_get_module_count(void) {
return hal_module_count;
}
/**
* @brief Get HAL module configuration
* @param module_type: Module type
* @retval Pointer to module configuration, or NULL if not found
*/
const hal_module_config_t* hal_get_module_config(hal_module_type_t module_type) {
if (module_type >= HAL_MODULE_MAX) {
return NULL;
}
if (hal_module_registry[module_type].ops.init == NULL) {
return NULL;
}
return &hal_module_registry[module_type];
}
/**
* @brief Initialize HAL error handling system
* @retval HAL status code
*/
hal_ret_t hal_error_init(void) {
memset(&hal_error_ctx.last_error, 0, sizeof(hal_error_t));
hal_error_ctx.error_count = 0;
hal_error_ctx.enabled = 1;
hal_error_ctx.callback = NULL;
return HAL_RET_OK;
}
/**
* @brief Deinitialize HAL error handling system
* @retval HAL status code
*/
hal_ret_t hal_error_deinit(void) {
hal_error_ctx.enabled = 0;
hal_error_ctx.callback = NULL;
return HAL_RET_OK;
}
/**
* @brief Register an error callback function
* @param callback: Error callback function
* @retval HAL status code
*/
hal_ret_t hal_error_register_callback(hal_error_callback_t callback) {
hal_error_ctx.callback = callback;
return HAL_RET_OK;
}
/**
* @brief Record an error
* @param error: Pointer to error information
* @retval HAL status code
*/
hal_ret_t hal_error_record(const hal_error_t* error) {
if (error == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (!hal_error_ctx.enabled) {
return HAL_RET_OK;
}
/* Copy error information */
memcpy(&hal_error_ctx.last_error, error, sizeof(hal_error_t));
hal_error_ctx.error_count++;
/* Call error callback if registered */
if (hal_error_ctx.callback != NULL) {
hal_error_ctx.callback(error);
}
return HAL_RET_OK;
}
/**
* @brief Get last error information
* @retval Pointer to last error information
*/
const hal_error_t* hal_error_get_last(void) {
return &hal_error_ctx.last_error;
}
/**
* @brief Get total error count
* @retval Total error count
*/
uint32_t hal_error_get_count(void) {
return hal_error_ctx.error_count;
}
/**
* @brief Clear error information
* @retval HAL status code
*/
hal_ret_t hal_error_clear(void) {
memset(&hal_error_ctx.last_error, 0, sizeof(hal_error_t));
hal_error_ctx.error_count = 0;
return HAL_RET_OK;
}
/**
* @brief Enable/disable error logging
* @param enable: Enable flag (1 to enable, 0 to disable)
* @retval HAL status code
*/
hal_ret_t hal_error_enable(uint8_t enable) {
hal_error_ctx.enabled = enable;
return HAL_RET_OK;
} }

313
HAL/Src/hal_adc.c Normal file
View File

@ -0,0 +1,313 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_adc.c
* @brief : ADC hardware abstraction layer source file
******************************************************************************
*/
/* USER CODE END Header */
#include "hal.h"
#include "hal_adc.h"
/**
* @brief Initialize ADC hardware
* @param config: ADC configuration structure
* @retval HAL status code
*/
hal_ret_t hal_adc_init(const hal_adc_config_t *config) {
if (config == NULL) {
return HAL_INVALID_PARAM;
}
if (config->instance >= HAL_ADC_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC initialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Deinitialize ADC hardware
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_deinit(hal_adc_instance_t instance) {
if (instance >= HAL_ADC_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC deinitialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC deinitialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Start ADC conversion
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_start(hal_adc_instance_t instance) {
if (instance >= HAL_ADC_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC start implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC start */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Stop ADC conversion
* @param instance: ADC instance identifier
* @retval HAL status code
*/
hal_ret_t hal_adc_stop(hal_adc_instance_t instance) {
if (instance >= HAL_ADC_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC stop implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC stop */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Get ADC conversion value
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @param value: Pointer to store conversion value
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_adc_get_value(hal_adc_instance_t instance, hal_adc_channel_t channel, uint16_t *value, uint32_t timeout) {
if (value == NULL) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC get value implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC get value */
*value = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC get value */
*value = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC get value */
*value = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC get value */
*value = 0;
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Get multiple ADC conversion values
* @param instance: ADC instance identifier
* @param values: Pointer to store conversion values
* @param length: Number of values to get
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_ret_t hal_adc_get_values(hal_adc_instance_t instance, uint16_t *values, uint8_t length, uint32_t timeout) {
if (values == NULL || length == 0) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_ADC_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC get values implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC get values */
for (uint8_t i = 0; i < length; i++) {
values[i] = 0;
}
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC get values */
for (uint8_t i = 0; i < length; i++) {
values[i] = 0;
}
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC get values */
for (uint8_t i = 0; i < length; i++) {
values[i] = 0;
}
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC get values */
for (uint8_t i = 0; i < length; i++) {
values[i] = 0;
}
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Configure ADC channel
* @param instance: ADC instance identifier
* @param config: ADC channel configuration structure
* @retval HAL status code
*/
hal_ret_t hal_adc_configure_channel(hal_adc_instance_t instance, const hal_adc_channel_config_t *config) {
if (config == NULL) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_ADC_INSTANCE_MAX || config->channel >= HAL_ADC_CHANNEL_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC channel configuration implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC channel configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC channel configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC channel configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC channel configuration */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Enable ADC channel
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @retval HAL status code
*/
hal_ret_t hal_adc_enable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel) {
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC channel enable implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC channel enable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC channel enable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC channel enable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC channel enable */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Disable ADC channel
* @param instance: ADC instance identifier
* @param channel: ADC channel
* @retval HAL status code
*/
hal_ret_t hal_adc_disable_channel(hal_adc_instance_t instance, hal_adc_channel_t channel) {
if (instance >= HAL_ADC_INSTANCE_MAX || channel >= HAL_ADC_CHANNEL_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific ADC channel disable implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 ADC channel disable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 ADC channel disable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 ADC channel disable */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 ADC channel disable */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}

275
HAL/Src/hal_can.c Normal file
View File

@ -0,0 +1,275 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_can.c
* @brief : CAN hardware abstraction layer source file
******************************************************************************
*/
/* USER CODE END Header */
#include "hal.h"
#include "hal_can.h"
/**
* @brief Initialize CAN hardware
* @param config: CAN configuration structure
* @retval HAL status code
*/
hal_status_t hal_can_init(const hal_can_config_t *config) {
if (config == NULL) {
return HAL_INVALID_PARAM;
}
if (config->instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN initialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Deinitialize CAN hardware
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_status_t hal_can_deinit(hal_can_instance_t instance) {
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN deinitialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN deinitialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Start CAN peripheral
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_status_t hal_can_start(hal_can_instance_t instance) {
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN start implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN start */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN start */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Stop CAN peripheral
* @param instance: CAN instance identifier
* @retval HAL status code
*/
hal_status_t hal_can_stop(hal_can_instance_t instance) {
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN stop implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN stop */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN stop */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Send CAN message
* @param instance: CAN instance identifier
* @param message: Pointer to CAN message structure
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_can_send(hal_can_instance_t instance, const hal_can_message_t *message, uint32_t timeout) {
if (message == NULL) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN send implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN send */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN send */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN send */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN send */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Receive CAN message
* @param instance: CAN instance identifier
* @param fifo: FIFO number (0 or 1)
* @param message: Pointer to CAN message structure
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_can_receive(hal_can_instance_t instance, uint8_t fifo, hal_can_message_t *message, uint32_t timeout) {
if (message == NULL || fifo > 1) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN receive */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Get CAN receive FIFO message pending count
* @param instance: CAN instance identifier
* @param fifo: FIFO number (0 or 1)
* @param count: Pointer to store pending message count
* @retval HAL status code
*/
hal_status_t hal_can_get_pending_count(hal_can_instance_t instance, uint8_t fifo, uint8_t *count) {
if (count == NULL || fifo > 1) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN get pending count implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN get pending count */
*count = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN get pending count */
*count = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN get pending count */
*count = 0;
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN get pending count */
*count = 0;
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Configure CAN filter
* @param instance: CAN instance identifier
* @param filter_config: Pointer to CAN filter configuration structure
* @retval HAL status code
*/
hal_status_t hal_can_configure_filter(hal_can_instance_t instance, const hal_can_filter_config_t *filter_config) {
if (filter_config == NULL) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_CAN_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific CAN filter configuration implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 CAN filter configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 CAN filter configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 CAN filter configuration */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 CAN filter configuration */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}

View File

@ -9,11 +9,13 @@
#include "hal.h" #include "hal.h"
#include "hal_gpio.h" #include "hal_gpio.h"
#include <stddef.h>
/** /**
* @brief Initialize GPIO hardware * @brief Initialize GPIO hardware
* @retval HAL status code
*/ */
void hal_gpio_init(void) { hal_ret_t hal_gpio_init(void) {
/* Call architecture specific GPIO initialization */ /* Call architecture specific GPIO initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_init(); hal_stm32f1_gpio_init();
@ -25,14 +27,21 @@ void hal_gpio_init(void) {
hal_stm32l4_gpio_init(); hal_stm32l4_gpio_init();
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
* @brief Configure GPIO pin * @brief Configure GPIO pin
* @param config: GPIO configuration structure * @param config: GPIO configuration structure
* @retval HAL status code
*/ */
void hal_gpio_configure_pin(const hal_gpio_config_t *config) { hal_ret_t hal_gpio_configure_pin(const hal_gpio_config_t *config) {
if (config == NULL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO configuration */ /* Call architecture specific GPIO configuration */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_configure_pin(config); hal_stm32f1_gpio_configure_pin(config);
@ -44,7 +53,9 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
hal_stm32l4_gpio_configure_pin(config); hal_stm32l4_gpio_configure_pin(config);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
@ -52,8 +63,14 @@ void hal_gpio_configure_pin(const hal_gpio_config_t *config) {
* @param port: GPIO port * @param port: GPIO port
* @param pin: GPIO pin * @param pin: GPIO pin
* @param state: GPIO pin state * @param state: GPIO pin state
* @retval HAL status code
*/ */
void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) { hal_ret_t hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_state_t state) {
/* Validate parameters */
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO write implementation */ /* Call architecture specific GPIO write implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_write_pin(port, pin, state); hal_stm32f1_gpio_write_pin(port, pin, state);
@ -65,15 +82,23 @@ void hal_gpio_write_pin(hal_gpio_port_t port, hal_gpio_pin_t pin, hal_gpio_pin_s
hal_stm32l4_gpio_write_pin(port, pin, state); hal_stm32l4_gpio_write_pin(port, pin, state);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
* @brief Toggle GPIO pin state * @brief Toggle GPIO pin state
* @param port: GPIO port * @param port: GPIO port
* @param pin: GPIO pin * @param pin: GPIO pin
* @retval HAL status code
*/ */
void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) { hal_ret_t hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
/* Validate parameters */
if (port >= HAL_GPIO_PORT_K + 1 || pin >= HAL_GPIO_PIN_ALL) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific GPIO toggle implementation */ /* Call architecture specific GPIO toggle implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_gpio_toggle_pin(port, pin); hal_stm32f1_gpio_toggle_pin(port, pin);
@ -85,7 +110,9 @@ void hal_gpio_toggle_pin(hal_gpio_port_t port, hal_gpio_pin_t pin) {
hal_stm32l4_gpio_toggle_pin(port, pin); hal_stm32l4_gpio_toggle_pin(port, pin);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**

218
HAL/Src/hal_i2c.c Normal file
View File

@ -0,0 +1,218 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : hal_i2c.c
* @brief : I2C hardware abstraction layer source file
******************************************************************************
*/
/* USER CODE END Header */
#include "hal.h"
#include "hal_i2c.h"
/**
* @brief Initialize I2C hardware
* @param config: I2C configuration structure
* @retval HAL status code
*/
hal_status_t hal_i2c_init(const hal_i2c_config_t *config) {
if (config == NULL) {
return HAL_INVALID_PARAM;
}
if (config->instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C initialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C initialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Deinitialize I2C hardware
* @param instance: I2C instance identifier
* @retval HAL status code
*/
hal_status_t hal_i2c_deinit(hal_i2c_instance_t instance) {
if (instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C deinitialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C deinitialization */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C deinitialization */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Transmit data to I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param data: Pointer to data buffer
* @param length: Data length in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_i2c_master_transmit(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *data, uint16_t length, uint32_t timeout) {
if (data == NULL || length == 0) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C transmit implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C transmit */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C transmit */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C transmit */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C transmit */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Receive data from I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param data: Pointer to data buffer
* @param length: Data length to receive in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_i2c_master_receive(hal_i2c_instance_t instance, uint16_t dev_address, uint8_t *data, uint16_t length, uint32_t timeout) {
if (data == NULL || length == 0) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C receive */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Transmit and receive data from I2C slave
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param tx_data: Pointer to transmit data buffer
* @param tx_length: Transmit data length in bytes
* @param rx_data: Pointer to receive data buffer
* @param rx_length: Receive data length in bytes
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_i2c_master_transmit_receive(hal_i2c_instance_t instance, uint16_t dev_address, const uint8_t *tx_data, uint16_t tx_length, uint8_t *rx_data, uint16_t rx_length, uint32_t timeout) {
if (tx_data == NULL || rx_data == NULL || tx_length == 0 || rx_length == 0) {
return HAL_INVALID_PARAM;
}
if (instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C transmit and receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C transmit and receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C transmit and receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C transmit and receive */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C transmit and receive */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}
/**
* @brief Check if I2C bus is ready
* @param instance: I2C instance identifier
* @param dev_address: Slave device address
* @param trials: Number of trials
* @param timeout: Timeout in milliseconds
* @retval HAL status code
*/
hal_status_t hal_i2c_is_device_ready(hal_i2c_instance_t instance, uint16_t dev_address, uint32_t trials, uint32_t timeout) {
if (instance >= HAL_I2C_INSTANCE_MAX) {
return HAL_INVALID_PARAM;
}
/* Call architecture specific I2C device ready check implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
/* TODO: Implement STM32F1 I2C device ready check */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
/* TODO: Implement STM32F4 I2C device ready check */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
/* TODO: Implement STM32F7 I2C device ready check */
return HAL_OK;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
/* TODO: Implement STM32L4 I2C device ready check */
return HAL_OK;
#else
#error "Unsupported HAL architecture"
return HAL_ERROR;
#endif
}

View File

@ -15,42 +15,54 @@
* @brief Initialize SPI hardware * @brief Initialize SPI hardware
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @param config SPI configuration structure * @param config SPI configuration structure
* @return true if initialization is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config) { hal_ret_t hal_spi_init(hal_spi_instance_t instance, const hal_spi_config_t *config) {
if (config == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_SPI_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific SPI initialization */ /* Call architecture specific SPI initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_spi_init(instance, config); return hal_stm32f1_spi_init(instance, config) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_spi_init(instance, config); return hal_stm32f4_spi_init(instance, config) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_spi_init(instance, config); return hal_stm32f7_spi_init(instance, config) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_spi_init(instance, config); return hal_stm32l4_spi_init(instance, config) ? HAL_OK : HAL_ERROR;
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return false; return HAL_RET_ERROR;
#endif #endif
} }
/** /**
* @brief Deinitialize SPI hardware * @brief Deinitialize SPI hardware
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @return true if deinitialization is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_deinit(hal_spi_instance_t instance) { hal_ret_t hal_spi_deinit(hal_spi_instance_t instance) {
if (instance >= HAL_SPI_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific SPI deinitialization */ /* Call architecture specific SPI deinitialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_spi_deinit(instance); return hal_stm32f1_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_spi_deinit(instance); return hal_stm32f4_spi_deinit(instance) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_spi_deinit(instance); return hal_stm32f7_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_spi_deinit(instance); return hal_stm32l4_spi_deinit(instance) ? HAL_OK : HAL_ERROR;
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return false; return HAL_RET_ERROR;
#endif #endif
} }
@ -59,21 +71,29 @@ bool hal_spi_deinit(hal_spi_instance_t instance) {
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @param p_data Pointer to data buffer to transmit * @param p_data Pointer to data buffer to transmit
* @param size Size of data to transmit * @param size Size of data to transmit
* @return true if transmission is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16_t size) { hal_ret_t hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16_t size) {
if (p_data == NULL || size == 0) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_SPI_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific SPI transmit implementation */ /* Call architecture specific SPI transmit implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_spi_transmit(instance, p_data, size); return hal_stm32f1_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_spi_transmit(instance, p_data, size); return hal_stm32f4_spi_transmit(instance, p_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_spi_transmit(instance, p_data, size); return hal_stm32f7_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_spi_transmit(instance, p_data, size); return hal_stm32l4_spi_transmit(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return false; return HAL_RET_ERROR;
#endif #endif
} }
@ -82,21 +102,29 @@ bool hal_spi_transmit(hal_spi_instance_t instance, const uint8_t *p_data, uint16
* @param instance SPI instance identifier * @param instance SPI instance identifier
* @param p_data Pointer to data buffer to receive * @param p_data Pointer to data buffer to receive
* @param size Size of data to receive * @param size Size of data to receive
* @return true if reception is successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size) { hal_ret_t hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size) {
if (p_data == NULL || size == 0) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_SPI_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific SPI receive implementation */ /* Call architecture specific SPI receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_spi_receive(instance, p_data, size); return hal_stm32f1_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_spi_receive(instance, p_data, size); return hal_stm32f4_spi_receive(instance, p_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_spi_receive(instance, p_data, size); return hal_stm32f7_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_spi_receive(instance, p_data, size); return hal_stm32l4_spi_receive(instance, p_data, size) ? HAL_OK : HAL_ERROR;
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return false; return HAL_RET_ERROR;
#endif #endif
} }
@ -106,20 +134,28 @@ bool hal_spi_receive(hal_spi_instance_t instance, uint8_t *p_data, uint16_t size
* @param p_tx_data Pointer to data buffer to transmit * @param p_tx_data Pointer to data buffer to transmit
* @param p_rx_data Pointer to data buffer to receive * @param p_rx_data Pointer to data buffer to receive
* @param size Size of data to transmit/receive * @param size Size of data to transmit/receive
* @return true if transmission and reception are successful, false otherwise * @retval HAL status code
*/ */
bool hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *p_tx_data, uint8_t *p_rx_data, uint16_t size) { hal_ret_t hal_spi_transmit_receive(hal_spi_instance_t instance, const uint8_t *p_tx_data, uint8_t *p_rx_data, uint16_t size) {
if (p_tx_data == NULL || p_rx_data == NULL || size == 0) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_SPI_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific SPI transmit and receive implementation */ /* Call architecture specific SPI transmit and receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_spi_transmit_receive(instance, p_tx_data, p_rx_data, size); return hal_stm32f1_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size); return hal_stm32f4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_RET_OK : HAL_RET_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_spi_transmit_receive(instance, p_tx_data, p_rx_data, size); return hal_stm32f7_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size); return hal_stm32l4_spi_transmit_receive(instance, p_tx_data, p_rx_data, size) ? HAL_OK : HAL_ERROR;
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return false; return HAL_RET_ERROR;
#endif #endif
} }

View File

@ -12,8 +12,9 @@
/** /**
* @brief Initialize UART hardware * @brief Initialize UART hardware
* @retval HAL status code
*/ */
void hal_uart_init(void) { hal_ret_t hal_uart_init(void) {
/* Call architecture specific UART initialization */ /* Call architecture specific UART initialization */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_uart_init(); hal_stm32f1_uart_init();
@ -25,14 +26,25 @@ void hal_uart_init(void) {
hal_stm32l4_uart_init(); hal_stm32l4_uart_init();
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
* @brief Configure UART parameters for specific instance * @brief Configure UART parameters for specific instance
* @param config: UART configuration structure * @param config: UART configuration structure
* @retval HAL status code
*/ */
void hal_uart_config(const hal_uart_config_t *config) { hal_ret_t hal_uart_config(const hal_uart_config_t *config) {
if (config == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (config->instance >= HAL_UART_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific UART configuration */ /* Call architecture specific UART configuration */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_uart_config(config); hal_stm32f1_uart_config(config);
@ -44,7 +56,9 @@ void hal_uart_config(const hal_uart_config_t *config) {
hal_stm32l4_uart_config(config); hal_stm32l4_uart_config(config);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
@ -52,8 +66,17 @@ void hal_uart_config(const hal_uart_config_t *config) {
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param length: Data length in bytes * @param length: Data length in bytes
* @retval HAL status code
*/ */
void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length) { hal_ret_t hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t length) {
if (data == NULL || length == 0) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_UART_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific UART send implementation */ /* Call architecture specific UART send implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
hal_stm32f1_uart_send(instance, data, length); hal_stm32f1_uart_send(instance, data, length);
@ -65,7 +88,9 @@ void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t len
hal_stm32l4_uart_send(instance, data, length); hal_stm32l4_uart_send(instance, data, length);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
@ -73,62 +98,92 @@ void hal_uart_send(hal_uart_instance_t instance, const uint8_t *data, size_t len
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @param data: Pointer to data buffer * @param data: Pointer to data buffer
* @param length: Data length to receive in bytes * @param length: Data length to receive in bytes
* @retval Number of bytes received * @param received: Pointer to store number of bytes received
* @retval HAL status code
*/ */
size_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length) { hal_ret_t hal_uart_receive(hal_uart_instance_t instance, uint8_t *data, size_t length, size_t *received) {
if (data == NULL || received == NULL || length == 0) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_UART_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific UART receive implementation */ /* Call architecture specific UART receive implementation */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_uart_receive(instance, data, length); *received = hal_stm32f1_uart_receive(instance, data, length);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_uart_receive(instance, data, length); *received = hal_stm32f4_uart_receive(instance, data, length);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_uart_receive(instance, data, length); *received = hal_stm32f7_uart_receive(instance, data, length);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_uart_receive(instance, data, length); *received = hal_stm32l4_uart_receive(instance, data, length);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return 0; return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
* @brief Check if specific UART instance is ready to send * @brief Check if specific UART instance is ready to send
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @retval 1 if ready, 0 otherwise * @param ready: Pointer to store ready status (1 if ready, 0 otherwise)
* @retval HAL status code
*/ */
uint8_t hal_uart_is_tx_ready(hal_uart_instance_t instance) { hal_ret_t hal_uart_is_tx_ready(hal_uart_instance_t instance, uint8_t *ready) {
if (ready == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_UART_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific UART TX ready check */ /* Call architecture specific UART TX ready check */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_uart_is_tx_ready(instance); *ready = hal_stm32f1_uart_is_tx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_uart_is_tx_ready(instance); *ready = hal_stm32f4_uart_is_tx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_uart_is_tx_ready(instance); *ready = hal_stm32f7_uart_is_tx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_uart_is_tx_ready(instance); *ready = hal_stm32l4_uart_is_tx_ready(instance);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return 0; return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }
/** /**
* @brief Check if specific UART instance has data to receive * @brief Check if specific UART instance has data to receive
* @param instance: UART instance identifier * @param instance: UART instance identifier
* @retval 1 if data available, 0 otherwise * @param ready: Pointer to store ready status (1 if data available, 0 otherwise)
* @retval HAL status code
*/ */
uint8_t hal_uart_is_rx_ready(hal_uart_instance_t instance) { hal_ret_t hal_uart_is_rx_ready(hal_uart_instance_t instance, uint8_t *ready) {
if (ready == NULL) {
return HAL_RET_INVALID_PARAM;
}
if (instance >= HAL_UART_INSTANCE_MAX) {
return HAL_RET_INVALID_PARAM;
}
/* Call architecture specific UART RX ready check */ /* Call architecture specific UART RX ready check */
#if HAL_TARGET_ARCH == HAL_ARCH_STM32F1 #if HAL_TARGET_ARCH == HAL_ARCH_STM32F1
return hal_stm32f1_uart_is_rx_ready(instance); *ready = hal_stm32f1_uart_is_rx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F4
return hal_stm32f4_uart_is_rx_ready(instance); *ready = hal_stm32f4_uart_is_rx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32F7
return hal_stm32f7_uart_is_rx_ready(instance); *ready = hal_stm32f7_uart_is_rx_ready(instance);
#elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4 #elif HAL_TARGET_ARCH == HAL_ARCH_STM32L4
return hal_stm32l4_uart_is_rx_ready(instance); *ready = hal_stm32l4_uart_is_rx_ready(instance);
#else #else
#error "Unsupported HAL architecture" #error "Unsupported HAL architecture"
return 0; return HAL_RET_ERROR;
#endif #endif
return HAL_RET_OK;
} }

View File

@ -85,7 +85,9 @@ size_t uart_receive(uint8_t *data, size_t length) {
return 0; return 0;
} }
return hal_uart_receive(uart.config.instance, data, length); size_t received = 0;
hal_uart_receive(uart.config.instance, data, length, &received);
return received;
} }
/** /**
@ -93,7 +95,9 @@ size_t uart_receive(uint8_t *data, size_t length) {
* @retval 1 if ready, 0 otherwise * @retval 1 if ready, 0 otherwise
*/ */
uint8_t uart_is_tx_ready(void) { uint8_t uart_is_tx_ready(void) {
return hal_uart_is_tx_ready(uart.config.instance); uint8_t ready = 0;
hal_uart_is_tx_ready(uart.config.instance, &ready);
return ready;
} }
/** /**
@ -101,5 +105,7 @@ uint8_t uart_is_tx_ready(void) {
* @retval 1 if data available, 0 otherwise * @retval 1 if data available, 0 otherwise
*/ */
uint8_t uart_is_rx_ready(void) { uint8_t uart_is_rx_ready(void) {
return hal_uart_is_rx_ready(uart.config.instance); uint8_t ready = 0;
hal_uart_is_rx_ready(uart.config.instance, &ready);
return ready;
} }

Binary file not shown.

View File

@ -119,3 +119,89 @@
2181 2249 7908477861665347 Middlewares/logging/liblogging.a df543b4167ac9a8e 2181 2249 7908477861665347 Middlewares/logging/liblogging.a df543b4167ac9a8e
2186 2268 7908477861722517 BSP/libbsp.a e0765276282a1d70 2186 2268 7908477861722517 BSP/libbsp.a e0765276282a1d70
2268 2802 7908477862532836 stm32f407vet6_cmake.elf 4338dca859bbb8b4 2268 2802 7908477862532836 stm32f407vet6_cmake.elf 4338dca859bbb8b4
83 278 7908512909651377 Modules/led/CMakeFiles/led.dir/src/led.c.obj f81c04216db73f61
15 884 7908515972897402 HAL/CMakeFiles/hal.dir/Src/hal_delay.c.obj 8860d5f0ee1a9236
24 885 7908515972988356 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4.c.obj b6e773bf8808077f
34 1014 7908515973084336 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_delay.c.obj 582888277cddaf7e
37 1014 7908515973105009 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_spi.c.obj f7e0911aaf0b3af
9 1015 7908515972833133 HAL/CMakeFiles/hal.dir/Src/hal.c.obj f9a0a9727c2eda2b
12 159 7908518882618028 HAL/CMakeFiles/hal.dir/Src/hal_delay.c.obj 8860d5f0ee1a9236
21 171 7908518882701350 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4.c.obj b6e773bf8808077f
15 174 7908518882653385 HAL/CMakeFiles/hal.dir/Src/hal_uart.c.obj dfcb3e6b3fe745db
6 181 7908518882557671 HAL/CMakeFiles/hal.dir/Src/hal.c.obj f9a0a9727c2eda2b
63 203 7908518883132879 BSP/CMakeFiles/bsp.dir/Src/bsp_w25qxx.c.obj 77426e3fb0f553e5
57 214 7908518883061873 BSP/CMakeFiles/bsp.dir/Src/bsp_board_manager.c.obj fb8792ab3e6d3cb9
76 216 7908518883250730 Modules/led/CMakeFiles/led.dir/src/led.c.obj f81c04216db73f61
80 220 7908518883296695 Middlewares/logging/CMakeFiles/logging.dir/src/logging.c.obj 50c1cd09ee8934e1
69 226 7908518883194202 BSP/CMakeFiles/bsp.dir/Src/bsp_key.c.obj 1a935290b16864c0
31 284 7908518882807131 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_delay.c.obj 582888277cddaf7e
27 284 7908518882761788 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_uart.c.obj df787ab831e6e2b4
24 288 7908518882731576 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_gpio.c.obj b6850ab729e76492
35 306 7908518882843312 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_spi.c.obj f7e0911aaf0b3af
19 107 7908519698989395 BSP/CMakeFiles/bsp.dir/Src/bsp_init.c.obj eae2726ff6a3757a
9 85 7908521054971674 HAL/CMakeFiles/hal.dir/Src/hal_spi.c.obj eac0e356644f7fd0
12 93 7908521054996808 Modules/uart/CMakeFiles/uart.dir/src/uart.c.obj 4979c5baa76e360d
12 87 7908523180428921 HAL/CMakeFiles/hal.dir/Src/hal_gpio.c.obj ab8546ae81e6b910
17 122 7908523180479324 BSP/CMakeFiles/bsp.dir/Src/stm32f407vet6_board.c.obj e09f143ebf2c7378
88 209 7908523181184046 HAL/libhal.a 1cac9cc1eea4712c
7 83 7908523909563980 Modules/uart/libuart.a f980800b2f79773c
20 99 7908523909696088 BSP/libbsp.a e0765276282a1d70
28 105 7908523909778142 Modules/led/libled.a 4975295d4e0f5144
83 162 7908523910322929 Middlewares/logging/liblogging.a df543b4167ac9a8e
14 255 7908523909640265 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/main.c.obj e02e91f67899b94
256 523 7908523912046776 stm32f407vet6_cmake.elf 4338dca859bbb8b4
5 81 7908532790141964 BSP/CMakeFiles/bsp.dir/Src/bsp_w25qxx.c.obj 77426e3fb0f553e5
81 150 7908532790910064 BSP/libbsp.a e0765276282a1d70
150 358 7908532791587632 stm32f407vet6_cmake.elf 4338dca859bbb8b4
3 32 7908532958214568 CMakeFiles/clean.additional a8e8475892b6c694
32 52 7908532958506129 clean 48fb0083216ba165
35 159 7908532960983723 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4.c.obj b6e773bf8808077f
54 164 7908532961173437 Modules/delay/CMakeFiles/delay.dir/src/delay.c.obj dd783bb1ca4e3531
31 176 7908532960936158 HAL/CMakeFiles/hal.dir/Src/hal_spi.c.obj eac0e356644f7fd0
25 195 7908532960878959 HAL/CMakeFiles/hal.dir/Src/hal_delay.c.obj 8860d5f0ee1a9236
27 215 7908532960905033 HAL/CMakeFiles/hal.dir/Src/hal_uart.c.obj dfcb3e6b3fe745db
22 221 7908532960858699 HAL/CMakeFiles/hal.dir/Src/hal_gpio.c.obj ab8546ae81e6b910
18 227 7908532960811596 HAL/CMakeFiles/hal.dir/Src/hal.c.obj f9a0a9727c2eda2b
67 243 7908532961308293 BSP/CMakeFiles/bsp.dir/Src/bsp_init.c.obj eae2726ff6a3757a
58 250 7908532961211264 Modules/uart/CMakeFiles/uart.dir/src/uart.c.obj 4979c5baa76e360d
85 255 7908532961486410 BSP/CMakeFiles/bsp.dir/Src/bsp_w25qxx.c.obj 77426e3fb0f553e5
80 292 7908532961431553 BSP/CMakeFiles/bsp.dir/Src/bsp_board_manager.c.obj fb8792ab3e6d3cb9
73 297 7908532961370713 BSP/CMakeFiles/bsp.dir/Src/stm32f407vet6_board.c.obj e09f143ebf2c7378
159 301 7908532962227977 Modules/led/CMakeFiles/led.dir/src/led.c.obj f81c04216db73f61
61 343 7908532961246426 Modules/w25qxx/CMakeFiles/w25qxx.dir/Src/w25qxx.c.obj 1323ceff5f2de7f3
38 370 7908532961014109 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_gpio.c.obj b6850ab729e76492
91 380 7908532961550065 BSP/CMakeFiles/bsp.dir/Src/bsp_key.c.obj 1a935290b16864c0
243 395 7908532963069274 CMakeFiles/stm32f407vet6_cmake.dir/startup_stm32f407xx.s.obj b5a75378db83dc21
49 399 7908532961132664 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_spi.c.obj f7e0911aaf0b3af
164 404 7908532962281218 Middlewares/logging/CMakeFiles/logging.dir/src/logging.c.obj 50c1cd09ee8934e1
46 408 7908532961095920 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_delay.c.obj 582888277cddaf7e
221 413 7908532962844751 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/sysmem.c.obj c095fbfdd0d59cee
42 417 7908532961060292 HAL/CMakeFiles/hal.dir/Src/arch/stm32f4/hal_stm32f4_uart.c.obj df787ab831e6e2b4
228 442 7908532962910366 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/syscalls.c.obj f55e0cca90c94027
215 585 7908532962774905 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/stm32f4xx_hal_msp.c.obj 5411b055884697f
195 590 7908532962577474 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/stm32f4xx_it.c.obj d64fe2dfedc34157
176 648 7908532962398578 CMakeFiles/stm32f407vet6_cmake.dir/Core/Src/main.c.obj e02e91f67899b94
250 654 7908532963143327 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Core/Src/system_stm32f4xx.c.obj 98718870e24fdc98
255 660 7908532963193704 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c.obj b4cbb79cfdb0499f
292 694 7908532963558756 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c.obj 9e3e07f22c592e2e
301 707 7908532963645921 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c.obj 77f344137ebef544
297 711 7908532963601426 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c.obj 654897fed5ce4603
404 718 7908532964669944 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c.obj eef165e34f85222c
370 730 7908532964336140 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c.obj a8ff6a868245f407
417 731 7908532964806727 HAL/libhal.a 1cac9cc1eea4712c
343 764 7908532964064412 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.c.obj 7e56c4dd817904f1
399 765 7908532964630911 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c.obj 3a843a6f430facac
380 765 7908532964441095 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.c.obj d4262c855c2e4a85
413 777 7908532964763760 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.obj 1d3d25d51d2ed50
408 795 7908532964717836 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c.obj bf712b1a5a395d40
395 796 7908532964584987 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c.obj f9570c42488c1a6e
442 821 7908532965054374 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.c.obj b8e31886dd11f779
731 827 7908532967947346 Modules/delay/libdelay.a fa50f3f1c7df37b
738 841 7908532968023499 Modules/uart/libuart.a f980800b2f79773c
747 847 7908532968100728 Modules/w25qxx/libw25qxx.a 6740ff1d64083f6c
755 855 7908532968190455 Modules/led/libled.a 4975295d4e0f5144
841 959 7908532969051621 Middlewares/logging/liblogging.a df543b4167ac9a8e
590 976 7908532966534270 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c.obj 733ca570ebe27f54
847 980 7908532969098608 BSP/libbsp.a e0765276282a1d70
585 986 7908532966479014 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c.obj ae9df026f66922f1
986 1216 7908532970495241 stm32f407vet6_cmake.elf 4338dca859bbb8b4

Binary file not shown.

File diff suppressed because it is too large Load Diff

BIN
build_output.txt Normal file

Binary file not shown.