Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 11 months ago.
STM32F7 bootloader help
Hi All,
I have a bootloader request with NUCLEO_F746ZG(STM32F746ZG). And I leverage the way of below link to use. https://os.mbed.com/docs/v5.6/tutorials/bootloader.html
But it's not work... My environment is including mbed-os.lib, use mbed CLI, GCC_ARM and windows7. This is my bootloader.
bootloader
#include "mbed.h" DigitalOut myled(LED1); InterruptIn button(BUTTON1); void leave_bootloader() { mbed_start_application(POST_APPLICATION_ADDR); } int main() { button.rise(&leave_bootloader); while(1) { myled = 1; // LED is ON wait(0.5); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec } }
This is my main program.
main
#include "mbed.h" DigitalOut myled(LED2); int main() { while(1) { myled = 1; // LED is ON wait(0.5); // 200 ms myled = 0; // LED is OFF wait(1.0); // 1 sec } }
There are my few steps to do.
- Step1. I referred to https://github.com/armmbed/mbed-os-example-bootloader-blinky and ad a mbed_app.json file.
mbed_app.json
{ "target_overrides": { "NUCLEO_F746ZG": { "target.restrict_size": "0x20000" } } }
Then change linker script.
STM32F746xG.ld
#if !defined(MBED_APP_START) #define MBED_APP_START 0x08000000 #endif #if !defined(MBED_APP_SIZE) #define MBED_APP_SIZE 1024k #endif /* Linker script to configure memory regions. */ MEMORY { FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE RAM (rwx) : ORIGIN = 0x200001C8, LENGTH = 320K - 0x1C8 }
Use mbed compile to compile the bootloader. Mbed CLI gave me a error "Bootloader not supported on this target". So I go to targets.json to add "bootloader_supported": true below NUCLEO_F746ZG. Finally the bootloader is completed.
- Step2 Create a new json file to my man program project.
mbed_app.json
{ "target_overrides": { "NUCLEO_F746ZG": { "target.bootloader_img": "bootloader/bootloader.bin" } } }
Change ld file and targets.json the same as bootloader projeact then compile. I update the final firmware to my board and test user button to switch in application, but it fail. It only can run bootloader. Do anyone can tell my step what is wrong?
2 Answers
6 years, 8 months ago.
Hi, following the tutorial I can program the program-image + bootloader image. Than I can execute bootloader program when the board start, leave bootloader and correctly execute the main program.
You can't use "wait" function. In order to correctly leave bootloader and start program you have to close all connection all resource you've allocated in bootstrap.
I've used a the following code to implement delay function
Timer *t = new Timer;" while(t->read()<1);
My problem is that FlashIAP don't work correctly, and at the end of my flashing procedure the original firmware doesn't work anymore (but the bootloader works).
Here my bootloader main code:
#include "mbed.h" #if !defined(POST_APPLICATION_ADDR) #error "target.restrict_size must be set for your target in mbed_app.json" #endif //FlashIAP flash; void apply_update(Serial *ps, uint32_t address); int main() { uint8_t sByte[7]; int count=0; Serial *pc = new Serial(USBTX, USBRX); // tx, rx Timer *t = new Timer; pc->baud(57600); pc->printf("GPD - Bootloader... \r\n"); pc->printf("Wait 10 sec for update\r\n"); t->reset(); t->start(); while(t->read()<10) { if(pc->readable()==1) { sByte[count] = pc->getc(); count++; if(count==7) { if((sByte[0]=='U')&&(sByte[1]=='P')&&(sByte[2]=='D')&&(sByte[3]=='A')&&(sByte[4]=='T')&&(sByte[5]=='E')&&(sByte[6]=='\n')) { while(pc->readable()){ pc->getc(); } while(pc->readable()){ pc->getc(); } pc->printf("Ready to receive firmware update...\r\n"); apply_update(pc,POST_APPLICATION_ADDR); break; } } } } t->stop(); pc->printf("Starting application at address [%X] \r\n",POST_APPLICATION_ADDR); free(pc); free(t); //flash->deinit(); mbed_start_application(POST_APPLICATION_ADDR); }
Any Idea??
Thank you
If you have issues with FlashIAP on this board, can you report it at https://github.com/armmbed/mbed-os ; then core Mbed OS team or ST engineers can take a look at it.
posted by 02 Mar 20186 years, 11 months ago.
That looks decent to me, could you attach a debugger (e.g. OpenOCD + GDB) to see what happens when the jump happens. Does it jump to empty flash or does it hang in e.g. a HardFault. We had some issues with interrupts not properly being cleared before which caused issues on another target. Would be good to debug.
If that does not help, can you raise an issue at https://github.com/armmbed/mbed-os, that's where the core team hangs out.
Hi Jan Jongboom, I used VisaulGDB+MVS and found when I trigger user_button, it will enter Infinite_Loop.... It seems like a serious conflict. If I change to below code, it will jump to main. The LED1 will not erase, and LED2 will flash.
bootloader
#include "mbed.h" int main() { myled = 1; mbed_start_application(POST_APPLICATION_ADDR); }
If I add wait(0.5) to bootloader. It will entry Infinite_Loop again.
bootloader
#include "mbed.h" int main() { myled = 1; wait(1); // 1s mbed_start_application(POST_APPLICATION_ADDR); }
And I really don't know to debug it... Maybe create a issue is better idea.
posted by 17 Dec 2017