Hi to all,
First of all, I apoligize for new topic about bootloader. I have searched but haven't found any post about it.
I'm working about custom bootloader via uart for STM32F072 microprocessor. I analyzed example of Usb Uart Bootloader project and i have tried same method for jump to bootloader firmware unlike jump to application but did't work.
My question is, how can i jump to bootloader start address(0x0801FC00). How can i set main stack pointer and call reset handler? Can anyone explain or send sample codes?
Best regards,
Jump to Bootlader issue
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Jump to Bootlader issue
Hi,
Welcome to the MikroE forum.
You didn't specify which MCU from the STM32F072 family you are using.
If it's STM32F072CB which has ROM range 00000000-0001FFFF, you need to set constants in the following example as below: C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for ARM\Examples\ST\Other\USB UART Bootloader\STM32F051R8
You use directive org to specify a starting address of a routine in ROM.
Kind regards,
Welcome to the MikroE forum.
You didn't specify which MCU from the STM32F072 family you are using.
If it's STM32F072CB which has ROM range 00000000-0001FFFF, you need to set constants in the following example as below: C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for ARM\Examples\ST\Other\USB UART Bootloader\STM32F051R8
Code: Select all
#pragma orgall 0x1EC00
#define BOOTLOADER_START_ADDR 0x1EC00
#define START_PROGRAM_ADDR 0x1FC00
Kind regards,
Stefan Filipović
Re: Jump to Bootlader issue
Hi,
Thanks for your reply. I realized that should to give more info about my project..
I'm using a STM32F072CB. My application has very big size that is almost 110k. Bootloader size is almost 12k.
Application starts 0x0000000 and bootloader starts 0x0801C000 address. They are working succesfully.
Bootloader firmware has been tried before same mcu(STM32F072CB) and it's working succesfully. I think that important thing is application and bootloader were KEIL projects. But now, Application project is on Microbasic Pro Arm IDE and Bootloader project is on KEIL IDE.
I used to this pieces of codes to jump to bootloader in KEIL project.
Like above code, i think that i need to similar codes on Microbasic. I have tried pieces of code below that you said "C:\Users\Public\Documents\Mikroelektronika\mikroC PRO for ARM\Examples\ST\Other\USB UART Bootloader\STM32F051R8"
When i get special character via uart to jump to bootloader, i call below function. But it's not jumping to 0x0801C000 address.
I hope its more clear and understandable.
Best regars,
Thanks for your reply. I realized that should to give more info about my project..
I'm using a STM32F072CB. My application has very big size that is almost 110k. Bootloader size is almost 12k.
Application starts 0x0000000 and bootloader starts 0x0801C000 address. They are working succesfully.
Bootloader firmware has been tried before same mcu(STM32F072CB) and it's working succesfully. I think that important thing is application and bootloader were KEIL projects. But now, Application project is on Microbasic Pro Arm IDE and Bootloader project is on KEIL IDE.
I used to this pieces of codes to jump to bootloader in KEIL project.
Code: Select all
#define BOOTLOADER_ADDRESS 0x0801C000
if (((*(__IO uint32_t*)BOOTLOADER_ADDRESS) & 0x2FFE0000 ) == 0x20000000)
{
JumpAddress = *(__IO uint32_t*) (BOOTLOADER_ADDRESS+ 4);
JumpToBootloader = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) BOOTLOADER_ADDRESS);
JumpToBootloader();
}
Code: Select all
const START_BOOTLOADER_ADDR = 0x0801F000
sub procedure Start_Bootloader() org 0x1F000
end sub
sub procedure Write_Begin()
dim i as word
ptr as ^longword
value as longword
appResetVector as byte[16]
arm_m0_inst as longword
dataToWrite as word
ptr = 0x0801C000
FLASH_Unlock()
'LDR R0, PC+X
arm_m0_inst = 0x4800 + 1
appResetVector[0] = arm_m0_inst
appResetVector[1] = arm_m0_inst >> 8
'MOV SP, R0
arm_m0_inst = 0x4685
appResetVector[2] = arm_m0_inst
appResetVector[3] = arm_m0_inst >> 8
'LDR R0, PC+Y
arm_m0_inst = 0x4800 + 1
appResetVector[4] = arm_m0_inst
appResetVector[5] = arm_m0_inst >> 8
'BX R0
arm_m0_inst = 0x4700
appResetVector[6] = arm_m0_inst
appResetVector[7] = arm_m0_inst >> 8
value = ptr^
'SP
appResetVector[8] = value
appResetVector[9] = value >> 8
appResetVector[10] = value >> 16
appResetVector[11] = value >> 24
ptr = 0x0801C004
value = ptr^
'PC
appResetVector[12] = value
appResetVector[13] = value >> 8
appResetVector[14] = value >> 16
appResetVector[15] = value >> 24
FLASH_ErasePage(START_BOOTLOADER_ADDR)
for i = 0 to 7
dataToWrite = appResetVector[i * 2] or (appResetVector[i * 2 + 1] << 8)
FLASH_Write_HalfWord( START_BOOTLOADER_ADDR + i*2, dataToWrite)
next i
FLASH_Lock()
end sub
When i get special character via uart to jump to bootloader, i call below function. But it's not jumping to 0x0801C000 address.
Code: Select all
sub procedure jumpToBootloader
Write_Begin()
Start_Bootloader()
end sub
Best regars,
- stefan.filipovic
- mikroElektronika team
- Posts: 1135
- Joined: 18 Dec 2018 10:30
Re: Jump to Bootlader issue
Hi,
In that case, you should set the bootloader start address to 0x1C000 instead of 0x1F000: Kind regards,
In that case, you should set the bootloader start address to 0x1C000 instead of 0x1F000:
Code: Select all
const START_BOOTLOADER_ADDR = 0x0801C000
sub procedure Start_Bootloader() org 0x1C000
end sub
Stefan Filipović