18
18
19
19
#if DEVICE_FLASH
20
20
#include "flash_api.h"
21
- #include "flash_data.h"
22
21
#include "platform/mbed_critical.h"
23
22
24
23
static uint32_t GetSector (uint32_t Address );
25
- static uint32_t GetSectorSize (uint32_t Sector );
26
24
static uint32_t GetSectorBase (uint32_t SectorId , uint32_t BanksId );
27
25
28
26
int32_t flash_init (flash_t * obj )
@@ -79,7 +77,7 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
79
77
EraseInitStruct .Sector = GetSector (address );
80
78
EraseInitStruct .NbSectors = 1 ;
81
79
82
- if (address < ADDR_FLASH_SECTOR_0_BANK2 ) {
80
+ if (address < FLASH_BANK2_BASE ) {
83
81
EraseInitStruct .Banks = FLASH_BANK_1 ;
84
82
} else {
85
83
EraseInitStruct .Banks = FLASH_BANK_2 ;
@@ -91,11 +89,11 @@ int32_t flash_erase_sector(flash_t *obj, uint32_t address)
91
89
92
90
#if defined(DUAL_CORE )
93
91
#if defined(CORE_CM7 )
94
- SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (EraseInitStruct .Sector , EraseInitStruct .Banks ), GetSectorSize ( EraseInitStruct . Sector ) );
92
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (EraseInitStruct .Sector , EraseInitStruct .Banks ), FLASH_SECTOR_SIZE );
95
93
SCB_InvalidateICache ();
96
94
#endif /* CORE_CM7 */
97
95
#else /* DUAL_CORE */
98
- SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (EraseInitStruct .Sector , EraseInitStruct .Banks ), GetSectorSize ( EraseInitStruct . Sector ) );
96
+ SCB_CleanInvalidateDCache_by_Addr ((uint32_t * )GetSectorBase (EraseInitStruct .Sector , EraseInitStruct .Banks ), FLASH_SECTOR_SIZE );
99
97
SCB_InvalidateICache ();
100
98
#endif /* DUAL_CORE */
101
99
@@ -119,11 +117,6 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
119
117
return -1 ;
120
118
}
121
119
122
- if ((size % 32 ) != 0 ) {
123
- /* H7 flash devices can only be programmed 256bits/32 bytes at a time */
124
- return -1 ;
125
- }
126
-
127
120
#if defined(DUAL_CORE )
128
121
while (LL_HSEM_1StepLock (HSEM , CFG_HW_FLASH_SEMID )) {
129
122
}
@@ -138,8 +131,8 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
138
131
StartAddress = address ;
139
132
while ((address < (StartAddress + size )) && (status == 0 )) {
140
133
if (HAL_FLASH_Program (FLASH_TYPEPROGRAM_FLASHWORD , address , (uint32_t )data ) == HAL_OK ) {
141
- address = address + 32 ;
142
- data = data + 32 ;
134
+ address = address + flash_get_page_size ( obj ) ;
135
+ data = data + flash_get_page_size ( obj ) ;
143
136
} else {
144
137
status = -1 ;
145
138
}
@@ -168,12 +161,12 @@ uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
168
161
if ((address >= (FLASH_BASE + FLASH_SIZE )) || (address < FLASH_BASE )) {
169
162
return MBED_FLASH_INVALID_SIZE ;
170
163
}
171
- return (GetSectorSize ( GetSector ( address )) );
164
+ return (FLASH_SECTOR_SIZE );
172
165
}
173
166
174
167
uint32_t flash_get_page_size (const flash_t * obj )
175
168
{
176
- return (32 );
169
+ return (FLASH_NB_32BITWORD_IN_FLASHWORD * 4 );
177
170
}
178
171
179
172
uint32_t flash_get_start_address (const flash_t * obj )
@@ -195,43 +188,15 @@ static uint32_t GetSector(uint32_t Address)
195
188
{
196
189
uint32_t sector = 0 ;
197
190
198
- if (((Address < ADDR_FLASH_SECTOR_1_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_0_BANK1 )) || \
199
- ((Address < ADDR_FLASH_SECTOR_1_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_0_BANK2 ))) {
200
- sector = FLASH_SECTOR_0 ;
201
- } else if (((Address < ADDR_FLASH_SECTOR_2_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_1_BANK1 )) || \
202
- ((Address < ADDR_FLASH_SECTOR_2_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_1_BANK2 ))) {
203
- sector = FLASH_SECTOR_1 ;
204
- } else if (((Address < ADDR_FLASH_SECTOR_3_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_2_BANK1 )) || \
205
- ((Address < ADDR_FLASH_SECTOR_3_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_2_BANK2 ))) {
206
- sector = FLASH_SECTOR_2 ;
207
- } else if (((Address < ADDR_FLASH_SECTOR_4_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_3_BANK1 )) || \
208
- ((Address < ADDR_FLASH_SECTOR_4_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_3_BANK2 ))) {
209
- sector = FLASH_SECTOR_3 ;
210
- } else if (((Address < ADDR_FLASH_SECTOR_5_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_4_BANK1 )) || \
211
- ((Address < ADDR_FLASH_SECTOR_5_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_4_BANK2 ))) {
212
- sector = FLASH_SECTOR_4 ;
213
- } else if (((Address < ADDR_FLASH_SECTOR_6_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_5_BANK1 )) || \
214
- ((Address < ADDR_FLASH_SECTOR_6_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_5_BANK2 ))) {
215
- sector = FLASH_SECTOR_5 ;
216
- } else if (((Address < ADDR_FLASH_SECTOR_7_BANK1 ) && (Address >= ADDR_FLASH_SECTOR_6_BANK1 )) || \
217
- ((Address < ADDR_FLASH_SECTOR_7_BANK2 ) && (Address >= ADDR_FLASH_SECTOR_6_BANK2 ))) {
218
- sector = FLASH_SECTOR_6 ;
191
+ if (Address < (FLASH_BASE + FLASH_BANK_SIZE )) {
192
+ sector = (Address - FLASH_BASE ) / FLASH_SECTOR_SIZE ;
219
193
} else {
220
- sector = FLASH_SECTOR_7 ;
194
+ sector = ( Address - ( FLASH_BASE + FLASH_BANK_SIZE )) / FLASH_SECTOR_SIZE ;
221
195
}
222
196
223
197
return sector ;
224
198
}
225
199
226
- /**
227
- * @brief Gets sector Size
228
- * @param None
229
- * @retval The size of a given sector
230
- */
231
- static uint32_t GetSectorSize (uint32_t Sector )
232
- {
233
- return FLASH_SECTOR_SIZE ;
234
- }
235
200
236
201
/**
237
202
* @brief Gets sector base address
@@ -251,7 +216,7 @@ static uint32_t GetSectorBase(uint32_t SectorId, uint32_t BanksId)
251
216
}
252
217
253
218
for (i = 0 ; i < SectorId ; i ++ ) {
254
- address_sector += GetSectorSize ( i ) ;
219
+ address_sector += FLASH_SECTOR_SIZE ;
255
220
}
256
221
return address_sector ;
257
222
}
0 commit comments