void SectorErase(void) { *(FlashStart + 0x5555) = 0xAAAA; *(FlashStart + 0x2AAA) = 0x5555; *(FlashStart + 0x5555) = 0x8080; *(FlashStart + 0x5555) = 0xAAAA; *(FlashStart + 0x2AAA) = 0x5555; (FlashStart + SectorSize4) = 0x3030; DINT; DELAY_US(40000); EINT; }改写成擦除0x200000到0x200005的代码
时间: 2023-08-15 22:03:57 浏览: 167
DSP 28335 NOR_FLASH擦写实验程序 外部flash 39VF400A
5星 · 资源好评率100%
这段代码可以改写成擦除特定的Flash地址范围的代码,具体实现如下:
```
void flash_erase_range(uint32_t start_address, uint32_t end_address) {
uint32_t flash_address = start_address;
while (flash_address <= end_address) {
volatile uint16_t *flash = (volatile uint16_t *)flash_address;
flash[0x5555] = 0xAAAA;
flash[0x2AAA] = 0x5555;
flash[0x5555] = 0x8080;
flash[0x5555] = 0xAAAA;
flash[0x2AAA] = 0x5555;
flash[0x0000] = 0x3030;
__disable_irq();
delay_us(40000);
__enable_irq();
flash_address += SectorSize;
}
}
// 擦除0x200000到0x200005
void erase_flash_range() {
uint32_t start_address = 0x200000;
uint32_t end_address = 0x200005;
flash_erase_range(start_address, end_address);
}
```
其中,`flash_erase_range`函数用于擦除特定的Flash地址范围,需要传入起始地址和结束地址,然后循环擦除每个扇区。`erase_flash_range`函数用于擦除0x200000到0x200005这个特定的Flash地址范围,直接调用`flash_erase_range`函数即可。
阅读全文