Add a production-ready, educational bootloader extension for STM32 MCUs. Core features: - Custom binary protocol with CRC16/CRC32 verification - AES-256 encryption for firmware security - Dual-bank firmware management with rollback support - Version management and firmware validation - Modular architecture with BSP abstraction layer Project structure: - include/: Header files (bootloader.h, bsp_flash.h, bsp_uart.h) - src/: Core implementation (bootloader, protocol, crypto, firmware manager) - port/: MCU-specific adaptation layer (STM32F4xx) - docs/: Documentation (integration guide, porting guide) Supported platforms: - STM32F4xx (primary) - STM32F1xx (via porting) Quick start: 1. Copy extension module to project 2. Configure bootloader_config.h 3. Modify linker script for APP_BASE_ADDR 4. Build and flash bootloader to 0x08000000 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
45 lines
1.0 KiB
C
45 lines
1.0 KiB
C
#include "stm32f4xx_hal_uart.h"
|
|
#include <stdint.h>
|
|
#define UART_HANDLE huart1
|
|
extern UART_HandleTypeDef UART_HANDLE;
|
|
|
|
int uart_port_init(uint32_t baudrate) {
|
|
|
|
if (UART_HANDLE.Init.BaudRate != baudrate) {
|
|
UART_HANDLE.Init.BaudRate = baudrate;
|
|
if (HAL_UART_Init(&UART_HANDLE) != HAL_OK) {
|
|
return -1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int uart_port_send(const uint8_t *data, uint32_t length) {
|
|
if (HAL_UART_Transmit(&UART_HANDLE, (uint8_t *)data, length, 1000) != HAL_OK) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int uart_port_recv(uint8_t *buffer, uint32_t length, uint32_t timeout_ms) {
|
|
if (HAL_UART_Receive(&UART_HANDLE, buffer, length, timeout_ms) != HAL_OK) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void uart_port_deinit(void) {
|
|
HAL_UART_DeInit(&UART_HANDLE);
|
|
}
|
|
|
|
static const bsp_uart_ops_t uart_ops = {
|
|
.init = uart_port_init,
|
|
.send = uart_port_send,
|
|
.recv = uart_port_recv,
|
|
.deinit = uart_port_deinit,
|
|
};
|
|
|
|
void uart_port_register(void) {
|
|
bsp_uart_register(&uart_ops);
|
|
}
|