CH32V103 Flash我怎么弄不對呢
#define?FLASH_POWERDATA_ADDR???????????((uint32_t)0x0800E000)

void?Save_ConfigData(void)
{
????FLASH_Unlock_Fast();
????FLASH_ErasePage_Fast(FLASH_POWERDATA_ADDR);
????FLASH_BufReset();
????FLASH_BufLoad(FLASH_POWERDATA_ADDR,?(u32)ConfigInfo.iMaxVoltage,?(u32)ConfigInfo.iMaxCurrent,?(u32)ConfigInfo.iTime1,?(u32)ConfigInfo.iTime2);
????FLASH_ProgramPage_Fast(FLASH_POWERDATA_ADDR);
????FLASH_Lock_Fast();
}

void?Read_ConfigData(void)
{
????ConfigInfo.iMaxVoltage?=?*(u32?*)(FLASH_POWERDATA_ADDR);
????ConfigInfo.iMaxCurrent?=?*(u32?*)(FLASH_POWERDATA_ADDR+0x04);
????ConfigInfo.iTime1?=?*(u32?*)(FLASH_POWERDATA_ADDR+0x08);
????ConfigInfo.iTime2?=?*(u32?*)(FLASH_POWERDATA_ADDR+0x0C);

	if(0xFFFF?==?ConfigInfo.iMaxVoltage)
	{
	????InitPowerInfo();
	????Save_ConfigData();
	}
}


一共就這幾行代碼,每次Read出來都是0XFFFF。 有沒有跟ST-LINK?Utility類似的工具啊,可以外部讀取Flash內(nèi)容,從而先確定是沒寫進(jìn)去,還是讀出問題了啊,函數(shù)接口又都是void類型,完全不知道問題出在哪里。

您好,若你需要讀取FLASH的存儲內(nèi)容,只需要讀對應(yīng)的地址就可以了。附件為CH32V103 FLASH讀操作例程,你可以參考下。注意下,若你在讀之前有解除讀保護(hù)操作,且解除之后并沒有寫入,那讀出來就會是0xFFFF。

icon_rar.gifCH32V103 FLASH讀操作.zip



我換到標(biāo)準(zhǔn)讀寫了,目前寫入的時候,在FLASH_Lock的時候卡住,出不來。


保存前,禁用中斷,LOCK后再恢復(fù),目前看效果一樣。


您好,若你是FLASH寫入出現(xiàn)問題,當(dāng)采用快速編程方式時,需要先執(zhí)行快速編程模式解鎖操作,然后再進(jìn)行操作,如下圖。具體可參考我們手冊閃存操作流程和EVT FLASH例程。

CH32V103應(yīng)用手冊:http://www.findthetime.net/downloads/CH32xRM_PDF.html

CH32V103EVT例程:http://www.findthetime.net/downloads/CH32V103EVT_ZIP.html

image.png

image.png


我用demo代碼,沒問題。


然后用自己的代碼,就不行了。 用到了ADC-DMA中斷, 外部中斷,F(xiàn)reertos.

EXTI0_IRQHandler中調(diào)用的Flash寫入,為了排除是不是中斷函數(shù)里不能讀寫Flash。 我把代碼加在Main中了


main讀了Flash,不過出來全部是0xFF。? 隨后執(zhí)行寫入操作(標(biāo)準(zhǔn)寫,不是Fast)。 這時候暫停代碼,發(fā)現(xiàn)停止在

FLASH_WaitForLastOperation函數(shù)入口。

void?Read_ConfigData(void)
{
????ConfigInfo.iMaxVoltage?=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR);
????ConfigInfo.iMaxCurrent?=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR+0x04);
????ConfigInfo.iTime1?=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR+0x08);
????ConfigInfo.iTime2?=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR+0x0C);
????ConfigInfo.iAutoTime?=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR+0x10);
????ConfigInfo.iInterval=?*(__IO?uint16_t?*)(FLASH_POWERDATA_ADDR+0x014);

	if(0xFFFF?==?ConfigInfo.iMaxVoltage)
	{
	????InitPowerInfo();
	????Save_ConfigData();
	}
}


void?Save_ConfigData(void)
{
????/*FLASH_Unlock_Fast();
????FLASH_ErasePage_Fast(FLASH_POWERDATA_ADDR);
????FLASH_BufReset();
????FLASH_BufLoad(FLASH_POWERDATA_ADDR,?(u32)ConfigInfo.iMaxVoltage,?(u32)ConfigInfo.iMaxCurrent,?(u32)ConfigInfo.iTime1,?(u32)ConfigInfo.iTime2);
????FLASH_ProgramPage_Fast(FLASH_POWERDATA_ADDR);
????FLASH_Lock_Fast();*/
????volatile?FLASH_Status?FLASHStatus?=?FLASH_COMPLETE;
????volatile?TestStatus?MemoryEraseStatus?=?PASSED;

????uint32_t??????????????EraseCounter?=?0x0,?Address?=?0x0;
????uint32_t??????????????WRPR_Value?=?0xFFFFFFFF;
????uint32_t??????????????NbrOfPage;

????__disable_irq();
????FLASH_Unlock();
????WRPR_Value?=?FLASH_GetWriteProtectionOptionByte();
????NbrOfPage?=?(PAGE_WRITE_END_ADDR?-?FLASH_POWERDATA_ADDR)?/?FLASH_PAGE_SIZE;

????if((WRPR_Value?&?FLASH_PAGES_TO_BE_PROTECTED)?!=?0x00)
????{
????????FLASH_ClearFlag(FLASH_FLAG_BSY?|?FLASH_FLAG_EOP?|?FLASH_FLAG_PGERR?|?FLASH_FLAG_WRPRTERR);

????????for(EraseCounter?=?0;?(EraseCounter?<?NbrOfPage)?&&?(FLASHStatus?==?FLASH_COMPLETE);?EraseCounter++)
????????{
????????????FLASHStatus?=?FLASH_ErasePage(FLASH_POWERDATA_ADDR?+?(FLASH_PAGE_SIZE?*?EraseCounter));
????????????if(FLASHStatus?!=?FLASH_COMPLETE)
????????????{
????????????????printf("FLASH?Erase?ERR?at?Page%d\r\n",?EraseCounter?+?60);
????????????}
????????????printf("FLASH?Erase?Page%d...\r\n",?EraseCounter?+?60);
????????}

????????Address?=?FLASH_POWERDATA_ADDR;
????????while((Address?<?PAGE_WRITE_END_ADDR)?&&?(MemoryEraseStatus?!=?FAILED))
????????{
????????????if((*(__IO?uint16_t?*)Address)?!=?0xFFFF)
????????????{
????????????????MemoryEraseStatus?=?FAILED;
????????????}
????????????Address?+=?2;
????????}
????????if(MemoryEraseStatus?==?FAILED)
????????{
????????????printf("Erase?Flash?FAIL!\r\n");
????????????printf("\r\n");
????????}
????????else
????????{
????????????printf("Erase?Flash?PASS!\r\n");
????????}

????????Address?=?FLASH_POWERDATA_ADDR;
????????//while((Address?<?PAGE_WRITE_END_ADDR)?&&?(FLASHStatus?==?FLASH_COMPLETE))
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iMaxVoltage);
????????Address?=?Address?+?2;
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iMaxCurrent);
????????Address?=?Address?+?2;
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iTime1);
????????Address?=?Address?+?2;
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iTime2);
????????Address?=?Address?+?2;
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iAutoTime);
????????Address?=?Address?+?2;
????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?ConfigInfo.iInterval);
????????Address?=?Address?+?2;
????????while((Address?<?PAGE_WRITE_END_ADDR)?&&?(FLASHStatus?==?FLASH_COMPLETE))
????????{
????????????FLASHStatus?=?FLASH_ProgramHalfWord(Address,?0xAA);
????????}

????????/*
????????Address?=?PAGE_WRITE_START_ADDR;
????????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();
}



您好,我們FLASH標(biāo)準(zhǔn)庫函數(shù)中有多處調(diào)用到FLASH_WaitForLastOperation這個函數(shù),你可以通過打印調(diào)試的方式看程序具體是停止在哪個函數(shù)里了,若需要,可將例程發(fā)到我的郵箱(lzs@wch.cn),這邊可以幫你看一下


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频