Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Stm32SPIFFS.cxx
Go to the documentation of this file.
1
36#include "Stm32SPIFFS.hxx"
37#include "spiffs.h"
38#include "stm32f_hal_conf.hxx"
39
40//
41// Stm32SPIFFS::flash_read()
42//
43int32_t Stm32SPIFFS::flash_read(uint32_t addr, uint32_t size, uint8_t *dst)
44{
45 HASSERT(addr >= fs_->cfg.phys_addr &&
46 (addr + size) <= (fs_->cfg.phys_addr + fs_->cfg.phys_size));
47
48 flash_.read(addr, size, dst);
49
50 return 0;
51}
52
53//
54// Stm32SPIFFS::flash_write()
55//
56int32_t Stm32SPIFFS::flash_write(uint32_t addr, uint32_t size, uint8_t *src)
57{
58 HASSERT(addr >= fs_->cfg.phys_addr &&
59 (addr + size) <= (fs_->cfg.phys_addr + fs_->cfg.phys_size));
60
61 flash_.write(addr, size, src);
62
63 return 0;
64}
65
66//
67// Stm32SPIFFS::flash_erase()
68//
69int32_t Stm32SPIFFS::flash_erase(uint32_t addr, uint32_t size)
70{
71 HASSERT(addr >= fs_->cfg.phys_addr &&
72 (addr + size) <= (fs_->cfg.phys_addr + fs_->cfg.phys_size));
73
74 flash_.erase(addr, size);
75
76/*
77 This is the old flash erase code. This will be needed in Stm32Flash when we want to support the F3, F0 or L4 MCUs.
78
79
80 extern char __flash_fs_start;
81 extern char __flash_fs_sector_start;
82
83 FLASH_EraseInitTypeDef erase_init;
84 memset(&erase_init, 0, sizeof(erase_init));
85
86 erase_init.TypeErase = TYPEERASE_SECTORS;
87 unsigned offset = addr - (unsigned)&__flash_fs_start;
88 HASSERT((size % ERASE_PAGE_SIZE) == 0);
89 HASSERT((offset % ERASE_PAGE_SIZE) == 0);
90 unsigned sector = offset / ERASE_PAGE_SIZE;
91 erase_init.Sector = ((unsigned)(&__flash_fs_sector_start)) + sector;
92 erase_init.NbSectors = size / ERASE_PAGE_SIZE;
93 erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3; // 3.3 to 3.6 volts powered.
94 HAL_FLASH_Unlock();
95 uint32_t sector_error;
96 HASSERT(HAL_OK == HAL_FLASHEx_Erase(&erase_init, &sector_error));
97 HAL_FLASH_Lock();
98*/
99
100 return 0;
101}
102
spiffs * fs_
file system instance metadata
Definition SPIFFS.hxx:182
int32_t flash_read(uint32_t addr, uint32_t size, uint8_t *dst) override
SPIFFS callback to read flash, in context.
int32_t flash_erase(uint32_t addr, uint32_t size) override
SPIFFS callback to erase flash, in context.
int32_t flash_write(uint32_t addr, uint32_t size, uint8_t *src) override
SPIFFS callback to write flash, in context.
Stm32Flash< FlashVariableSectors > flash_
Implementation of the flash read/write routines.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138