cancel
Showing results for 
Search instead for 
Did you mean: 

IAP Problem

giles
Associate II
Posted on April 03, 2008 at 10:42

IAP Problem

3 REPLIES 3
giles
Associate II
Posted on May 17, 2011 at 12:28

Hi all,

I am writing my own IAP firmware. This will allow the user to upgrade in the field. The code for this resides at the end of the chip and is completely separate code (project) from the main firmware. The IAP will be driven by a serial interface from USART1.

Both main & IAP firmware are pre-programmed into the STM32.

In order to update the main firmware, the following steps are envisaged:

1. A command is sent via a serial interface to enter IAP mode. A JumpToIap flag is set and written to flash (at a fixed location).

2. Interrupts are Disabled and a software reset is called.

3. The main code starts up.

4. In start-up code, the JumpToIap flag is seen as set and the code jumps to a fixed address (the IAP code's start location)

5. IAP code runs, sets up the (un)initialised variables and stack pointer.

6. IAP code runs - Flash is updated accordingly using non-interrupt driven commands via USART1.

7. When finished, the JumpToIap flag is cleared and written to flash.

8. A software reset is called.

9. The main code starts up. In start-up code, the JumpToIap flag is seen as cleared and the code runs normally.

My questions / problem are as follows:

For a software reset, I am using the NVIC_GenerateCoreReset() function as the NVIC_GenerateSystemReset() function doesn't seem to work. Is this resetting the hardware properly - this is what I want to do.

If I try to jump to my IAP code (as in step 4), I get a hardware exception. However, if I single step through the code on my debugger, it seems to work OK.

I have a suspicion that the stack pointer is something to do with the problem. How do I manually set the stack pointer?

On looking at the vector table, the first item at address 0x00000000 is reserved. Is this for initialising the stack pointer?

My code in startup (as in step 4 & 9) is as follows:

#define STM32_IAP_MAIN_ADDRESS 0x0801C000

#define STM32_IAP_FLAG_ADDRESS 0x0801FC00

#define STM32_IAP_FLAG 'I' + ('A' * 0x100) + ('P' * 0x010000)

void ResetISR(void)

{

unsigned int IapFlag;

//Read IAP Flag

IapFlag = *(unsigned int*)STM32_IAP_FLAG_ADDRESS;

//If IAP Flag set, then jump to IAP code. Else carry on

if (IapFlag == STM32_IAP_FLAG)

{

(*(void (*) (void))(STM32_IAP_MAIN_ADDRESS))();

}

......................

main();

}

Please help.

Thanks,

ericvanolden9
Associate II
Posted on May 17, 2011 at 12:28

You must jump to an odd adress.

See

http://www.st.com/mcu/forums-cat-6457-23.html

giles
Associate II
Posted on May 17, 2011 at 12:28

Thanks eric, i hadn't realised that!

I've moved my IAP code to the start of the STM32 (as observed from looking at source code in AN2557 IAP Apps Note). It now works OK!

I wasn't properly looking after the vector table & stack with my original method.

Thanks again.