cancel
Showing results for 
Search instead for 
Did you mean: 

Another bootloade question

spa2
Associate II

Posted on May 26, 2010 at 07:59

Another bootloade question

5 REPLIES 5
Posted on May 17, 2011 at 13:52

If I don’t use interrupts in my application, it seems to work fine, but if I use interrupts something goes wrong.

 

No kidding. You should probably have the boot loader code jump directly into the application very early in the boot process, and certainly before you have set interrupts up. I've advocated several times on the forum the use of rebooting and checking RAM based magic numbers.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
indrek
Associate II
Posted on May 17, 2011 at 13:52

May I ask what the problem was and how did you solve it?

Have you also solved the system reset problem that you had?

I'm having problems with a simple custom bootloader and application code that uses interrupts as well. It might be that I've forgotten to disable some interrupts before jumping (though, shouldn't all interrupts be disabled on a reset anyway?)

A simple LED-blinky application at 0x0800 8000 boots well, problems occur when I try to use any interrupts in the application code.

Booloader based on LeafLabs Maple (

http://leaflabs.com/docs/bootloader.html

:(

#define BOOT_ADDR       0x08008000

void jumpToUser (u32 usrAddr) {

  typedef void (*funcPtr)(void);

  u32 jumpAddr = *(vu32*) (usrAddr + 0x04); /* reset ptr in vector table */  

  funcPtr usrMain = (funcPtr) jumpAddr;

  flashLock();

  nvicDisableInterrupts();

  systemReset(); // resets clocks and periphs, not core regs  

  __MSR_MSP(*(vu32*) usrAddr);              /* set the users stack ptr */

  usrMain();                                /* go! */

}

int main() {

    NVIC_SetVectorTable( NVIC_VectTab_FLASH, 0x8000 );

    if (checkUserCode( BOOT_ADDR ))

        jumpToUser( BOOT_ADDR );

    

    while( 1 ) { ; }

}

rs2399
Associate II
Posted on May 17, 2011 at 13:52

    SysTick_CounterCmd(SysTick_Counter_Disable);

    NVIC_DeInit();

    RCC_DeInit();

spa2
Associate II
Posted on May 17, 2011 at 13:52

It seems that I have found my problem, but I do have one question.

I have two spaces in the flash, one for bootloader and one for the application; my question is how I can perform a reset make the bootloader start all over.

I have tied with System reset without any look, and if I do a Core reset I can’t after worth use the I2C bus.(The STm32 is slave on the bus)

// Code

NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00);

NVIC_GenerateSystemReset();

// CodeEnd

Bootloader address space : 0x08000000 – 0x08001800   

Application address space : 0x8002000– 0x8014000

indrek
Associate II
Posted on May 17, 2011 at 13:52

Never mind..

Thanks to Atollic gdb server and ST-Link, I found out that the problem was not in interrupts.

The most nasty problem was jumping to an uninitialized function pointer that was in someone else's code.

After booting the application code, HCLK_Frequency, PCLK1_Frequency, PCLK2_Frequency and ADCCLK_Frequency are all 0x0, which is not what happens after a simple reset. And because of this, USART BRR becomes 0x0.

Edit: The cause was APBAHBPrescTable ending up in the .data section and being filled with gibberish (because both the bootloader and test app use the same region of RAM).

So, I just replaced

static __I uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9};

with

#define __READ_ONLY __attribute__((section(''.flashtext'')))

__READ_ONLY uint8_t APBAHBPrescTable[16] = {0, 0, 0, 0, 1, 2, 3, 4, 1, 2, 3, 4, 6, 7, 8, 9}; where

/*

* for some STRx devices, the beginning of the startup code is stored in the .flashtext section,

* which goes to FLASH

*/

.flashtext :

{

. = ALIGN(4);

KEEP (*(.flashtext)) /* Startup code */

. = ALIGN(4);

} >FLASH for example. Or you could create a custom section for these variables.

Note that I'm using Raisonance Ride and the aforementioned macro for defining section might not work on other IDE-s. See [DEAD LINK /public/STe2ecommunities/mcu/Lists/ARM%20CortexM3%20STM32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/ARM CortexM3 STM32/Struct in Flash&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000626BE2B829C32145B9EB5739142DC17E&currentviews=334]this post on some more details.

Thanks