123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "gd32f10x.h"
- #include "fmc.h"
- void GD32_EraseFlash(uint16_t start, uint16_t num)
- {
- uint16_t i;
- uint16_t j = 0;
- fmc_unlock();
- if ((start < 256) && ((start + num) < 256))
- {
- for(i = 0; i < num; i++)
- {
- fmc_page_erase((0x08000000 + start * 2048) + (2048 * i));
- }
- }
- else if ((start < 256) && ((start + num) > 256))
- {
- for(i = 0; i < num; i++)
- {
- if((start + i) < 256)
- {
- fmc_page_erase((0x08000000 + start * 2 * 1024) + (2 * 1024 * i));
- }
- else
- {
- fmc_page_erase(0x08080000 + (4 * 1024 * j));
- j++;
- }
- }
- }
- else if (start > 256)
- {
- for(i = 0; i < num; i++)
- {
- fmc_page_erase((0x08080000 + (start - 256) * 4 * 1024) + (4 * 1024 * i));
- }
- }
-
- fmc_lock();
- }
- void GD32_WriteFlash(uint32_t saddr, uint32_t *wdata, uint32_t wnum)
- {
- fmc_unlock();
- while(wnum){
- fmc_word_program(saddr,*wdata);
- wnum-=4;
- saddr+=4;
- wdata++;
- }
- fmc_lock();
- }
|