GD32F1x0: USB/GD32_USB_Device_Library/Class/dfu/src/usbd_flash_if.c Source File

GD32F1x0

usbd_flash_if.c
1 
11 /* Includes ------------------------------------------------------------------*/
12 #include "usbd_flash_if.h"
13 
33 static uint8_t Flash_If_Init (void);
34 static uint8_t Flash_If_DeInit (void);
35 static uint8_t Flash_If_Erase (uint32_t Addr);
36 static uint8_t Flash_If_Write (uint32_t Addr, uint32_t Len);
37 static uint8_t* Flash_If_Read (uint32_t Addr, uint32_t Len);
38 static uint8_t Flash_If_CheckAddr (uint32_t Addr);
39 
47 DFU_MAL_Property_TypeDef DFU_Flash_cb =
48 {
49  FLASH_IF_STRING,
50  Flash_If_Init,
51  Flash_If_DeInit,
52  Flash_If_Erase,
53  Flash_If_Write,
54  Flash_If_Read,
55  Flash_If_CheckAddr,
56  60, /* Flash erase timeout in ms */
57  80 /* Flash programming timeout in ms (80us * RAM Buffer size (1024 Bytes) */
58 };
59 
69 static uint8_t Flash_If_Init (void)
70 {
71  /* Unlock the internal flash */
72  FMC_Unlock();
73 
74  return MAL_OK;
75 }
76 
82 static uint8_t Flash_If_DeInit (void)
83 {
84  /* Lock the internal flash */
85  FMC_Lock();
86 
87  return MAL_OK;
88 }
89 
95 static uint8_t Flash_If_Erase (uint32_t Addr)
96 {
97  /* Call the standard flash erase-page function */
98  FMC_ErasePage(Addr);
99 
100  return MAL_OK;
101 }
102 
109 static uint8_t Flash_If_Write (uint32_t Addr, uint32_t Len)
110 {
111  uint32_t idx = 0;
112 
113  if (Len & 0x03) /* Not an aligned data */
114  {
115  for (idx = Len; idx < ((Len & 0xFFFC) + 4); idx++)
116  {
117  MAL_Buffer[idx] = 0xFF;
118  }
119  }
120 
121  /* Data received are word multiple */
122  for (idx = 0; idx < Len; idx += 4)
123  {
124  FMC_ProgramWord(Addr, *(uint32_t *)(MAL_Buffer + idx));
125  Addr += 4;
126  }
127 
128  return MAL_OK;
129 }
130 
137 static uint8_t* Flash_If_Read (uint32_t Addr, uint32_t Len)
138 {
139  return (uint8_t *)(Addr);
140 }
141 
147 static uint8_t Flash_If_CheckAddr (uint32_t Addr)
148 {
149  if ((Addr >= FLASH_START_ADDR) && (Addr < FLASH_END_ADDR))
150  {
151  return MAL_OK;
152  }
153  else
154  {
155  return MAL_FAIL;
156  }
157 }
158 
179 /************************ (C) COPYRIGHT 2014 GIGADEVICE *****END OF FILE****/
Generated by   doxygen 1.8.10