2010-05-25 10:59 PM
Posted on May 26, 2010 at 07:59
Another bootloade question
2011-05-17 04:52 AM
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.
2011-05-17 04:52 AM
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 ) { ; }
}
2011-05-17 04:52 AM
2011-05-17 04:52 AM
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 – 0x08001800Application address space : 0x8002000– 0x8014000
2011-05-17 04:52 AM
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 replacedstatic __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¤tviews=334]this post on some more details. Thanks