cancel
Showing results for 
Search instead for 
Did you mean: 

Jumping to IAP code issue

JK.4
Associate II

Hi,

I am facing some issues while jumping from main application to the last locations(0x0801C000) of the flash memory, where IAP application (customized) is located.

The controller used is STM32F072.(128kb flash,Cortex-M0).

The main application code placed at 0x08000000.

I am using the GPRS modem to receive a new bin file from FTP (through main application) and am successful in placing the received bin starting from flash location 0x0800d800.

Issue: I am getting hard-fault error while jumping from main application to IAP locations. Especially when I set main stack pointer to 0x801c000 (__set_MSP(0x801c000))

JumpAddress = *(__IO uint32_t*) (0x0801C004);
  Jump_To_Application = (pFunction) (JumpAddress);     
      /* Initialize user application's Stack Pointer */
      __set_MSP(*(__IO uint32_t*) 0x0801C000);
      Jump_To_Application();

Can someone please help. I am not getting what is going wrong.

7 REPLIES 7
berendi
Principal

Are all interrupts disabled? Is systick stopped?

What values are in the flash at 0x0801C000 and 0x0801C004 ?

TDK
Guru

Debug the hard fault. See what caused it, investigate the addresses it's pointing to, see where the PC is at the time of the fault.

If you feel a post has answered your question, please click "Accept as Solution".

Yes. All the interrupts are disabled, including systick.

__disable_irq();

NVIC_DisableIRQ(USART1_IRQn);

NVIC_DisableIRQ(USART2_IRQn);

NVIC_DisableIRQ(RTC_IRQn);

NVIC_DisableIRQ(DMA1_Channel1_IRQn);

NVIC_DisableIRQ(TIM15_IRQn);         

NVIC_DisableIRQ(TIM16_IRQn);         

NVIC_DisableIRQ(TIM17_IRQn);  

SysTick->CTRL = 0;

SCB->ICSR |= SCB_ICSR_PENDSTCLR_Msk;

The value at 0x0801C000 is 0x80, and the value at 0x0801C004 is 0x21.

berendi
Principal

> The value at 0x0801C000 is 0x80

A bit odd as the LSB of the initial stack pointer.

Actually I wanted to see the 32-bit word values at 0x0801C000 and 0x0801C004.

Why are you adjusting the stack pointer before jumping at all? What is the first thing the Reset_Handler of the application at 0x0801C000 does?

The value at 0x801C000 is <0x80,0x12,0x00,0x20 >and the value at 0x801C004 is <0x21,0x29,0x00,0x08>0693W000001qPBWQA2.png

berendi
Principal

> The value at 0x801C000 is <0x80,0x12,0x00,0x20 >

that is 0x20001280, i.e. 4736 bytes from the start of SRAM. Why did you set it so low?

> the value at 0x801C004 is <0x21,0x29,0x00,0x08>

that is 0x08002921, which is way outside the flash range the aplication should occupy. Find out how to link the application at the address it is loaded to (I don't use IAR).

I don't like the look of your current SP either. Is it some IAR specific memory arrangement? How does the RAM memory map look like, is there anything placed above the stack?

And you haven't answered the last questions:

Why are you adjusting the stack pointer before jumping at all? What is the first thing the Reset_Handler of the application at 0x0801C000 does?

What is the first thing the Reset_Handler of the application at 0x0801C000 does?

Reset_Handler

    LDR   R0, =SystemInit

    BLX   R0

    LDR   R0, =__iar_program_start

    BX   R0

     

Why are you adjusting the stack pointer before jumping at all? 

I followed some sample codes.

__set_MSP(*(__IO uint32_t*) 0x0801C000)...After this it is going to hard fault error.