测试写flash, 基于EVT里的程序改的, 在ch32v307vct6的开发板上测试正常.
改到我们自己的ch32v307wcu6的板子上运行会报timeout, 但读的话能看到值正常写入了
请问可能是什么原因呢?
测试写flash, 基于EVT里的程序改的, 在ch32v307vct6的开发板上测试正常.
改到我们自己的ch32v307wcu6的板子上运行会报timeout, 但读的话能看到值正常写入了
请问可能是什么原因呢?
看一下是不是没有解锁flash ,标准编程调用FLASH_Unlock,快速编程需要调用?FLASH_Unlock_Fast。再看一下是不是操作flash的主频超过了120M没有降频。后续有问题的话可以邮箱发程序测试一下zdg@wch.cn
程序是基于例程改的,如下:
void write_flash_data(uint16_t *data, int size)
{
? ? __disable_irq();
? ? FLASH_Unlock();
? ? FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_WRPRTERR);
? ? FLASHStatus = FLASH_ErasePage(FLASH_ADDR);
? ? if(FLASHStatus != FLASH_COMPLETE)
? ? {
? ? ? ? printf("FLASH Erase Fail\r\n");
? ? }
? ? printf("FLASH Erase Suc\r\n");
? ? printf("Programing...\r\n");
? ? for(int i=0; i
? ? ? ? FLASHStatus = FLASH_ProgramHalfWord(FLASH_ADDR + (2*i), data[i]);
? ? ? ? if(FLASHStatus != FLASH_COMPLETE) {
? ? ? ? ? ? printf("flash failed: 0x%08x, %d\r\n", FLASH_ADDR + (2*i), FLASHStatus);
? ? ? ? }
? ? }
? ? FLASH_Lock();
? ? __enable_irq();
}
下面是运行的log,时钟是96M,erase看着是成功的,但program会fail,返回status是5 timeout
实际都program的地址值都是对的,写进去了,不知道为啥返回status不对。
SystemClk:96000000???????????????????????????????????????????????????????????????????????????????????????? ChipID:30730518??????????????????????????????????????????????????????????????????????????????????????????? FLASH?Erase?Suc??????????????????????????????????????????????????????????????????????????????????????????? Programing...????????????????????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070000,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070002,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070004,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070006,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070008,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807000a,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807000c,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807000e,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070010,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070012,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070014,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070016,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x08070018,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807001a,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807001c,?5??????????????????????????????????????????????????????????????????????????????? flash?failed:?0x0807001e,?5
#define PAGE_WRITE_START_ADDR ((uint32_t)0x0800F000) /* Start from 60K */
#define PAGE_WRITE_END_ADDR ((uint32_t)0x08010000) /* End at 63K */
#define FLASH_PAGE_SIZE 4096
#define FLASH_PAGES_TO_BE_PROTECTED FLASH_WRProt_Pages60to63
void Flash_Test(void)
{
printf("FLASH Test\n");
__disable_irq();
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP | FLASH_FLAG_WRPRTERR);
FLASHStatus = FLASH_ErasePage(PAGE_WRITE_START_ADDR); //Erase 4KB
if(FLASHStatus != FLASH_COMPLETE)
{
printf("FLASH Erase Fail\r\n");
return;
}
printf("FLASH Erase Suc\r\n");
Address = PAGE_WRITE_START_ADDR;
printf("Programing...\r\n");
while((Address < PAGE_WRITE_END_ADDR) && (FLASHStatus == FLASH_COMPLETE))
{
FLASHStatus = FLASH_ProgramHalfWord(Address, Data);
Address = Address + 2;
}
Address = PAGE_WRITE_START_ADDR;
printf("Program Cheking...\r\n");
while((Address < PAGE_WRITE_END_ADDR) && (MemoryProgramStatus != FAILED))
{
if((*(__IO uint16_t *)Address) != Data)
{
MemoryProgramStatus = FAILED;
}
Address += 2;
}
if(MemoryProgramStatus == FAILED)
{
printf("Memory Program FAIL!\r\n");
}
else
{
printf("Memory Program PASS!\r\n");
}
FLASH_Lock();
__enable_irq();
}
你好 ,你的代码贴的看不清,我贴了一份我测试过的程序,是没问题的。检查一下你的程序的地址是不是与代码地址有重叠,后续有问题可以将你的程序通过邮箱发我。zdg@wch.cn