Skip to content

Commit eea1b82

Browse files
FRASTMkartben
authored andcommitted
drivers: flash: stm32 flash drivers supports the get_size API function
Implement the get_size flash device API function for the various stm32 This is just CONFIG_FLASH_SIZE expressed in Bytes or the FLASH_SIZE given by the LL driver Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 5dc5373 commit eea1b82

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

drivers/flash/flash_stm32.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <soc.h>
2020
#include <stm32_ll_bus.h>
2121
#include <stm32_ll_rcc.h>
22+
#include <stm32_ll_utils.h>
2223
#include <zephyr/logging/log.h>
2324

2425
#include "flash_stm32.h"
@@ -354,6 +355,16 @@ flash_stm32_get_parameters(const struct device *dev)
354355
return &flash_stm32_parameters;
355356
}
356357

358+
/* Gives the total logical device size in bytes and return 0. */
359+
static int flash_stm32_get_size(const struct device *dev, uint64_t *size)
360+
{
361+
ARG_UNUSED(dev);
362+
363+
*size = (uint64_t)LL_GetFlashSize() * 1024U;
364+
365+
return 0;
366+
}
367+
357368
static struct flash_stm32_priv flash_data = {
358369
.regs = (FLASH_TypeDef *) DT_INST_REG_ADDR(0),
359370
/* Getting clocks information from device tree description depending
@@ -372,6 +383,7 @@ static DEVICE_API(flash, flash_stm32_api) = {
372383
.write = flash_stm32_write,
373384
.read = flash_stm32_read,
374385
.get_parameters = flash_stm32_get_parameters,
386+
.get_size = flash_stm32_get_size,
375387
#ifdef CONFIG_FLASH_PAGE_LAYOUT
376388
.page_layout = flash_stm32_page_layout,
377389
#endif

drivers/flash/flash_stm32h7x.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,16 @@ static const struct flash_parameters *flash_stm32h7_get_parameters(const struct
836836
return &flash_stm32h7_parameters;
837837
}
838838

839+
/* Gives the total logical device size in bytes and return 0. */
840+
static int flash_stm32h7_get_size(const struct device *dev, uint64_t *size)
841+
{
842+
ARG_UNUSED(dev);
843+
844+
*size = (uint64_t)LL_GetFlashSize() * 1024U;
845+
846+
return 0;
847+
}
848+
839849
void flash_stm32_page_layout(const struct device *dev, const struct flash_pages_layout **layout,
840850
size_t *layout_size)
841851
{
@@ -893,6 +903,7 @@ static DEVICE_API(flash, flash_stm32h7_api) = {
893903
.write = flash_stm32h7_write,
894904
.read = flash_stm32h7_read,
895905
.get_parameters = flash_stm32h7_get_parameters,
906+
.get_size = flash_stm32h7_get_size,
896907
#ifdef CONFIG_FLASH_PAGE_LAYOUT
897908
.page_layout = flash_stm32_page_layout,
898909
#endif

drivers/flash/flash_stm32wb0x.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <stm32_ll_bus.h>
2323
#include <stm32_ll_rcc.h>
2424
#include <stm32_ll_system.h>
25+
#include <stm32_ll_utils.h>
2526

2627
#include <zephyr/logging/log.h>
2728
LOG_MODULE_REGISTER(flash_stm32wb0x, CONFIG_FLASH_LOG_LEVEL);
@@ -400,6 +401,8 @@ int flash_wb0x_erase(const struct device *dev, off_t offset, size_t size)
400401
const struct flash_parameters *flash_wb0x_get_parameters(
401402
const struct device *dev)
402403
{
404+
ARG_UNUSED(dev);
405+
403406
static const struct flash_parameters fp = {
404407
.write_block_size = WRITE_BLOCK_SIZE,
405408
.erase_value = 0xff,
@@ -408,6 +411,16 @@ const struct flash_parameters *flash_wb0x_get_parameters(
408411
return &fp;
409412
}
410413

414+
/* Gives the total logical device size in bytes and return 0. */
415+
static int flash_wb0x_get_size(const struct device *dev, uint64_t *size)
416+
{
417+
ARG_UNUSED(dev);
418+
419+
*size = (uint64_t)LL_GetFlashSize() * 1024U;
420+
421+
return 0;
422+
}
423+
411424
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
412425
void flash_wb0x_pages_layout(const struct device *dev,
413426
const struct flash_pages_layout **layout,
@@ -432,6 +445,7 @@ static DEVICE_API(flash, flash_wb0x_api) = {
432445
.write = flash_wb0x_write,
433446
.read = flash_wb0x_read,
434447
.get_parameters = flash_wb0x_get_parameters,
448+
.get_size = flash_wb0x_get_size,
435449
#ifdef CONFIG_FLASH_PAGE_LAYOUT
436450
.page_layout = flash_wb0x_pages_layout,
437451
#endif

drivers/flash/flash_stm32wba_fm.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ LOG_MODULE_REGISTER(flash_stm32wba, CONFIG_FLASH_LOG_LEVEL);
1818
#include "flash_manager.h"
1919
#include "flash_driver.h"
2020

21+
#include <stm32_ll_utils.h>
22+
2123
/* Let's wait for double the max erase time to be sure that the operation is
2224
* completed.
2325
*/
@@ -163,6 +165,16 @@ static const struct flash_parameters *
163165
return &flash_stm32_parameters;
164166
}
165167

168+
/* Gives the total logical device size in bytes and return 0. */
169+
static int flash_stm32h7_get_size(const struct device *dev, uint64_t *size)
170+
{
171+
ARG_UNUSED(dev);
172+
173+
*size = (uint64_t)LL_GetFlashSize() * 1024U;
174+
175+
return 0;
176+
}
177+
166178
static struct flash_stm32_priv flash_data = {
167179
.regs = (FLASH_TypeDef *) DT_INST_REG_ADDR(0),
168180
};
@@ -192,6 +204,7 @@ static DEVICE_API(flash, flash_stm32_api) = {
192204
.write = flash_stm32_write,
193205
.read = flash_stm32_read,
194206
.get_parameters = flash_stm32_get_parameters,
207+
.get_size = flash_stm32_get_size,
195208
#ifdef CONFIG_FLASH_PAGE_LAYOUT
196209
.page_layout = flash_stm32wba_page_layout,
197210
#endif

0 commit comments

Comments
 (0)