#include <stdint.h>
#include "stm32l4xx_hal.h"
#include "stm32l4xx_hal_flash.h"
Go to the source code of this file.
|
| enum | STM32_INTERNAL_FLASH_memory_region_addresses_t {
STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_ADDRESS = 0x20000000
, STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_2_ADDRESS = 0x10000000
, STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_3_ADDRESS = 0x20040000
, STM32_INTERNAL_FLASH_MEMORY_REGION_FLASH_BANK_1_ADDRESS = 0x08000000
,
STM32_INTERNAL_FLASH_MEMORY_REGION_FLASH_BANK_2_ADDRESS = 0x08100000
} |
| | Flash Partitions. More...
|
| enum | STM32_internal_flash_write_return_t {
STM32_INTERNAL_FLASH_WRITE_SUCCESS
, STM32_INTERNAL_FLASH_WRITE_ADDRESS_TOO_LOW
, STM32_INTERNAL_FLASH_WRITE_ADDRESS_TOO_HIGH
, STM32_INTERNAL_FLASH_WRITE_ADDRESS_OVERLAPS_BOTH_FLASH_BANKS
,
STM32_INTERNAL_FLASH_WRITE_UNLOCK_FAILED
, STM32_INTERNAL_FLASH_WRITE_LOCK_FAILED
, STM32_INTERNAL_FLASH_WRITE_OPERATION_FAILED
} |
|
| STM32_internal_flash_write_return_t | STM32_internal_flash_write (uint32_t address, uint8_t *data, uint32_t length, STM32_internal_flash_write_status_t *status) |
| | Writes data to the flash memory in chunks of 8 bytes.
|
| uint8_t | STM32_internal_flash_read (uint32_t address, uint8_t *buffer, uint32_t length) |
| | Reads data from the flash memory.
|
| uint8_t | STM32_internal_flash_page_erase (uint8_t flash_bank, uint16_t start_page_erase, uint16_t number_of_pages_to_erase, uint32_t *page_error) |
| | Erase pages from provided flash bank of flash memory.
|
| uint8_t | STM32_internal_flash_bank_erase (uint8_t flash_bank, uint32_t *bank_erase_error) |
| | Erase flash bank.
|
| uint8_t | STM32_internal_flash_get_option_bytes (FLASH_OBProgramInitTypeDef *ob_data) |
| | Gets option bytes configuration from the stm32 internal flash memory.
|
| uint8_t | STM32_internal_flash_set_active_flash_bank (uint8_t wanted_active_flash_bank) |
| | Sets the active flash bank to either 1 or 2 (only if it is different than the current active flash bank).
|
| uint8_t | STM32_internal_flash_get_active_flash_bank () |
| | Returns active flash bank.
|
| uint8_t | STM32_internal_flash_what_bank_is_this_address (uint32_t address, uint32_t length) |
| | Data-only operation to determine what bank (1 or 2) the address is in.
|
| uint8_t | STM32_internal_flash_calculate_sha256 (uint32_t address, uint32_t length, uint8_t hash[32]) |
| | Calculates the SHA256 hash of a chunk of STM32 internal flash.
|
◆ FLASH_BANK_1_END_PAGE
| #define FLASH_BANK_1_END_PAGE 255u |
◆ FLASH_BANK_1_START_PAGE
| #define FLASH_BANK_1_START_PAGE 0u |
◆ FLASH_BANK_2_END_PAGE
| #define FLASH_BANK_2_END_PAGE 511u |
◆ FLASH_BANK_2_START_PAGE
| #define FLASH_BANK_2_START_PAGE 256u |
◆ NUMBER_OF_PAGES_PER_FLASH_BANK
| #define NUMBER_OF_PAGES_PER_FLASH_BANK 256u |
◆ STM32_INTERNAL_FLASH_memory_region_addresses_t
Flash Partitions.
- Note
- look in the STM32L4R5XX_FLASH.ld file to see the address of each partition, update this as needed
| Enumerator |
|---|
| STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_ADDRESS | |
| STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_2_ADDRESS | |
| STM32_INTERNAL_FLASH_MEMORY_REGION_RAM_3_ADDRESS | |
| STM32_INTERNAL_FLASH_MEMORY_REGION_FLASH_BANK_1_ADDRESS | |
| STM32_INTERNAL_FLASH_MEMORY_REGION_FLASH_BANK_2_ADDRESS | |
◆ STM32_internal_flash_write_return_t
| Enumerator |
|---|
| STM32_INTERNAL_FLASH_WRITE_SUCCESS | |
| STM32_INTERNAL_FLASH_WRITE_ADDRESS_TOO_LOW | |
| STM32_INTERNAL_FLASH_WRITE_ADDRESS_TOO_HIGH | |
| STM32_INTERNAL_FLASH_WRITE_ADDRESS_OVERLAPS_BOTH_FLASH_BANKS | |
| STM32_INTERNAL_FLASH_WRITE_UNLOCK_FAILED | |
| STM32_INTERNAL_FLASH_WRITE_LOCK_FAILED | |
| STM32_INTERNAL_FLASH_WRITE_OPERATION_FAILED | |
◆ STM32_internal_flash_bank_erase()
| uint8_t STM32_internal_flash_bank_erase |
( |
uint8_t | flash_bank, |
|
|
uint32_t * | bank_erase_error ) |
Erase flash bank.
- Parameters
-
| flash_bank | 1 or 2, which flash bank to erase |
| page_error | address of page which failed on error, defaults to UINT32_MAX on success |
- Returns
- 0 on success, more than 0 on error
◆ STM32_internal_flash_calculate_sha256()
| uint8_t STM32_internal_flash_calculate_sha256 |
( |
uint32_t | address, |
|
|
uint32_t | length, |
|
|
uint8_t | hash[32] ) |
Calculates the SHA256 hash of a chunk of STM32 internal flash.
- Parameters
-
| address | Start address in flash memory |
| length | Number of bytes to hash |
| hash | Output buffer (must be 32 bytes) |
- Returns
- 0 on success, >0 on error. 30 on invalid ranges.
◆ STM32_internal_flash_get_active_flash_bank()
| uint8_t STM32_internal_flash_get_active_flash_bank |
( |
| ) |
|
Returns active flash bank.
- Returns
- 1 is Flash Bank 1, 2 is Flash Bank 2
◆ STM32_internal_flash_get_option_bytes()
| uint8_t STM32_internal_flash_get_option_bytes |
( |
FLASH_OBProgramInitTypeDef * | ob_data | ) |
|
Gets option bytes configuration from the stm32 internal flash memory.
- Parameters
-
| ob_data | pointer to an FLASH_OBProgramInitTypeDef structure that contains the configuration information for the programming. |
- Returns
- 0 always
◆ STM32_internal_flash_page_erase()
| uint8_t STM32_internal_flash_page_erase |
( |
uint8_t | flash_bank, |
|
|
uint16_t | start_page_erase, |
|
|
uint16_t | number_of_pages_to_erase, |
|
|
uint32_t * | page_error ) |
Erase pages from provided flash bank of flash memory.
- Parameters
-
| flash_bank | 1 or 2, which flash bank to erase |
| start_page_erase | what page to start erasing from (0-255 for bank 1, 256-511 for bank 2, inclusive) |
| number_of_pages_to_erase | how many pages to erase. MAX is 256, MIN is 1. |
| page_error | address of page which failed on error, defaults to UINT32_MAX on success |
- Returns
- 0 on success, 1 if HAL_FLASH_Unlock() failed, 2 if HAL_FLASH_Lock() failed
◆ STM32_internal_flash_read()
| uint8_t STM32_internal_flash_read |
( |
uint32_t | address, |
|
|
uint8_t * | buffer, |
|
|
uint32_t | length ) |
Reads data from the flash memory.
- Parameters
-
| address | address to start reading from |
| buffer | buffer to store the read data, must be length long |
| length | number of bytes to read |
- Returns
- 0 on success, > 0 on error
◆ STM32_internal_flash_set_active_flash_bank()
| uint8_t STM32_internal_flash_set_active_flash_bank |
( |
uint8_t | wanted_active_flash_bank | ) |
|
Sets the active flash bank to either 1 or 2 (only if it is different than the current active flash bank).
On Success, will load application in desired flash bank
By Default, the active flash bank is 1
- Parameters
-
| wanted_active_flash_bank | 1 or 2 |
- Returns
- 0 on success, > 0 otherwise
◆ STM32_internal_flash_what_bank_is_this_address()
| uint8_t STM32_internal_flash_what_bank_is_this_address |
( |
uint32_t | address, |
|
|
uint32_t | length ) |
Data-only operation to determine what bank (1 or 2) the address is in.
- Parameters
-
- Returns
- 1 if the range is completely in BANK_1. 2 if the range is completely in BANK_2. 0 if the range falls outside of the banks, or overlaps the two banks.
◆ STM32_internal_flash_write()
Writes data to the flash memory in chunks of 8 bytes.
- Parameters
-
| address | Address in the flash memory where the data will be written. |
| data | uint8_t buffer containing the data to be written. |
| length | Length of the data to be written. |
- Returns
- 0 on success, > 0 on error
- Note
- Writes data in chunks of 8 bytes. Ex: Suppose we wanted to write to address 0x00, and suppose that at address 0x00, the first 8 bytes looks like the following: [1,2,3,4,5,6,7,8]. If we wanted to write [25,26,27,28], it would result in the following: [25,26,27,28,0,0,0,0], clearing the rest of the bytes.