Stima V4 Slave RAIN  4.2
flash.h
Go to the documentation of this file.
1 
30 #ifndef _FLASH_H
31 #define _FLASH_H
32 
33 /* Includes ------------------------------------------------------------------*/
34 #include <STM32FreeRTOS.h>
35 #include "ticks.hpp"
36 #include "thread.hpp"
37 #include "stm32l4xx_hal.h"
38 #include "FreeRTOS.h"
39 #include "AT25SF161.h"
40 
41 using namespace cpp_freertos;
42 
43 #define FLASH_MEMORYMAP_BASE 0x90000000
44 
45 // Security Check W->R Data
46 #define CHECK_FLASH_WRITE
47 
48 #define FLASH_FW_POSITION (0ul)
49 #define FLASH_FW_BACKUP (262144ul) // 000 - 256 KBytes For Program Flash
50 #define FLASH_FILE_POSITION (524288ul) // 256 - 512 KBytes For Program Flash (Backup)
51 #define FLASH_FREE_ACCESS (1048756ul) // 512 - 1024 KBytes For Extra File (... -> Free)
52 #define FLASH_BUFFER_SIZE (256)
53 #define FLASH_INFO_SIZE_LEN (256)
54 #define FLASH_FILE_SIZE_LEN (128)
55 #define FLASH_SIZE_ADDR(X) (X + FLASH_FILE_SIZE_LEN + 1)
56 #define FLASH_INFO_SIZE_U64 (8)
57 
58 class Flash {
59 
60  public:
61 
62  /* QSPI Error codes */
63  typedef enum
64  {
65  QSPI_KO_INIT = -1,
66  QSPI_OK = HAL_OK,
67  QSPI_ERROR = HAL_ERROR,
68  QSPI_BUSY = HAL_BUSY,
69  QSPI_TIMEOUT = HAL_TIMEOUT,
73  QSPI_RESET
74  } QSPI_StatusTypeDef;
75 
76  /* QSPI IT EventFlag */
77  typedef union {
78  struct {
79  uint8_t flag_TE : 1;
80  uint8_t flag_TC : 1;
81  uint8_t flag_SM : 1;
82  uint8_t match_TE : 1;
83  uint8_t match_TC : 1;
84  uint8_t match_SM : 1;
85  } flagBit;
86  uint8_t flag;
88 
89  /* QSPI Info */
90  typedef struct
91  {
92  uint32_t FlashSize;
93  uint32_t EraseBlockSize;
94  uint32_t EraseBlockNumber;
95  uint32_t ProgPageSize;
96  uint32_t ProgPagesNumber;
97  uint32_t StatusRegister;
99  } QSPI_Info;
100 
101  Flash();
102  Flash(QSPI_HandleTypeDef *hqspi);
103  QSPI_StatusTypeDef BSP_QSPI_Init(void);
104  QSPI_StatusTypeDef BSP_QSPI_DeInit(void);
105  QSPI_StatusTypeDef BSP_QSPI_Read(uint8_t *pData, uint32_t ReadAddr, uint32_t Size);
106  QSPI_StatusTypeDef BSP_QSPI_Write(uint8_t *pData, uint32_t WriteAddr, uint32_t Size);
107  QSPI_StatusTypeDef BSP_QSPI_Erase_Block(uint32_t BlockAddress);
108  QSPI_StatusTypeDef BSP_QSPI_Erase_Sector(uint32_t Sector);
109  QSPI_StatusTypeDef BSP_QSPI_Erase_Chip(void);
110  QSPI_StatusTypeDef BSP_QSPI_ReadStatus(uint32_t *Reg);
111  QSPI_StatusTypeDef BSP_QSPI_WriteStatus(uint32_t Reg);
112  QSPI_StatusTypeDef BSP_QSPI_GetStatus(void);
113  QSPI_StatusTypeDef BSP_QSPI_GetInfo(QSPI_Info *pInfo);
114  QSPI_StatusTypeDef BSP_QSPI_EnableMemoryMappedMode(void);
115  QSPI_StatusTypeDef BSP_QSPI_DisableMemoryMappedMode(void);
116  uint8_t BSP_QSPI_SuspendErase(void);
117  uint8_t BSP_QSPI_ResumeErase(void);
118 
119 protected:
120 private:
121 
122  QSPI_StatusTypeDef BSP_QSPI_Receive(uint8_t *pData, uint32_t Timeout);
123  QSPI_StatusTypeDef BSP_QSPI_Transmit(uint8_t *pData, uint32_t Timeout);
124  QSPI_StatusTypeDef BSP_QSPI_AutoPolling(QSPI_CommandTypeDef *cmd, QSPI_AutoPollingTypeDef *cfg, uint32_t Timeout);
125  QSPI_StatusTypeDef BSP_QSPI_WaitingForEvent(uint32_t Timeout);
126  QSPI_StatusTypeDef QSPI_SetDeepPowerDown(void);
127  QSPI_StatusTypeDef QSPI_ExitDeepPowerDown(void);
128  QSPI_StatusTypeDef QSPI_ResetMemory(void);
129  QSPI_StatusTypeDef QSPI_DummyCyclesCfg(void);
130  QSPI_StatusTypeDef QSPI_WriteEnableVolat(void);
131  QSPI_StatusTypeDef QSPI_WriteEnable(void);
132  QSPI_StatusTypeDef QSPI_WriteDisable(void);
133  QSPI_StatusTypeDef QSPI_DisableContinuousMode(void);
134  QSPI_StatusTypeDef QSPI_AutoPollingMemReady(uint32_t Timeout);
135 
136  QSPI_HandleTypeDef *_hqspi;
137  inline static QSPI_Info _FlashInfo;
138  inline static QSPI_IT_EventFlag *_evtFlag;
139 };
140 
141 #endif /* __ETH452_QSPI_H */
142 
This file contains all the description of the AT25SF161 QSPI memory.
Definition: flash.h:58
QSPI_StatusTypeDef
Definition: flash.h:64
@ QSPI_READY
Definition: flash.h:72
@ QSPI_NOT_SUPPORTED
Definition: flash.h:70
@ QSPI_SUSPENDED
Definition: flash.h:71
static QSPI_IT_EventFlag * _evtFlag
Definition: flash.h:138
static QSPI_Info _FlashInfo
Definition: flash.h:137
QSPI_HandleTypeDef * _hqspi
Definition: flash.h:136
__IO QSPI_StatusTypeDef State
Definition: flash.h:98
uint32_t ProgPageSize
Definition: flash.h:95
uint32_t FlashSize
Definition: flash.h:92
uint32_t EraseBlockNumber
Definition: flash.h:94
uint32_t ProgPagesNumber
Definition: flash.h:96
uint32_t StatusRegister
Definition: flash.h:97
uint32_t EraseBlockSize
Definition: flash.h:93