STM32 Bootloader
Customizable Bootloader for STM32 microcontrollers
flash.c File Reference

This file contains the MCU internal flash driver implementation for read, write, erase, and write protection operations. More...

#include "flash.h"
#include "mcu_hal.h"
#include "rcc.h"
#include <string.h>

Go to the source code of this file.

Macros

#define FLASH_SIZE_WRAPPER   (uint32_t)(FLASH_SIZE)
 
#define FLASH_BANK_SIZE_WRAPPER   (uint32_t)(FLASH_BANK_SIZE)
 
#define FLASH_PAGE_NB_PER_BANK    (uint32_t)(FLASH_BANK_SIZE_WRAPPER / FLASH_PAGE_SIZE)
 

Functions

static bool FlashPerformErase (const uint32_t address, const uint32_t length)
 Private helper function to perform the actual erase of the required flash pages. More...
 
static uint32_t FlashPerformWrite (const uint8_t *const data, const uint32_t address, const uint32_t length)
 Private helper function to perform the actual writing of the provided data into the flash. More...
 
static uint32_t FlashGetBank (const uint32_t address)
 Get the bank where the provided address is located. More...
 
static uint32_t FlashGetPage (const uint32_t address)
 Get the page number where the provided address is located. More...
 
static bool FlashCheckIfPageRangesOverlap (const uint32_t range1Start, const uint32_t range1End, const uint32_t range2Start, const uint32_t range2End)
 Check if two flash page ranges overlap. More...
 
void FlashClearErrorFlags (void)
 Clear all flash error flags.
 
bool FlashCheckIfDataFits (const uint32_t address, const uint32_t length)
 Check if an array of data fits into the flash. More...
 
bool FlashCheckIfWriteProtectionEnabled (const uint32_t address, const uint32_t length)
 Check if flash write protection is enabled for the specified region. More...
 
bool FlashDisableWriteProtection (void)
 Disable flash write protection for the application area. More...
 
bool FlashEnableWriteProtection (const uint32_t address, const uint32_t length)
 Enable flash write protection for the specified region. More...
 
bool FlashCompare (const uint8_t *const data, const uint32_t address, const uint32_t length)
 Compare buffer content with microcontroller flash content. More...
 
uint32_t FlashRead (uint8_t *const data, const uint32_t address, const uint32_t length)
 Read data from the microcontroller flash. More...
 
uint32_t FlashWrite (const uint8_t *const data, const uint32_t address, const uint32_t length)
 Write data into the microcontroller flash. More...
 
void FlashRemapMemoryToSystemFlash (void)
 Remap the microcontroller flash memory to the built-in system flash memory. More...
 

Detailed Description

This file contains the MCU internal flash driver implementation for read, write, erase, and write protection operations.

STM32 Bootloader

Author
Akos Pasztor

Definition in file flash.c.