![]() |
Midnight Sun Firmware
|
bootloader Firmware More...
Classes | |
struct | BootloaderStateData |
Private Bootloader State Storage. More... | |
struct | BootCanTiming |
Selection for the supported CAN Bitrates. More... | |
struct | CanSettings |
CAN Settings. More... | |
struct | Boot_CanMessage |
CAN message structure. More... | |
struct | BootloaderDatagram |
Datagram message definition. More... | |
Macros | |
#define | FLASH_START_ADDRESS_LINKERSCRIPT ((uint32_t)&_flash_start) |
Flash start address as defined in the linkerscripts. | |
#define | FLASH_SIZE_LINKERSCRIPT ((size_t)&_flash_size) |
Flash size as defined in the linkerscripts. | |
#define | FLASH_PAGE_SIZE_LINKERSCRIPT ((size_t)&_flash_page_size) |
Flash page size as defined in the linkerscripts. | |
#define | APPLICATION_START_ADDRESS ((uint32_t)&_application_start) |
Application start address as defined in the linkerscripts. | |
#define | APPLICATION_SIZE ((size_t)&_application_size) |
Application size as defined in the linkerscripts. | |
#define | BOOTLOADER_START_ADDRESS ((uint32_t)&_bootloader_start) |
Bootloader start address as defined in the linkerscripts. | |
#define | BOOTLOADER_SIZE ((size_t)&_bootloader_size) |
Bootloader size as defined in the linkerscripts. | |
#define | SRAM_START_ADDRESS ((uint32_t)&_sram_start) |
SRAM start address as defined in the linkerscripts. | |
#define | SRAM_SIZE ((size_t)&_sram_size) |
SRAM size as defined in the linkerscripts. | |
#define | CAN_HW_BASE CAN1 |
#define | ACK 0U |
ACK defined as 0. | |
#define | NACK 1U |
NACK defined as 1. | |
#define | BYTES_TO_WORD(bytes) (bytes / 4) |
Convert bytes to number of words for ARM32 system. | |
#define | NUM_FLASH_PAGES 128U |
256KB of memory / 2KB per page | |
#define | BOOTLOADER_PAGE_BYTES ((size_t)0x800) |
2KB per flash page as per datasheet | |
#define | BOOTLOADER_FLASH_WORD_SIZE 4U |
ARM32 Word size is 4 bytes. | |
#define | BOOTLOADER_ADDR_TO_PAGE(addr) (((uintptr_t)(addr) - (uintptr_t)APPLICATION_START_ADDRESS) / BOOTLOADER_PAGE_BYTES) |
Convert memory address to page number. More... | |
#define | BOOTLOADER_PAGE_TO_ADDR(page) ((uintptr_t)(page) * (uintptr_t)BOOTLOADER_PAGE_BYTES + (uintptr_t)APPLICATION_START_ADDRESS) |
Convert page number to memory address. More... | |
Typedefs | |
typedef struct CanSettings | Boot_CanSettings |
CAN Settings. More... | |
Functions | |
BootloaderError | bootloader_init (void) |
Initialize the bootloader. More... | |
BootloaderError | bootloader_run (Boot_CanMessage *msg) |
Run the bootloader. More... | |
BootloaderError | bootloader_jump_app (void) |
Jump application. More... | |
BootloaderError | boot_can_init (const Boot_CanSettings *settings) |
Initialize the CAN interface for the bootloader. More... | |
BootloaderError | boot_can_transmit (uint32_t id, bool extended, const uint8_t *data, size_t len) |
Transmit a CAN message in the bootloader. More... | |
BootloaderError | boot_can_receive (Boot_CanMessage *const msg) |
Receive a CAN message in the bootloader. More... | |
BootloaderDatagram | deserialize_datagram (Boot_CanMessage *msg, uint16_t *target_nodes) |
Deserialize an incoming CAN message. More... | |
void | send_ack_datagram (bool ack, BootloaderError error) |
Send Bootloader ACK/NACK message over CAN. More... | |
BootloaderError | boot_crc32_init (void) |
Initialize the CRC hardware component. More... | |
uint32_t | boot_crc32_calculate (const uint32_t *buffer, size_t buffer_len) |
Calculate a CRC32 on a provided data buffer. More... | |
void | boot_align_to_32bit_words (uint8_t *buffer, size_t *buffer_len) |
Align a provided data buffer to the 4-byte boundary. More... | |
BootloaderError | boot_flash_write (uintptr_t address, uint8_t *buffer, size_t buffer_len) |
Write to flash memory. More... | |
BootloaderError | boot_flash_erase (uint8_t start_page, uint8_t num_pages) |
Erase some number of flash pages. More... | |
BootloaderError | boot_flash_read (uintptr_t address, uint8_t *buffer, size_t buffer_len) |
Read from flash memory. More... | |
BootloaderError | boot_verify_flash_memory (void) |
Verify that the flash memory is not erased. More... | |
void | protect_bootloader_memory (uint32_t bootloader_start_address, uint32_t bootloader_size) |
Protect the bootloader memory provided the bootloaders start address and size. More... | |
bootloader Firmware
#define BOOTLOADER_ADDR_TO_PAGE | ( | addr | ) | (((uintptr_t)(addr) - (uintptr_t)APPLICATION_START_ADDRESS) / BOOTLOADER_PAGE_BYTES) |
Convert memory address to page number.
addr | Address to be converted to page number |
#define BOOTLOADER_PAGE_TO_ADDR | ( | page | ) | ((uintptr_t)(page) * (uintptr_t)BOOTLOADER_PAGE_BYTES + (uintptr_t)APPLICATION_START_ADDRESS) |
Convert page number to memory address.
page | Page number |
typedef struct CanSettings Boot_CanSettings |
CAN Settings.
TX Pin will transmit data. RX pin will receive data. The bitrate is the number of bits sent per second. The device ID is the CAN ID of the STM32 node. Loopback will internally connect the transmit and receive CAN lines for testing. Silent mode is used for only listening to the bus.
enum Boot_CanBitrate |
enum BootloaderCanID |
Bootloader reserved CAN arbitration IDs.
enum BootloaderError |
Bootloader error definitions.
enum BootloaderStates |
Bootloader State Machine.
void boot_align_to_32bit_words | ( | uint8_t * | buffer, |
size_t * | buffer_len | ||
) |
Align a provided data buffer to the 4-byte boundary.
This prevents hard faults when writing to flash memory, ensuring all our flash is 4-byte aligned
buffer | Pointer to the data buffer to be aligned |
buffer_len | Length of the data buffer |
BootloaderError boot_can_init | ( | const Boot_CanSettings * | settings | ) |
Initialize the CAN interface for the bootloader.
BootloaderError boot_can_receive | ( | Boot_CanMessage *const | msg | ) |
Receive a CAN message in the bootloader.
msg | Pointer to the message that will be updated with incoming data |
BootloaderError boot_can_transmit | ( | uint32_t | id, |
bool | extended, | ||
const uint8_t * | data, | ||
size_t | len | ||
) |
Transmit a CAN message in the bootloader.
id | CAN Message arbitration Id |
extended | Boolean flag to select 11-bit vs 29-bit CAN transmission |
data | Pointer to the data buffer to transmit |
len | Length of the data buffer |
uint32_t boot_crc32_calculate | ( | const uint32_t * | buffer, |
size_t | buffer_len | ||
) |
Calculate a CRC32 on a provided data buffer.
buffer | Pointer to the data buffer to be checksummed |
buffer_len | Length of the data buffer |
BootloaderError boot_crc32_init | ( | void | ) |
Initialize the CRC hardware component.
BootloaderError boot_flash_erase | ( | uint8_t | start_page, |
uint8_t | num_pages | ||
) |
Erase some number of flash pages.
start_page | Initial page number to erase |
num_pages | Number of pages to erase |
BootloaderError boot_flash_read | ( | uintptr_t | address, |
uint8_t * | buffer, | ||
size_t | buffer_len | ||
) |
Read from flash memory.
address | Base memory address to read from |
buffer | Pointer to the data buffer |
buffer_len | Length of the data buffer |
BootloaderError boot_flash_write | ( | uintptr_t | address, |
uint8_t * | buffer, | ||
size_t | buffer_len | ||
) |
Write to flash memory.
address | Base memory address to write to |
buffer | Pointer to the data buffer |
buffer_len | Length of the data buffer |
BootloaderError boot_verify_flash_memory | ( | void | ) |
Verify that the flash memory is not erased.
This checks the entire application flash memory to ensure it is not entirely erased
BootloaderError bootloader_init | ( | void | ) |
Initialize the bootloader.
BootloaderError bootloader_jump_app | ( | void | ) |
Jump application.
Exits bootloader and jumps to main application
BootloaderError bootloader_run | ( | Boot_CanMessage * | msg | ) |
Run the bootloader.
msg | Pointer to incoming CAN data to feed the bootloader |
BootloaderDatagram deserialize_datagram | ( | Boot_CanMessage * | msg, |
uint16_t * | target_nodes | ||
) |
Deserialize an incoming CAN message.
This will deserialize a CAN message and produce a datagram
msg | Pointer to the incoming CAN message |
target_nodes | Pointer that will be updated with the target MCU Id |
void protect_bootloader_memory | ( | uint32_t | bootloader_start_address, |
uint32_t | bootloader_size | ||
) |
Protect the bootloader memory provided the bootloaders start address and size.
bootloader_start_address | The start address defined in the linkerscript |
bootloader_size | The bootloader size defined in the linkerscript |
void send_ack_datagram | ( | bool | ack, |
BootloaderError | error | ||
) |
Send Bootloader ACK/NACK message over CAN.
ack | Boolean ACK status. 0: ACK, 1: NACK |
error | Bootloader error status for further information |