2017-03-28 10:35 AM
I am trying to execute the example program given by ST for firmware update using USB, I'm able to download and upload the binary image but the jump is not working properly. After the new program has flashed onto new location(sector 2), my Program Counter(PC) is supposed to jump to location 0x08008000, but it is getting stuck in some infinite loop. Can someone help me to sort this out asap please..
Below is the piece of code i'm using..
#include 'usbh_core.h'#include 'usbh_usr.h'#include 'usbh_msc_core.h'#include 'flash_if.h'USB_OTG_CORE_HANDLE USB_OTG_Core;USBH_HOST USB_Host;pFunction Jump_To_Application;
uint32_t JumpAddress;int main(void){ /* STM32 evalboard user initialization */ BSP_Init();/* Flash unlock */
FLASH_If_FlashUnlock(); /* Test if User button on the Discovery kit is pressed */ if (STM_EVAL_PBGetState(BUTTON_USER) == Bit_RESET) { /* Check Vector Table: Test if user code is programmed starting from address 'APPLICATION_ADDRESS' */ if (((*(__IO uint32_t*)APPLICATION_ADDRESS) & 0x2FFE0000 ) == 0x20000000) { /* Jump to user application */ JumpAddress = *(__IO uint32_t*) (APPLICATION_ADDRESS + 4); Jump_To_Application = (pFunction) JumpAddress; /* Initialize user application's Stack Pointer */ __set_MSP(*(__IO uint32_t*) APPLICATION_ADDRESS); __set_PSP(*(__IO uint32_t*) APPLICATION_ADDRESS); Jump_To_Application(); } } /* Init Host Library */ USBH_Init(&USB_OTG_Core, USB_OTG_FS_CORE_ID, &USB_Host, &USBH_MSC_cb, &USR_Callbacks); while (1) { /* Host Task handler */ USBH_Process(&USB_OTG_Core, &USB_Host); }}#ifdef USE_FULL_ASSERT/** * @brief assert_failed * Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param File: pointer to the source file name * @param Line: assert_param error line source number * @retval None */void assert_failed(uint8_t* file, uint32_t line){ /* User can add his own implementation to report the file name and line number, ex: printf('Wrong parameters value: file %s on line %d\r\n', file, line) *//* Infinite loop */
while (1) {}}#endif2017-03-28 02:52 PM
I'd suspect it is in the Hard Fault or Default Handler, because you have an interrupt running, and you are not servicing it at the new address, or haven't set the Vector Table Address correctly.
Look at the address of this loop, then look at the .MAP files for the loader and the application. Figure out where and what it is.
Also the PC isn't set to 0x08008000, that is the base of the Vector Table and contains no executable code, ideally you should be loading the value at 0x08008004 and then transferring control to that address, which should be ODD, and match the Reset_Handler described in the .MAP file for the application.