cancel
Showing results for 
Search instead for 
Did you mean: 

IAP jump to APP, but it don't work.HELP!!!

Treacy Yao
Associate II
Posted on January 17, 2018 at 11:38

Hi,

I was doing IAP&App in STM32F030rc. 

When I finish IAP and APP, and run from IAP to jump to APP, it can not be realized. I have try many ways, but useless. Please help me, I have waste a lot of time for this function.

IAP project:

#define APPADDRESS 0x08020000;

typedef void (*pFunction)(void);    

pFunction Jump_To_Application;

uint32_t JumpAddress;

uint32_t ApplicationAddress = APPADDRESS;

int main(void)

{

//NVIC_SetVectorTable();

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

 // MX_RTC_Init();

  MX_USART1_UART_Init();

  MX_ADC_Init();

 // MX_I2C1_Init();

  MX_USART2_UART_Init();

  //MX_USART3_UART_Init();

  //MX_USART5_UART_Init();

  /* USER CODE BEGIN 2 */

 log_init();

 USART_Prepare();

  JumpToApp();

....

}

void JumpToApp(void)

{

 /* check the APP address stack point is correct, because the first 4 bytes store the stack address, default is  0x20000000 */

     TRACE_DBG_STRING(DEBUG_MODULE, LOG_LVL_INFO, 'JumpToApp:%x', ((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ));

 if (((*(__IO uint32_t*)ApplicationAddress) & 0x2FFE0000 ) == 0x20000000)

 {

 __set_PRIMASK(1);

      TRACE_DBG_STRING(DEBUG_MODULE, LOG_LVL_INFO, 'JumpToApp2:%x', *(__IO uint32_t*) (ApplicationAddress + 4));

  /* Move the 4 bytes to APP address */

  JumpAddress = *(__IO uint32_t*) (ApplicationAddress + 4);

  /* Point to the APP entry address */

  Jump_To_Application = (pFunction) JumpAddress;

  /* Reset the top of the stack point address */

  __set_MSP(*(__IO uint32_t*) ApplicationAddress);

  /* Jump to the reset function */

  Jump_To_Application();

 }

}

================================================

APP project:

#define APPADDRESS 0x08020000;

uint32_t ApplicationAddress = APPADDRESS;

int main(void)

{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

 

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

  HAL_Init();

  /* Configure the system clock */

  SystemClock_Config();

  NVIC_SetVectorTable();

//__set_PRIMASK(0);

  /* Initialize all configured peripherals */

  MX_GPIO_Init();

  MX_RTC_Init();

  MX_USART1_UART_Init();

  MX_ADC_Init();

  MX_I2C1_Init();

  MX_USART2_UART_Init();

  MX_USART3_UART_Init();

  MX_USART5_UART_Init();

.....

}

void NVIC_SetVectorTable(void) 

{  

 U8 i; 

 U32 *pVecTab=(U32 *)(0x20000000); 

 for(i = 0; i < 48; i++) 

 { 

  *(pVecTab++) = *(__IO U32*)(ApplicationAddress + (i<<2)); 

 } 

 __HAL_RCC_SYSCFG_CLK_ENABLE(); 

 __HAL_SYSCFG_REMAPMEMORY_SRAM();

And of course, I have changed the .ICF file.

IAP project:

/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile='$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml' */

/*-Specials-*/

define symbol __ICFEDIT_intvec_start__ = 0x08000000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x08000000;

define symbol __ICFEDIT_region_ROM_end__   = 0x0801FFFF;

define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;

define symbol __ICFEDIT_region_RAM_end__   = 0x20007FFF;

/*-Sizes-*/

define symbol __ICFEDIT_size_cstack__ = 0x400;

define symbol __ICFEDIT_size_heap__ = 0x200;

/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;

define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];

define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };

define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

initialize by copy { readwrite };

do not initialize  { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place in ROM_region   { readonly };

place in RAM_region   { readwrite,

                        block CSTACK, block HEAP };

export symbol __ICFEDIT_region_RAM_start__;

export symbol __ICFEDIT_region_RAM_end__;

=============================================

APP project:

/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile='$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml' */

/*-Specials-*/

define symbol __ICFEDIT_intvec_start__ = 0x08020000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x08020000;

define symbol __ICFEDIT_region_ROM_end__   = 0x0803FFFF;

define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;

define symbol __ICFEDIT_region_RAM_end__   = 0x20007FFF;

/*-Sizes-*/

define symbol __ICFEDIT_size_cstack__ = 0x400;

define symbol __ICFEDIT_size_heap__ = 0x200;

/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;

define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__   to __ICFEDIT_region_ROM_end__];

define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__   to __ICFEDIT_region_RAM_end__];

define block CSTACK    with alignment = 8, size = __ICFEDIT_size_cstack__   { };

define block HEAP      with alignment = 8, size = __ICFEDIT_size_heap__     { };

initialize by copy { readwrite };

do not initialize  { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place in ROM_region   { readonly };

place in RAM_region   { readwrite,

                        block CSTACK, block HEAP };

export symbol __ICFEDIT_region_RAM_start__;

export symbol __ICFEDIT_region_RAM_end__;
5 REPLIES 5
Posted on January 17, 2018 at 14:36

>>

I have try many ways, but useless. Please help me, I have waste a lot of time for this function.

Unfortunately you just pasted the code and didn't explain what you learned about what was happening when you were debugging during this time.

What exactly goes wrong, and how far can you step into your APP code?

I would expect you'd want to set up the vector table before HAL_Init()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 18, 2018 at 01:17

1. Sorry that I've not explained my problem. My APP aplication will let LED blink, but when I add IAP and modify the APP application(add

Vector redefinition

), the LED blink cannot be realized. I don't know the problem is from IAP or APP, I don't know how to debug.

2. Now, when running IAP, it will run to APP directly. 

3. I've tried '

set up the vector table before HAL_Init()', but still useless. The phenomenon is same as 1.

I don't know where the problem is, plz help!

Posted on January 18, 2018 at 04:29

Things look reasonable enough. I don't think I'd have the PRIMASK code in there, and I'd be wary of what interrupts (SysTick) that are running in the IAP loader side.

Implement a proper Hard Fault Handler so you can determine if the processor traps into that for some reason. ie Unhandled IRQ or touching memory inappropriately.

I can't expend time/resources on recreating the situation, and don't think I have an F030RC to hand to test on. You'll have to use the debugger in the IAP, you want to step into the 

Jump_To_Application call, ideally from the disassembly view, and confirm it enters into the Reset_Handler on the APP side, and how far along it goes. Watch what is happening in the system_stm32f0xx.c code, especially the SystemInit() function and the subroutines that calls.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 18, 2018 at 04:36

define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;  <<< Change this to 0x200000C0 on the APP so it doesn't step on the vector table

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Treacy Yao
Associate II
Posted on January 23, 2018 at 04:20

Thanks a lot. I have realized the IAP to APP function.