6 years, 4 months ago.

please HELP with Bootloader problems (possible tutorial inside)

Greetings.

I am working with a NUCLEO_L476RG board.

Currently I am trying to learn about bootloaders to subsequently try FOTA upgrades.

My first goal is to create a very simple bootloader and a very simple main_program to check if the bootloader is able to jump into the memory block of the main program.

For this task I am following the tutorial: https://os.mbed.com/docs/v5.6/tutorials/bootloader.html

and the git explanations:

-Bootloader https://github.com/ARMmbed/mbed-os-example-bootloader

-Main program https://github.com/ARMmbed/mbed-os-example-bootloader-blinky

Based on those git examples I have created my bootloader and my program which are the following. The steps I have followed are:

Step 1: Create the Bootloader:

-Step1.1 File main.cpp

#include "mbed.h"


Serial pc(D1, D0);
DigitalOut myled(LED1);

int main()
{
    
    pc.printf("Bootloader started,\n\r Main program starts in…:\n\r");
    myled=1;
    
    for(int i=10;i>0;i--) {
        
        pc.printf("\r %d",i);
        wait(1);
    }
    myled=0;
    mbed_start_application(POST_APPLICATION_ADDR);
}

-Step1.2 File mbed_app.json

{
    "config": {
      
    },
    "target_overrides": {
       
        "NUCLEO_L476RG": {
            "target.restrict_size": "0x40000"
        }
       
    }
}

-Step1.3 Following the tutorial I compile this program and it creates the file.bin Up to here everything is correct =).

Problem 1

My first problem appears now: If I use the online compiler when I create the following project and include the .bin file, I get an error message because it seems that the compiler does not allow importing them.

Solution

The solution that I decide is, Using mbed CLI instead mbed online compiler.

Step 2 Create the main application

-Step2.1 I imported the git proyect https://github.com/ARMmbed/mbed-os-example-bootloader-blinky to my local directory with mbed CLI:

-Step2.2 I added the .bin of the bootloader that I created (boot_NUCLEOL476RG.bin) and deleted the example from the following folder:

Quote:

C:\mbed_programs\mbed-os-example-bootloader-blinky\bootloader

-Step2.3 I opened the main.cpp file with notepad ++ and modified it:

#include "mbed.h"

DigitalOut led1(LED1);
Serial pc(D1, D0);
int i=0;
// main() runs in its own thread in the OS
int main() {
    pc.printf("\n\r main program\n\r");
    i=0;
    while (true) {
        
        pc.printf("\n\r running %d seconds\n\r",i);
        led1 = !led1;
        wait(1);
        i++;
    }
}

-Step 2.4 I opened the file mbed_app.json with notepad ++ and modified it to the following code:

{
    "config": {
      
    },
    "target_overrides": {
        
        "NUCLEO_L476RG": {
            "target.bootloader_img": "bootloader/boot_NUCLEOL476RG.bin"
        
        }
    }
}

-Step 2.5 Compiling with CLI

Quote:

C:\mbed_programs\mbed-os-example-bootloader-blinky> mbed config target NUCLEO_L476RG C:\mbed_programs\mbed-os-example-bootloader-blinky>mbed toolchain GCC_ARM C:\mbed_programs\mbed-os-example-bootloader-blinky>mbed config GCC_ARM_PATH "C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q2-update\bin" C:\mbed_programs\mbed-os-example-bootloader-blinky>mbed compile

Problem 2

And my second problem has appeared. The console told me that my target board does not allow bootloader. But it is allowed, the instruction ( "bootloader_supported": true) appears in the targets.json file of mbed compiler online

Solution

I have opened the targets.json file of my local project (CLI) and modified my target:

.
.
.

"NUCLEO_L476RG": {
        "supported_form_factors": ["ARDUINO", "MORPHO"],
        "core": "Cortex-M4F",
        "default_toolchain": "ARM",
        "extra_labels": ["STM", "STM32L4", "STM32L476RG", "STM32L476xG"],
        "supported_toolchains": ["ARM", "uARM", "IAR", "GCC_ARM"],
        "inherits": ["Target"],
        "detect_code": ["0765"],
        "macros": ["TRANSACTION_QUEUE_SIZE_SPI=2","USBHOST_OTHER"],
        "device_has": ["ANALOGIN", "ANALOGOUT", "CAN", "I2C", "I2CSLAVE", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SERIAL_FC", "SLEEP", "SPI", "SPISLAVE", "SPI_ASYNCH", "STDIO_MESSAGES", "TRNG"],
        "release_versions": ["2", "5"],
        "device_name": "STM32L476RG",
		"bootloader_supported": true
    },
.
.
.

And the program has compiled !!!

Problem 3

Once the .bin has been generated I have added it to my evaluation board STM32L476RG and from what I see in terminal only the part of the bootloader is launched. =(

That is, I see the countdown and how the led turns off (bootloader) but I do not see the LED blinking or anything per terminal (main_program)

I would like to please someone to tell me if I am doing something wrong, if I did not understand some section of the process of creating a bootloader, or if you have any idea or solution. Since without bootloader I will not be able to advance to the next step (firmware upgrade)

PS: Please Could someone bright me with your ideas? I'm desperate.

Thank you very much, Greetings

IG

UPDATE:

I solved the problem.

The problem arises because when importing the git examples and updating them in CLI some files are not updated correctly. I mean, I created the program from the beginning and I did not need to modify the targets.json file and it works perfectly. I do not know if it is a CLI failure or that I use the wrong command.

Anyway, the program works and is a pretty simple example of a bootloader and a main application

1 Answer

6 years, 4 months ago.

I solved the problem.

The problem arises because when importing the git examples and updating them in CLI some files are not updated correctly. I mean, I created the program from the beginning and I did not need to modify the targets.json file and it works perfectly. I do not know if it is a CLI failure or that I use the wrong command.

Anyway, the program works and is a pretty simple example of a bootloader and a main application

Even so it would be interesting to check if CLI is not updated well the files . And would be interesting write the steps or reliability to do the bootloader from the web

Accepted Answer

Assigned to Ivan Gutierrez 6 years, 4 months ago.

This means that the question has been accepted and is being worked on.