123456789101112131415161718192021222324252627282930313233343536 |
- #include "gd32f30x.h"
- #include "gd32_flash.h"
- /*-------------------------------------------------*/
- /*函数名:擦除FLASH */
- /*参 数:start:擦除起始扇区 num:擦几个扇区 */
- /*返回值:无 */
- /*-------------------------------------------------*/
- void GD32_EraseFlash(uint16_t start, uint16_t num)
- {
- uint16_t i; //用于for循环
- fmc_unlock();
- for(i=0;i<num;i++){
- fmc_page_erase((0x08000000 + start * 1024) + (1024 * i));
- }
- fmc_lock();
- }
- /*---------------------------------------------------------------------*/
- /*函数名:写入FLASH */
- /*参 数:saddr:写入地址 wdata:写入数据指针 wnum:写入多少个字节 */
- /*返回值:无 */
- /*---------------------------------------------------------------------*/
- 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();
- }
|