2008-03-28 03:28 AM
calling boot/flash loader from user code
2011-05-17 03:27 AM
2011-05-17 03:27 AM
in C this is how to cast an address as a void function and call it
(*(void (*) (void))(0x1ffff000))(); i cant remember the assembler equivalent for sure but its roughly ldr r1 0x1ffff000 blx r1 if the boot loader remaps the memory and uses absolute addressing the function you're jumping to won't work thought but as i don't know the boot loader code i haven't a clue.2011-05-17 03:27 AM
(this was discussed earlier.)
2011-05-17 03:27 AM
2011-05-17 03:27 AM
jumping to the loader like that is dangerous since the stack pointer could be at a ram area used for storage in the loader.
at a minimum you should: -reset all RCC-resetable peripherals (see RCC_APBxPeriphResetCmd()) -safer if you also reset DMA and NVIC -reset the RCC to HSI without PLL and other default stuff (see RCC_DeInit()) -set SCB->VTOR to the sys mem start (0x1ffff000?) (this is to more or less emulate the reset behavior; on reset VTOR = 0, but when booting the bootloader the sys mem is aliased to adr 0, so the vectors are available.) -SP = *((int*) 0x1ffff000); -PC = *((int*) 0x1ffff004); some post I made on the thread you mention sort of explains the last items. [ This message was edited by: lanchon on 27-03-2008 16:26 ]2011-05-17 03:27 AM
2011-05-17 03:27 AM
> But I don't understand what you mean about the memory aliasing ?
when the stm32 is out of reset one of the mems (flash, sys mem, or ram) is aliased to address zero, depending on the BOOT0/1 pins. and VTOR is zero, so vectors work without initing VTOR. since you can't clear VTOR and change the aliased range by software (i think), the closest thing you can do is to set VTOR so that it points to the same content (ie, the start of the sys mem range). > I can do this with some inline assembly. looks right but I don't remember much about assembler. > I know I've not included all the resetting of the peripherals, > but that should be a simple matter of calling the DeInit() functions. you can reset almost all peripherals with one pair of calls, see RCC_APBxPeriphResetCmd(). (that function is used in DeInit() of almost all peripherals, take a look.) but DMA and NVIC have to be reset differently. also, you may need to set or clear things like PRIMASK and clear the processor registers to be completely compatible. you'd have to look for that info in the cortex manual. but come to think of it, there's a much better way of doing all this, simply: -call NVIC_SETFAULTMASK() to assure the vector table won't be used, -set VTOC to 0x1ffff000, -and cause a software reset. the reset will init all peripherals, registers and processor flags, and set SP and PC from the vector table. so it should be that simple. (only ''incompatibility'' is that the target code can know that this is not a power-on reset.)2011-05-17 03:27 AM
2011-05-17 03:27 AM