Stores data on the flash memory of stm32f4xx

Dependents:   DISCO-F429ZI_LCDTS_demo_richard

Fork of storage_on_flash by henning l

Committer:
pierrebizouard
Date:
Fri Mar 16 15:50:04 2018 +0000
Revision:
1:801ddc4634a5
Parent:
0:4cb438b58dc2
added support for 429ZI up to bank 11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hendreh 0:4cb438b58dc2 1 /**
hendreh 0:4cb438b58dc2 2 * @file SOF_dev.c
hendreh 0:4cb438b58dc2 3 *
hendreh 0:4cb438b58dc2 4 * @author hillkim7@gmail.com
hendreh 0:4cb438b58dc2 5 * @brief Storage On Flash device interface
hendreh 0:4cb438b58dc2 6 *
hendreh 0:4cb438b58dc2 7 */
hendreh 0:4cb438b58dc2 8
hendreh 0:4cb438b58dc2 9 #pragma once
hendreh 0:4cb438b58dc2 10
hendreh 0:4cb438b58dc2 11 #include <stdint.h>
hendreh 0:4cb438b58dc2 12 #include <stddef.h>
hendreh 0:4cb438b58dc2 13
hendreh 0:4cb438b58dc2 14 /** The default value of erased flash memory */
hendreh 0:4cb438b58dc2 15 #define SOF_ERASED_BYTE_VALUE 0xFF
hendreh 0:4cb438b58dc2 16
hendreh 0:4cb438b58dc2 17 #define SOF_INVALID_HANDLE 0xFFFFFFFF
hendreh 0:4cb438b58dc2 18
hendreh 0:4cb438b58dc2 19 /** Error code definition */
hendreh 0:4cb438b58dc2 20 typedef enum {
hendreh 0:4cb438b58dc2 21 kSOF_ErrNone = 0,
hendreh 0:4cb438b58dc2 22 kSOF_ErrParam,
hendreh 0:4cb438b58dc2 23 kSOF_ErrNoInfo,
hendreh 0:4cb438b58dc2 24 kSOF_ErrBusyBlock,
hendreh 0:4cb438b58dc2 25 kSOF_ErrBadBlock,
hendreh 0:4cb438b58dc2 26 kSOF_ErrDataCurrupted,
hendreh 0:4cb438b58dc2 27 kSOF_ErrFatal,
hendreh 0:4cb438b58dc2 28 } SOF_Error_t;;
hendreh 0:4cb438b58dc2 29
hendreh 0:4cb438b58dc2 30 /** Flash sector specification */
hendreh 0:4cb438b58dc2 31 typedef struct {
hendreh 0:4cb438b58dc2 32 uint32_t sec_no;
hendreh 0:4cb438b58dc2 33 uint32_t sec_addr;
hendreh 0:4cb438b58dc2 34 uint32_t sec_size;
hendreh 0:4cb438b58dc2 35 } SOF_SectorSpec_t;
hendreh 0:4cb438b58dc2 36
hendreh 0:4cb438b58dc2 37 /** statics of SOF block */
hendreh 0:4cb438b58dc2 38 typedef struct {
hendreh 0:4cb438b58dc2 39 uint8_t *data_addr;
hendreh 0:4cb438b58dc2 40 uint32_t data_size;
hendreh 0:4cb438b58dc2 41 uint32_t free_size;
hendreh 0:4cb438b58dc2 42 } SOF_Statics_t;
hendreh 0:4cb438b58dc2 43
hendreh 0:4cb438b58dc2 44 typedef uint32_t SOF_DevHandle_t;
hendreh 0:4cb438b58dc2 45
hendreh 0:4cb438b58dc2 46 class SOF_BlockHandle;
hendreh 0:4cb438b58dc2 47 typedef SOF_BlockHandle* SOF_BlockHandle_t;
hendreh 0:4cb438b58dc2 48
hendreh 0:4cb438b58dc2 49 /*-----------------------------------------------------------------------------------------------------*/
hendreh 0:4cb438b58dc2 50 /* Flash device interface */
hendreh 0:4cb438b58dc2 51 /*-----------------------------------------------------------------------------------------------------*/
hendreh 0:4cb438b58dc2 52 int SOF_dev_is_valid_sector(uint8_t sector_index);
hendreh 0:4cb438b58dc2 53 const SOF_SectorSpec_t *SOF_dev_info(SOF_DevHandle_t hdev);
hendreh 0:4cb438b58dc2 54 const SOF_SectorSpec_t *SOF_dev_info_by_index(uint8_t sector_index);
hendreh 0:4cb438b58dc2 55 SOF_DevHandle_t SOF_dev_open(uint8_t sector_index);
hendreh 0:4cb438b58dc2 56 void SOF_dev_close(SOF_DevHandle_t hdev);
hendreh 0:4cb438b58dc2 57 uint8_t *SOF_dev_get_hw_addr(SOF_DevHandle_t hdev);
hendreh 0:4cb438b58dc2 58 void SOF_dev_erase(SOF_DevHandle_t handle);
hendreh 0:4cb438b58dc2 59 int SOF_dev_write_word(SOF_DevHandle_t handle, uint32_t offset_addr, uint32_t data);
hendreh 0:4cb438b58dc2 60 uint32_t SOF_dev_read_word(SOF_DevHandle_t handle, uint32_t offset_addr);
hendreh 0:4cb438b58dc2 61 int SOF_dev_write_byte(SOF_DevHandle_t handle, uint32_t offset_addr, uint8_t data);
hendreh 0:4cb438b58dc2 62 uint8_t SOF_dev_read_byte(SOF_DevHandle_t handle, uint32_t offset_addr);
hendreh 0:4cb438b58dc2 63
hendreh 0:4cb438b58dc2 64 /*-----------------------------------------------------------------------------------------------------*/
hendreh 0:4cb438b58dc2 65 /* Flash block device interface */
hendreh 0:4cb438b58dc2 66 /*-----------------------------------------------------------------------------------------------------*/
hendreh 0:4cb438b58dc2 67 bool SOF_block_format(uint8_t sector_index);
hendreh 0:4cb438b58dc2 68 SOF_BlockHandle_t SOF_block_open_storage(uint8_t sector_index, SOF_Error_t *err);
hendreh 0:4cb438b58dc2 69 SOF_BlockHandle_t SOF_block_create_storage(uint8_t sector_index, SOF_Error_t *err);
hendreh 0:4cb438b58dc2 70 bool SOF_block_close(SOF_BlockHandle_t handle);
hendreh 0:4cb438b58dc2 71 uint8_t *SOF_block_base_addr(SOF_BlockHandle_t handle);
hendreh 0:4cb438b58dc2 72 bool SOF_block_putc(SOF_BlockHandle_t handle, uint8_t c);
hendreh 0:4cb438b58dc2 73 size_t SOF_block_write(SOF_BlockHandle_t handle, const uint8_t *p, size_t p_size);
hendreh 0:4cb438b58dc2 74 bool SOF_block_getc(SOF_BlockHandle_t handle, uint8_t *c);
hendreh 0:4cb438b58dc2 75 size_t SOF_block_read(SOF_BlockHandle_t handle, uint8_t *p, size_t p_size);
hendreh 0:4cb438b58dc2 76 size_t SOF_block_get_free_size(SOF_BlockHandle_t handle);
hendreh 0:4cb438b58dc2 77 uint32_t SOF_block_storage_size(SOF_BlockHandle_t handle);
hendreh 0:4cb438b58dc2 78 SOF_Error_t SOF_block_get_statics(uint8_t sector_index, SOF_Statics_t *stat);
hendreh 0:4cb438b58dc2 79 const SOF_SectorSpec_t *SOF_block_get_info(uint8_t sector_index);
hendreh 0:4cb438b58dc2 80
hendreh 0:4cb438b58dc2 81
hendreh 0:4cb438b58dc2 82