@@ -145,7 +145,6 @@ int32_t flash_program_page(flash_t *obj, uint32_t address, const uint8_t *data,
145
145
146
146
uint32_t flash_get_sector_size (const flash_t * obj , uint32_t address )
147
147
{
148
-
149
148
if ((address >= (FLASH_BASE + FLASH_SIZE )) || (address < FLASH_BASE )) {
150
149
return MBED_FLASH_INVALID_SIZE ;
151
150
}
@@ -165,7 +164,7 @@ uint32_t flash_get_start_address(const flash_t *obj)
165
164
}
166
165
uint32_t flash_get_size (const flash_t * obj )
167
166
{
168
- return FLASH_SIZE ;
167
+ return FLASH_SIZE ;
169
168
}
170
169
171
170
/**
@@ -175,28 +174,30 @@ uint32_t flash_get_size(const flash_t *obj)
175
174
*/
176
175
static uint32_t GetSector (uint32_t address )
177
176
{
178
- uint32_t sector = 0 ;
177
+ uint32_t sector = 0 ;
179
178
uint32_t tmp = address - ADDR_FLASH_SECTOR_0 ;
180
179
/* This function supports 1Mb and 2Mb flash sizes */
181
180
#if defined(ADDR_FLASH_SECTOR_16 )
182
181
if (address & 0x100000 ) { // handle 2nd bank
182
+ /* Sector will be at least 12 */
183
183
sector = FLASH_SECTOR_12 ;
184
- tmp = address - ADDR_FLASH_SECTOR_12 ;
184
+ tmp -= 0x100000 ;
185
+ address -= 0x100000 ;
185
186
}
186
187
#endif
187
188
if (address < ADDR_FLASH_SECTOR_4 ) { // 16k sectorsize
188
189
sector += tmp >>14 ;
189
190
}
190
191
#if defined(ADDR_FLASH_SECTOR_5 )
191
192
else if (address < ADDR_FLASH_SECTOR_5 ) { //64k sector size
192
- sector += FLASH_SECTOR_4 ;
193
+ sector += FLASH_SECTOR_4 ;
193
194
} else {
194
195
sector += 4 + (tmp >>17 );
195
196
}
196
197
#else
197
198
// In case ADDR_FLASH_SECTOR_5 is not defined, sector 4 is the last one.
198
199
else { //64k sector size
199
- sector += FLASH_SECTOR_4 ;
200
+ sector += FLASH_SECTOR_4 ;
200
201
}
201
202
#endif
202
203
return sector ;
@@ -225,7 +226,7 @@ if((Sector == FLASH_SECTOR_0) || (Sector == FLASH_SECTOR_1) || (Sector == FLASH_
225
226
sectorsize = 64 * 1024 ;
226
227
} else {
227
228
sectorsize = 128 * 1024 ;
228
- }
229
+ }
229
230
return sectorsize ;
230
231
}
231
232
0 commit comments