X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fcpu%2Fcortex-m3%2Fdrv%2Fflash_stm32.c;h=62e448f3ab35dd9d201ba78756c89b3655247d9f;hb=46a1dfc5b039beb4495945e534c746bcce91edae;hp=68b3cdaff630e58af8906c8ea8b023e8f34e362d;hpb=6b88c2593ab913484e8b8f88fd65a23831acf4fe;p=bertos.git diff --git a/bertos/cpu/cortex-m3/drv/flash_stm32.c b/bertos/cpu/cortex-m3/drv/flash_stm32.c index 68b3cdaf..62e448f3 100644 --- a/bertos/cpu/cortex-m3/drv/flash_stm32.c +++ b/bertos/cpu/cortex-m3/drv/flash_stm32.c @@ -139,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) { - 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; } @@ -165,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) { + ASSERT(offset == 0); + ASSERT(size == blk->blk_size); + if (!stm32_erasePage(blk, (idx * blk->blk_size))) return 0; @@ -173,7 +173,7 @@ static size_t stm32_flash_writeDirect(struct KBlock *blk, block_idx_t idx, const while (size) { - uint16_t data = ((*buf + 1) << 8) | *buf; + uint16_t data = (*(buf + 1) << 8) | *buf; if (!stm32_writeWord(blk, addr, data)) return 0; @@ -195,6 +195,8 @@ static const KBlockVTable flash_stm32_buffered_vt = .load = kblock_swLoad, .store = kblock_swStore, + .close = kblock_swClose, + .error = stm32_flash_error, .clearerr = stm32_flash_clearerror, }; @@ -204,6 +206,8 @@ static const KBlockVTable flash_stm32_unbuffered_vt = .readDirect = stm32_flash_readDirect, .writeDirect = stm32_flash_writeDirect, + .close = kblock_swClose, + .error = stm32_flash_error, .clearerr = stm32_flash_clearerror, }; @@ -227,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; - 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; + + /* 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; + fls->blk.priv.flags |= flags; }