目的是將程序跳轉(zhuǎn)到放在地址 0x34800的IAP程序。但在擦除地址 0? 段的過程中會死在擦除函數(shù)中。
但將flash例程中的代碼,移植到程序前面,這個過程就不會死機。
奇怪的問題在于即便刪除flash例程中的不相關(guān)代碼,例如,打印,也會導(dǎo)致仍然會死在擦除函數(shù)中。
具體卡死位置為 ch57x_flash.c? L115 行之后, 即:? ?R8_FLASH_COMMAND=ROM_CMD_ERASE;
附件上傳說服務(wù)器返回失敗,,只能貼代碼,如下。
/**********************************?(C)?COPYRIGHT?******************************* ?*?File?Name??????????:?main.c ?*?Author?????????????:?JFM ?*?Version????????????:?V1.0 ?*?Date???????????????:?2018/11/12 ?*?Description????????:?本程序通過2.4G接收程序的IAP,并將之更新到APP ?********************************************************************************* ?*?Copyright?(c)?2021?Nanjing?Qinheng?Microelectronics?Co.,?Ltd. ?*?Attention:?This?software?(modified?or?not)?and?binary?are?used?for? ?*?microcontroller?manufactured?by?Nanjing?Qinheng?Microelectronics. ?*******************************************************************************/ /******************************************************************************/ /*?頭文件包含?*/ #include?"CONFIG.h" #include?"CH57x_common.h" #include?"HAL.h" #include?"OTA.h" #include?"RF_PHY.h" /********************************************************************* ?*?GLOBAL?TYPEDEFS ?*/ __align(4)?u32?MEM_BUF[BLE_MEMHEAP_SIZE/4]; __align(4)?u8?Vector_BUF[512]; #define?IMAGE_A_ADDR 0 #define?IMAGE_B_ADDR 0x0001A400 #define?IMAGE_IAP_ADDR 0x00034800 #define?TEST_CODEADDR???0x24800 #define?TEST_CODESIZE 128 /******************************************************************************* *?Function?Name??:?main *?Description????:?主函數(shù) *?Input??????????:?None *?Output?????????:?None *?Return?????????:?None *******************************************************************************/ UINT32???TestBuf[?TEST_CODESIZE?]; int?main(?void?)? { UINT8??key_tmp=0; UINT16?i=0; PUINT32?p_flash,p32; UINT32?TEST_ADD=0x24800; #if?(defined?(HAL_SLEEP))?&&?(HAL_SLEEP?==?TRUE) ??GPIOA_ModeCfg(?GPIO_Pin_All,?GPIO_ModeIN_PU?); ??GPIOB_ModeCfg(?GPIO_Pin_All,?GPIO_ModeIN_PU?); #endif #ifdef?DEBUG ??GPIOA_SetBits(?bTXD1?); ??GPIOA_ModeCfg(?bTXD1,?GPIO_ModeOut_PP_5mA?); UART1_DefInit(?); #endif?? GPIOB_ModeCfg(?GPIO_Pin_6,?GPIO_ModeIN_PU?); ??PRINT("OLD?A?start.\n"); ??{ ????PRINT("%s\n",VER_LIB); ??} ??CH57X_BLEInit(?); ??HAL_Init(??); ??RF_RoleInit(?); ??RF_Init(?); while(1){ if(GPIOB_ReadPortPin(GPIO_Pin_6)==0){ if(key_tmp==0){ PRINT("JUMP?IAP.\n"); key_tmp=1; /*?? p32?=?(PUINT32)TEST_CODEADDR; ????PRINT(?"Read?addr=0x%08lx?:\n",?(UINT32)p32?);???? ????for(i=0;?i<TEST_CODESIZE;?i++) ????{ ????????PRINT("%08lx?",*p32++); ????}PRINT("\n"); ??? ????p32?=?(PUINT32)TEST_CODEADDR; ????PRINT(?"Earse?addr=0x%08lx?:?",?(UINT32)p32?); ????i?=?FlashBlockErase(?(UINT32)p32?); ????if(?i?==?SUCCESS?)??PRINT("success..\n"); ????else????????????????PRINT("failed..\n"); ?*/? ////////////////////////////以下這段代碼刪掉任何一塊,都會導(dǎo)致卡死在擦除過程/////////////////////////////////// ????p32?=?(PUINT32)TEST_CODEADDR; ????PRINT(?"Read?addr=0x%08lx?:\n",?(UINT32)p32?);???? ????for(i=0;?i<TEST_CODESIZE;?i++) ????{ ????????PRINT("%08lx?",*p32++); ????}PRINT("\n"); ????for(i=0;?i<TEST_CODESIZE;?i++) ????{ ????????TestBuf[i]?=?i; ????????TestBuf[i]?=?(TestBuf[i]<<8)?|?i; ????????TestBuf[i]?=?(TestBuf[i]<<8)?|?i; ????????TestBuf[i]?=?(TestBuf[i]<<8)?|?i; ????} ???? ????p32?=?(PUINT32)TEST_CODEADDR; ????PRINT(?"Write?addr=0x%08lx?:?",?(UINT32)p32?); ????i?=?FlashWriteBuf(?(UINT32)p32,?TestBuf,?TEST_CODESIZE*4?); ????if(?i?==?SUCCESS?)??PRINT("success..\n"); ????else????????????????PRINT("failed..\n");?? ????p32?=?(PUINT32)TEST_CODEADDR; ????PRINT(?"Read?addr=0x%08lx?:\n",?(UINT32)p32?);???? ????for(i=0;?i<TEST_CODESIZE;?i++) ????{ ????????PRINT("%08lx?",*p32++); ????} PRINT("\n"); //DelayMs(?5000?); /*?編程ImageA第一塊?*/ PRINT("ORG.\n"); FlashBlockErase(TEST_ADD); p_flash?=?(PUINT32)IMAGE_IAP_START_ADD; for(i=0;i<FLASH_BLOCK_SIZE/sizeof(UINT32);i++){ TestBuf[i]=*(p_flash+i); PRINT("?%08lx?",*(p_flash+i)); if(((i+1)%8)==0){ PRINT("-----%03d\n",i); } } i?=?(UINT32)FlashWriteBuf(TEST_ADD,TestBuf,?FLASH_BLOCK_SIZE); // p_flash?=?(PUINT32)TEST_ADD; // if(?i?==?SUCCESS?)??PRINT("success..\n"); // else????????????????PRINT("failed..\n");?? //PRINT("CPY.\n"); // for(i=0;i<FLASH_BLOCK_SIZE/sizeof(UINT32);i++){ // PRINT("?%x?",*(p_flash+i)); // if(((i+1)%8)==0){ // PRINT("-----%03d\n",i); // } // } //////////////////////////以上這段代碼刪掉任何一塊,例如上面注釋,就會導(dǎo)致卡死在擦除過程////////////////////////////////////////////////////////////// PRINT("UPD.\n"); p_flash?=?(PUINT32)IMAGE_IAP_START_ADD; /*?關(guān)閉當(dāng)前所有使用中斷,或者方便一點直接全部關(guān)閉?*/ DisableAllIRQ(); PRINT("ERA.\n"); FlashBlockErase(IMAGE_A_START_ADD); //清除芯片的第一塊 PRINT("WRI.\n"); FlashWriteBuf(IMAGE_A_START_ADD,?p_flash,?FLASH_BLOCK_SIZE); PRINT("JUMP?.\n"); /*?保證打印結(jié)束?*/ DelayMs(?10?);// /*?復(fù)位,進用戶程序運行,跳轉(zhuǎn)到IAP程序?*/ SYS_ResetExecute(?); } }else{ key_tmp=0; } TMOS_SystemProcess(?); } } /********************************?endfile?@?main?******************************/
熱門產(chǎn)品 :
USB3.0 HUB控制器:CH634