usbd_flash_if.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_flash_if.h"
30 #include "usbd_dfu_mal.h"
31 
32 /* Private typedef -----------------------------------------------------------*/
33 /* Private define ------------------------------------------------------------*/
34 /* Private macro -------------------------------------------------------------*/
35 
36 /* Private function prototypes -----------------------------------------------*/
37 uint16_t FLASH_If_Init(void);
38 uint16_t FLASH_If_Erase (uint32_t Add);
39 uint16_t FLASH_If_Write (uint32_t Add, uint32_t Len);
40 uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len);
41 uint16_t FLASH_If_DeInit(void);
42 uint16_t FLASH_If_CheckAdd(uint32_t Add);
43 
44 
45 /* Private variables ---------------------------------------------------------*/
47  {
48  FLASH_IF_STRING,
55  50, /* Erase Time in ms */
56  50 /* Programming Time in ms */
57  };
58 
59 /* Private functions ---------------------------------------------------------*/
60 
67 uint16_t FLASH_If_Init(void)
68 {
69  /* Unlock the internal flash */
70  FLASH_Unlock();
71 
72  return MAL_OK;
73 }
74 
81 uint16_t FLASH_If_DeInit(void)
82 {
83  /* Lock the internal flash */
84  FLASH_Lock();
85 
86  return MAL_OK;
87 }
88 
89 /*******************************************************************************
90 * Function Name : FLASH_If_Erase
91 * Description : Erase sector
92 * Input : None
93 * Output : None
94 * Return : None
95 *******************************************************************************/
96 uint16_t FLASH_If_Erase(uint32_t Add)
97 {
98 #if defined (STM32F2XX) || defined (STM32F4XX)
99  /* Check which sector has to be erased */
100  if (Add < 0x08004000)
101  {
103  }
104  else if (Add < 0x08008000)
105  {
107  }
108  else if (Add < 0x0800C000)
109  {
111  }
112  else if (Add < 0x08010000)
113  {
115  }
116  else if (Add < 0x08020000)
117  {
119  }
120  else if (Add < 0x08040000)
121  {
123  }
124  else if (Add < 0x08060000)
125  {
127  }
128  else if (Add < 0x08080000)
129  {
131  }
132  else if (Add < 0x080A0000)
133  {
135  }
136  else if (Add < 0x080C0000)
137  {
139  }
140  else if (Add < 0x080E0000)
141  {
143  }
144  else if (Add < 0x08100000)
145  {
147  }
148  else
149  {
150  return MAL_FAIL;
151  }
152 #elif defined(STM32F10X_CL)
153  /* Call the standard Flash erase function */
154  FLASH_ErasePage(Add);
155 #endif /* STM32F2XX */
156 
157  return MAL_OK;
158 }
159 
167 uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
168 {
169  uint32_t idx = 0;
170 
171  if (Len & 0x3) /* Not an aligned data */
172  {
173  for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++)
174  {
175  MAL_Buffer[idx] = 0xFF;
176  }
177  }
178 
179  /* Data received are Word multiple */
180  for (idx = 0; idx < Len; idx = idx + 4)
181  {
182  FLASH_ProgramWord(Add, *(uint32_t *)(MAL_Buffer + idx));
183  Add += 4;
184  }
185  return MAL_OK;
186 }
187 
195 uint8_t *FLASH_If_Read (uint32_t Add, uint32_t Len)
196 {
197 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
198  uint32_t idx = 0;
199  for (idx = 0; idx < Len; idx += 4)
200  {
201  *(uint32_t*)(MAL_Buffer + idx) = *(uint32_t *)(Add + idx);
202  }
203  return (uint8_t*)(MAL_Buffer);
204 #else
205  return (uint8_t *)(Add);
206 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
207 }
208 
216 uint16_t FLASH_If_CheckAdd(uint32_t Add)
217 {
218  if ((Add >= FLASH_START_ADD) && (Add < FLASH_END_ADD))
219  {
220  return MAL_OK;
221  }
222  else
223  {
224  return MAL_FAIL;
225  }
226 }
227 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define FLASH_Sector_2
uint16_t FLASH_If_DeInit(void)
FLASH_If_DeInit Memory deinitialization routine.
Definition: usbd_flash_if.c:81
uint16_t FLASH_If_Erase(uint32_t Add)
Definition: usbd_flash_if.c:96
void FLASH_Unlock(void)
Unlocks the FLASH control register access.
#define FLASH_Sector_7
#define FLASH_Sector_5
#define VoltageRange_3
#define FLASH_Sector_6
uint16_t FLASH_If_Init(void)
FLASH_If_Init Memory initialization routine.
Definition: usbd_flash_if.c:67
uint16_t FLASH_If_Write(uint32_t Add, uint32_t Len)
FLASH_If_Write Memory write routine.
#define FLASH_Sector_0
uint8_t MAL_Buffer[XFERSIZE]
Definition: usbd_dfu_mal.c:83
uint8_t * FLASH_If_Read(uint32_t Add, uint32_t Len)
FLASH_If_Read Memory read routine.
#define FLASH_Sector_1
#define FLASH_Sector_8
uint16_t FLASH_If_CheckAdd(uint32_t Add)
FLASH_If_CheckAdd Check if the address is an allowed address for this memory.
#define FLASH_Sector_4
Header for usbd_dfu_mal.c file.
DFU_MAL_Prop_TypeDef DFU_Flash_cb
Definition: usbd_flash_if.c:46
#define MAL_OK
Definition: usbd_dfu_mal.h:55
Header for usbd_flash_if.c file.
#define FLASH_Sector_11
#define FLASH_START_ADD
Definition: usbd_flash_if.h:37
#define FLASH_Sector_3
FLASH_Status FLASH_ErasePage(uint32_t Page_Address)
Erases a specified FLASH page.
FLASH_Status FLASH_ProgramWord(uint32_t Address, uint32_t Data)
Programs a word at a specified address.
#define FLASH_Sector_10
#define FLASH_Sector_9
void FLASH_Lock(void)
Locks the FLASH control register access.
FLASH_Status FLASH_EraseSector(uint32_t FLASH_Sector, uint8_t VoltageRange)
Erases a specified FLASH Sector.
#define MAL_FAIL
Definition: usbd_dfu_mal.h:56


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:26