Skip to content

Commit e6631c0

Browse files
committed
STM32: adjust flash.get_page_size() to minimum programable size
Users of FlashIAP usually get the minimum programable size by calling flash.get_page_size(), so let's return the minimum to allows a most efficient usage of flash. For F4 devices, this is 1 byte. For L0 and L1 devices, this is a word (4 bytes). For L4 devices, this is a double word (8 bytes).
1 parent 3de2ce9 commit e6631c0

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

targets/TARGET_STM/TARGET_STM32F4/flash_api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
129129

130130
uint32_t flash_get_page_size(const flash_t *obj)
131131
{
132-
// not applicable for STM32F4
133-
return (0x4000); // minimum sector size
132+
// Flash of STM32F4 devices can be programed 1 byte at a time
133+
return (1);
134134
}
135+
135136
uint32_t flash_get_start_address(const flash_t *obj)
136137
{
137138
return FLASH_BASE;

targets/TARGET_STM/TARGET_STM32L0/flash_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) {
128128
}
129129

130130
uint32_t flash_get_page_size(const flash_t *obj) {
131-
return FLASH_PAGE_SIZE;
131+
/* Page size is the minimum programable size, which 4 bytes */
132+
return 4;
132133
}
133134

134135
uint32_t flash_get_start_address(const flash_t *obj) {

targets/TARGET_STM/TARGET_STM32L1/flash_api.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
127127

128128
uint32_t flash_get_page_size(const flash_t *obj)
129129
{
130-
return FLASH_PAGE_SIZE;
130+
/* Page size is the minimum programable size, which 4 bytes */
131+
return 4;
131132
}
132133

133134
uint32_t flash_get_start_address(const flash_t *obj)

targets/TARGET_STM/TARGET_STM32L4/flash_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address) {
221221
* @return The size of a page
222222
*/
223223
uint32_t flash_get_page_size(const flash_t *obj) {
224-
/* considering 1 sector = 1 page */
225-
return FLASH_PAGE_SIZE;
224+
/* Page size is the minimum programable size, which 8 bytes */
225+
return 8;
226226
}
227227

228228
/** Get start address for the flash region

0 commit comments

Comments
 (0)