projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
SEC: improve cipher API to allow variable-key ciphers.
[bertos.git]
/
bertos
/
cpu
/
cortex-m3
/
drv
/
flash_stm32.c
diff --git
a/bertos/cpu/cortex-m3/drv/flash_stm32.c
b/bertos/cpu/cortex-m3/drv/flash_stm32.c
index d3e82b28b5f379d0a1058f7eb152e26e1c84af91..62e448f3ab35dd9d201ba78756c89b3655247d9f 100644
(file)
--- a/
bertos/cpu/cortex-m3/drv/flash_stm32.c
+++ b/
bertos/cpu/cortex-m3/drv/flash_stm32.c
@@
-56,13
+56,6
@@
#define EMB_FLASH ((struct stm32_flash*)FLASH_R_BASE)
#define EMB_FLASH ((struct stm32_flash*)FLASH_R_BASE)
-#if CPU_CM3_STM32F103RB
- #define EMB_FLASH_PAGE_SIZE 1024
-#else
- #error Unknown CPU
-#endif
-
-
struct FlashHardware
{
uint8_t status;
struct FlashHardware
{
uint8_t status;
@@
-146,10
+139,7
@@
static void stm32_flash_clearerror(struct KBlock *blk)
static size_t stm32_flash_readDirect(struct KBlock *blk, block_idx_t idx, void *buf, size_t offset, size_t size)
{
static size_t stm32_flash_readDirect(struct KBlock *blk, block_idx_t idx, void *buf, size_t offset, size_t size)
{
- ASSERT(offset == 0);
- ASSERT(size == blk->blk_size);
-
- memcpy(buf, (void *)(idx * blk->blk_size), size);
+ memcpy(buf, (void *)(idx * blk->blk_size + offset), size);
return size;
}
return size;
}
@@
-172,6
+162,9
@@
INLINE bool stm32_writeWord(struct KBlock *blk, uint32_t addr, uint16_t data)
static size_t stm32_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const void *_buf, size_t offset, size_t size)
{
static size_t stm32_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const void *_buf, size_t offset, size_t size)
{
+ ASSERT(offset == 0);
+ ASSERT(size == blk->blk_size);
+
if (!stm32_erasePage(blk, (idx * blk->blk_size)))
return 0;
if (!stm32_erasePage(blk, (idx * blk->blk_size)))
return 0;
@@
-180,7
+173,7
@@
static size_t stm32_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const
while (size)
{
while (size)
{
- uint16_t data = (
(*
buf + 1) << 8) | *buf;
+ uint16_t data = (
*(
buf + 1) << 8) | *buf;
if (!stm32_writeWord(blk, addr, data))
return 0;
if (!stm32_writeWord(blk, addr, data))
return 0;
@@
-202,6
+195,8
@@
static const KBlockVTable flash_stm32_buffered_vt =
.load = kblock_swLoad,
.store = kblock_swStore,
.load = kblock_swLoad,
.store = kblock_swStore,
+ .close = kblock_swClose,
+
.error = stm32_flash_error,
.clearerr = stm32_flash_clearerror,
};
.error = stm32_flash_error,
.clearerr = stm32_flash_clearerror,
};
@@
-211,24
+206,24
@@
static const KBlockVTable flash_stm32_unbuffered_vt =
.readDirect = stm32_flash_readDirect,
.writeDirect = stm32_flash_writeDirect,
.readDirect = stm32_flash_readDirect,
.writeDirect = stm32_flash_writeDirect,
+ .close = kblock_swClose,
+
.error = stm32_flash_error,
.clearerr = stm32_flash_clearerror,
};
static struct FlashHardware flash_stm32_hw;
.error = stm32_flash_error,
.clearerr = stm32_flash_clearerror,
};
static struct FlashHardware flash_stm32_hw;
-static uint8_t flash_buf[
EMB_
FLASH_PAGE_SIZE];
+static uint8_t flash_buf[FLASH_PAGE_SIZE];
static void common_init(Flash *fls)
{
memset(fls, 0, sizeof(*fls));
DB(fls->blk.priv.type = KBT_FLASH);
static void common_init(Flash *fls)
{
memset(fls, 0, sizeof(*fls));
DB(fls->blk.priv.type = KBT_FLASH);
- EMB_FLASH->CR = 0;
-
fls->hw = &flash_stm32_hw;
fls->hw = &flash_stm32_hw;
- fls->blk.blk_size =
EMB_
FLASH_PAGE_SIZE;
- fls->blk.blk_cnt = (F_SIZE * 1024) /
EMB_
FLASH_PAGE_SIZE;
+ fls->blk.blk_size = FLASH_PAGE_SIZE;
+ fls->blk.blk_cnt = (F_SIZE * 1024) / FLASH_PAGE_SIZE;
/* Unlock flash memory for the FPEC Access */
EMB_FLASH->KEYR = FLASH_KEY1;
/* Unlock flash memory for the FPEC Access */
EMB_FLASH->KEYR = FLASH_KEY1;
@@
-236,16
+231,21
@@
static void common_init(Flash *fls)
}
}
-void flash_hw_init(Flash *fls)
+void flash_hw_init(Flash *fls
, int flags
)
{
common_init(fls);
fls->blk.priv.vt = &flash_stm32_buffered_vt;
{
common_init(fls);
fls->blk.priv.vt = &flash_stm32_buffered_vt;
- fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE;
+ fls->blk.priv.flags |= KB_BUFFERED | KB_PARTIAL_WRITE
| flags
;
fls->blk.priv.buf = flash_buf;
fls->blk.priv.buf = flash_buf;
+
+ /* Load the first block in the cache */
+ void *flash_start = 0x0;
+ memcpy(fls->blk.priv.buf, flash_start, fls->blk.blk_size);
}
}
-void flash_hw_initUnbuffered(Flash *fls)
+void flash_hw_initUnbuffered(Flash *fls
, int flags
)
{
common_init(fls);
fls->blk.priv.vt = &flash_stm32_unbuffered_vt;
{
common_init(fls);
fls->blk.priv.vt = &flash_stm32_unbuffered_vt;
+ fls->blk.priv.flags |= flags;
}
}