usbd_dfu_mal.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbd_dfu_mal.h"
30 
31 #include "usbd_flash_if.h"
32 
33 #ifdef DFU_MAL_SUPPORT_OTP
34  #include "usbd_otp_if.h"
35 #endif
36 
37 #ifdef DFU_MAL_SUPPORT_MEM
38  #include "usbd_mem_if_template.h"
39 #endif
40 
41 /* Private typedef -----------------------------------------------------------*/
42 /* Private define ------------------------------------------------------------*/
43 /* Private macro -------------------------------------------------------------*/
44 /* Private variables ---------------------------------------------------------*/
45 
46 /* Global Memories callback and string descriptors reference tables.
47  To add a new memory, modify the value of MAX_USED_MEDIA in usbd_dfu_mal.h
48  and add the pointer to the callback structure in this table.
49  Then add the pointer to the memory string descriptor in usbd_dfu_StringDesc table.
50  No other operation is required. */
51 DFU_MAL_Prop_TypeDef* tMALTab[MAX_USED_MEDIA] = {
53 #ifdef DFU_MAL_SUPPORT_OTP
54  , &DFU_Otp_cb
55 #endif
56 #ifdef DFU_MAL_SUPPORT_MEM
57  , &DFU_Mem_cb
58 #endif
59 };
60 
61 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
62  #if defined ( __ICCARM__ )
63  #pragma data_alignment=4
64  #endif
65 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
66 
67 __ALIGN_BEGIN const uint8_t* usbd_dfu_StringDesc[MAX_USED_MEDIA] __ALIGN_END = {
68  FLASH_IF_STRING
69 #ifdef DFU_MAL_SUPPORT_OTP
71 #endif
72 #ifdef DFU_MAL_SUPPORT_MEM
74 #endif
75 };
76 
77 #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
78  #if defined ( __ICCARM__ )
79  #pragma data_alignment=4
80  #endif
81 #endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
82 /* RAM Buffer for Downloaded Data */
83 __ALIGN_BEGIN uint8_t MAL_Buffer[XFERSIZE] __ALIGN_END ;
84 
85 /* Private function prototypes -----------------------------------------------*/
86 static uint8_t MAL_CheckAdd (uint32_t Add);
87 /* Private functions ---------------------------------------------------------*/
88 
95 uint16_t MAL_Init(void)
96 {
97  uint32_t memIdx = 0;
98 
99  /* Init all supported memories */
100  for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++)
101  {
102  /* If the check addres is positive, exit with the memory index */
103  if (tMALTab[memIdx]->pMAL_Init != NULL)
104  {
105  tMALTab[memIdx]->pMAL_Init();
106  }
107  }
108 
109  return MAL_OK;
110 }
111 
118 uint16_t MAL_DeInit(void)
119 {
120  uint32_t memIdx = 0;
121 
122  /* Init all supported memories */
123  for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++)
124  {
125  /* Check if the command is supported */
126  if (tMALTab[memIdx]->pMAL_DeInit != NULL)
127  {
128  tMALTab[memIdx]->pMAL_DeInit();
129  }
130  }
131 
132  return MAL_OK;
133 }
134 
141 uint16_t MAL_Erase(uint32_t Add)
142 {
143  uint32_t memIdx = MAL_CheckAdd(Add);
144 
145  /* Check if the area is protected */
146  if (DFU_MAL_IS_PROTECTED_AREA(Add))
147  {
148  return MAL_FAIL;
149  }
150 
151  if (memIdx < MAX_USED_MEDIA)
152  {
153  /* Check if the command is supported */
154  if (tMALTab[memIdx]->pMAL_Erase != NULL)
155  {
156  return tMALTab[memIdx]->pMAL_Erase(Add);
157  }
158  else
159  {
160  return MAL_FAIL;
161  }
162  }
163  else
164  {
165  return MAL_FAIL;
166  }
167 }
168 
176 uint16_t MAL_Write (uint32_t Add, uint32_t Len)
177 {
178  uint32_t memIdx = MAL_CheckAdd(Add);
179 
180  /* Check if the area is protected */
181  if (DFU_MAL_IS_PROTECTED_AREA(Add))
182  {
183  return MAL_FAIL;
184  }
185 
186  if (memIdx < MAX_USED_MEDIA)
187  {
188  /* Check if the command is supported */
189  if (tMALTab[memIdx]->pMAL_Write != NULL)
190  {
191  return tMALTab[memIdx]->pMAL_Write(Add, Len);
192  }
193  else
194  {
195  return MAL_FAIL;
196  }
197  }
198  else
199  {
200  return MAL_FAIL;
201  }
202 }
203 
211 uint8_t *MAL_Read (uint32_t Add, uint32_t Len)
212 {
213  uint32_t memIdx = MAL_CheckAdd(Add);
214 
215  if (memIdx < MAX_USED_MEDIA)
216  {
217  /* Check if the command is supported */
218  if (tMALTab[memIdx]->pMAL_Read != NULL)
219  {
220  return tMALTab[memIdx]->pMAL_Read(Add, Len);
221  }
222  else
223  {
224  return MAL_Buffer;
225  }
226  }
227  else
228  {
229  return MAL_Buffer;
230  }
231 }
232 
241 uint16_t MAL_GetStatus(uint32_t Add , uint8_t Cmd, uint8_t *buffer)
242 {
243  uint32_t memIdx = MAL_CheckAdd(Add);
244 
245  if (memIdx < MAX_USED_MEDIA)
246  {
247  if (Cmd & 0x01)
248  {
249  SET_POLLING_TIMING(tMALTab[memIdx]->EraseTiming);
250  }
251  else
252  {
253  SET_POLLING_TIMING(tMALTab[memIdx]->WriteTiming);
254  }
255 
256  return MAL_OK;
257  }
258  else
259  {
260  return MAL_FAIL;
261  }
262 }
263 
270 static uint8_t MAL_CheckAdd(uint32_t Add)
271 {
272  uint32_t memIdx = 0;
273 
274  /* Check with all supported memories */
275  for(memIdx = 0; memIdx < MAX_USED_MEDIA; memIdx++)
276  {
277  /* If the check addres is positive, exit with the memory index */
278  if (tMALTab[memIdx]->pMAL_CheckAdd(Add) == MAL_OK)
279  {
280  return memIdx;
281  }
282  }
283  /* If no memory found, return MAX_USED_MEDIA */
284  return (MAX_USED_MEDIA);
285 }
286 
287 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint16_t MAL_DeInit(void)
MAL_DeInit DeInitializes the Media on the STM32.
Definition: usbd_dfu_mal.c:118
#define SET_POLLING_TIMING(x)
Definition: usbd_dfu_mal.h:65
uint8_t * MAL_Read(uint32_t Add, uint32_t Len)
MAL_Read Read sectors of memory.
Definition: usbd_dfu_mal.c:211
DFU_MAL_Prop_TypeDef DFU_Mem_cb
const uint8_t * usbd_dfu_StringDesc[]
Header for usbd_mem_if_template.c file.
uint16_t(* pMAL_DeInit)(void)
Definition: usbd_dfu_mal.h:43
uint8_t *(* pMAL_Read)(uint32_t Add, uint32_t Len)
Definition: usbd_dfu_mal.h:46
#define OTP_IF_STRING
Definition: usbd_otp_if.h:40
static uint8_t buffer[BMP280_DATA_FRAME_SIZE]
Definition: drv_bmp280.c:61
#define MEM_IF_STRING
uint8_t MAL_Buffer[XFERSIZE]
Definition: usbd_dfu_mal.c:83
uint16_t(* pMAL_Erase)(uint32_t Add)
Definition: usbd_dfu_mal.h:44
uint16_t MAL_Init(void)
MAL_Init Initializes the Media on the STM32.
Definition: usbd_dfu_mal.c:95
static uint8_t MAL_CheckAdd(uint32_t Add)
MAL_CheckAdd Determine which memory should be managed.
Definition: usbd_dfu_mal.c:270
__ALIGN_BEGIN const uint8_t *usbd_dfu_StringDesc[MAX_USED_MEDIA] __ALIGN_END
Definition: usbd_dfu_mal.c:67
uint16_t MAL_GetStatus(uint32_t Add, uint8_t Cmd, uint8_t *buffer)
MAL_GetStatus Get the status of a given memory.
Definition: usbd_dfu_mal.c:241
#define __ALIGN_BEGIN
uint16_t(* pMAL_Write)(uint32_t Add, uint32_t Len)
Definition: usbd_dfu_mal.h:45
Header for usbd_otp_if.c file.
uint16_t MAL_Write(uint32_t Add, uint32_t Len)
MAL_Write Write sectors of memory.
Definition: usbd_dfu_mal.c:176
Header for usbd_dfu_mal.c file.
DFU_MAL_Prop_TypeDef DFU_Flash_cb
Definition: usbd_flash_if.c:46
DFU_MAL_Prop_TypeDef DFU_Otp_cb
Definition: usbd_otp_if.c:44
#define MAL_OK
Definition: usbd_dfu_mal.h:55
Header for usbd_flash_if.c file.
uint16_t MAL_Erase(uint32_t Add)
MAL_Erase Erase a sector of memory.
Definition: usbd_dfu_mal.c:141
#define NULL
Definition: usbd_def.h:50
uint16_t(* pMAL_Init)(void)
Definition: usbd_dfu_mal.h:42
DFU_MAL_Prop_TypeDef * tMALTab[MAX_USED_MEDIA]
Definition: usbd_dfu_mal.c:51
#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