优化实现串口驱动,SPI驱动 W25QXX还需要初始化验证修复
This commit is contained in:
107
BSP/Inc/bsp_board.h
Normal file
107
BSP/Inc/bsp_board.h
Normal file
@ -0,0 +1,107 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_board.h
|
||||
* @brief : Board support package board abstraction header file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_BOARD_H
|
||||
#define BSP_BOARD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
|
||||
/**
|
||||
* @brief Board LED configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port;
|
||||
hal_gpio_pin_t pin;
|
||||
hal_gpio_mode_t mode;
|
||||
hal_gpio_speed_t speed;
|
||||
hal_gpio_pull_t pull;
|
||||
} bsp_led_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board button configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
hal_gpio_port_t port;
|
||||
hal_gpio_pin_t pin;
|
||||
hal_gpio_mode_t mode;
|
||||
hal_gpio_speed_t speed;
|
||||
hal_gpio_pull_t pull;
|
||||
} bsp_button_config_t;
|
||||
|
||||
/**
|
||||
* @brief UART instance identifier definitions
|
||||
*/
|
||||
typedef enum {
|
||||
BSP_UART_INSTANCE_1 = 0,
|
||||
BSP_UART_INSTANCE_2,
|
||||
BSP_UART_INSTANCE_3,
|
||||
BSP_UART_INSTANCE_4,
|
||||
BSP_UART_INSTANCE_5,
|
||||
BSP_UART_INSTANCE_6,
|
||||
BSP_UART_INSTANCE_MAX
|
||||
} bsp_uart_instance_t;
|
||||
|
||||
/**
|
||||
* @brief Board UART configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
bsp_uart_instance_t instance;
|
||||
uint32_t baudrate;
|
||||
hal_uart_parity_t parity;
|
||||
hal_uart_stopbits_t stopbits;
|
||||
hal_uart_databits_t databits;
|
||||
hal_gpio_port_t tx_port;
|
||||
hal_gpio_pin_t tx_pin;
|
||||
hal_gpio_port_t rx_port;
|
||||
hal_gpio_pin_t rx_pin;
|
||||
} bsp_uart_config_t;
|
||||
|
||||
/**
|
||||
* @brief Board peripheral initialization function type
|
||||
*/
|
||||
typedef void (*bsp_periph_init_func_t)(const void* config);
|
||||
|
||||
/**
|
||||
* @brief Board configuration structure
|
||||
*/
|
||||
typedef struct {
|
||||
const char* name;
|
||||
bsp_led_config_t led;
|
||||
bsp_button_config_t button;
|
||||
bsp_uart_config_t uart;
|
||||
|
||||
/* Initialization function pointers */
|
||||
bsp_periph_init_func_t led_init;
|
||||
bsp_periph_init_func_t button_init;
|
||||
bsp_periph_init_func_t uart_init;
|
||||
|
||||
/* Additional board-specific configuration */
|
||||
uint32_t clock_speed;
|
||||
uint8_t uart_count;
|
||||
} bsp_board_config_t;
|
||||
|
||||
/**
|
||||
* @brief STM32F407VET6 board configuration extern declaration
|
||||
*/
|
||||
extern const bsp_board_config_t stm32f407vet6_board_config;
|
||||
|
||||
/**
|
||||
* @brief Board hardware initialization
|
||||
*/
|
||||
void bsp_board_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get board name
|
||||
* @retval Board name string
|
||||
*/
|
||||
const char* bsp_board_get_name(void);
|
||||
|
||||
#endif /* BSP_BOARD_H */
|
||||
63
BSP/Inc/bsp_board_manager.h
Normal file
63
BSP/Inc/bsp_board_manager.h
Normal file
@ -0,0 +1,63 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_board_manager.h
|
||||
* @brief : Board support package manager header file
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_BOARD_MANAGER_H
|
||||
#define BSP_BOARD_MANAGER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "bsp_board.h"
|
||||
|
||||
/**
|
||||
* @brief Get number of supported boards
|
||||
* @retval Number of supported boards
|
||||
*/
|
||||
uint8_t bsp_board_get_count(void);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval Pointer to board configuration structure, NULL if invalid index
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Get board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval Pointer to board configuration structure, NULL if not found
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by index
|
||||
* @param index: Board configuration index
|
||||
* @retval 0 if successful, -1 if invalid index
|
||||
*/
|
||||
int8_t bsp_board_set_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief Set current board configuration by name
|
||||
* @param name: Board name string
|
||||
* @retval 0 if successful, -1 if not found
|
||||
*/
|
||||
int8_t bsp_board_set_by_name(const char* name);
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to current board configuration structure
|
||||
*/
|
||||
const bsp_board_config_t* bsp_board_get_config(void);
|
||||
|
||||
/**
|
||||
* @brief Get current board index
|
||||
* @retval Current board index
|
||||
*/
|
||||
uint8_t bsp_board_get_current_index(void);
|
||||
|
||||
#endif /* BSP_BOARD_MANAGER_H */
|
||||
@ -11,6 +11,7 @@
|
||||
#define BSP_CONFIG_H
|
||||
|
||||
#include "hal_gpio.h"
|
||||
#include "hal_uart.h"
|
||||
|
||||
/**
|
||||
* @brief Board name definition
|
||||
@ -32,7 +33,7 @@
|
||||
/**
|
||||
* @brief UART hardware configuration
|
||||
*/
|
||||
#define BSP_UART_INSTANCE USART1
|
||||
#define BSP_UART_INSTANCE BSP_UART_INSTANCE_1
|
||||
#define BSP_UART_BAUDRATE 115200
|
||||
#define BSP_UART_PARITY HAL_UART_PARITY_NONE
|
||||
#define BSP_UART_STOPBITS HAL_UART_STOPBITS_1
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
#ifndef BSP_INIT_H
|
||||
#define BSP_INIT_H
|
||||
|
||||
#include "bsp_board.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize board support package
|
||||
*/
|
||||
@ -26,4 +28,10 @@ void bsp_gpio_init(void);
|
||||
*/
|
||||
const char* bsp_get_board_name(void);
|
||||
|
||||
/**
|
||||
* @brief Get current board configuration
|
||||
* @retval Pointer to board configuration structure
|
||||
*/
|
||||
const bsp_board_config_t* bsp_get_board_config(void);
|
||||
|
||||
#endif /* BSP_INIT_H */
|
||||
|
||||
86
BSP/Inc/bsp_w25qxx.h
Normal file
86
BSP/Inc/bsp_w25qxx.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_w25qxx.h
|
||||
* @brief : BSP layer for W25QXX flash memory
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef BSP_W25QXX_H
|
||||
#define BSP_W25QXX_H
|
||||
|
||||
#include "w25qxx.h"
|
||||
#include "hal_spi.h"
|
||||
#include "hal_gpio.h"
|
||||
|
||||
/**
|
||||
* @brief W25QXX chip select pin configuration
|
||||
*/
|
||||
#define W25QXX_CS_PORT HAL_GPIO_PORT_B
|
||||
#define W25QXX_CS_PIN HAL_GPIO_PIN_0
|
||||
|
||||
/**
|
||||
* @brief W25QXX SPI instance
|
||||
*/
|
||||
#define W25QXX_SPI_INSTANCE HAL_SPI_INSTANCE_1
|
||||
|
||||
/**
|
||||
* @brief Initialize W25QXX flash memory
|
||||
* @retval true if initialization is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get W25QXX device information
|
||||
* @param info Pointer to device information structure to fill
|
||||
* @retval true if successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_get_device_info(w25qxx_device_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief Read data from W25QXX flash memory
|
||||
* @param address Starting address to read from
|
||||
* @param data Pointer to data buffer to store read data
|
||||
* @param size Size of data to read
|
||||
* @retval true if read is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_read(uint32_t address, uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Write data to W25QXX flash memory
|
||||
* @param address Starting address to write to
|
||||
* @param data Pointer to data buffer to write
|
||||
* @param size Size of data to write
|
||||
* @retval true if write is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_write(uint32_t address, const uint8_t *data, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Erase 4KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_4kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase 32KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_32kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase 64KB block
|
||||
* @param address Address within the block to erase
|
||||
* @retval true if erase is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_erase_block_64kb(uint32_t address);
|
||||
|
||||
/**
|
||||
* @brief Erase entire chip
|
||||
* @retval true if erase is successful, false otherwise
|
||||
*/
|
||||
bool bsp_w25qxx_erase_chip(void);
|
||||
|
||||
#endif /* BSP_W25QXX_H */
|
||||
Reference in New Issue
Block a user