Help with custom bootloader

Post here first, or if you can't find a relevant section!
razzil
Posts: 3
Joined: Fri Feb 10, 2017 12:36 pm

Help with custom bootloader

Postby razzil » Fri Feb 10, 2017 2:30 pm

Hello friends! I want to split my program to two parts. First part is like bootloader, it should copy datas of second part from SD-card to flash memory and give it control.
I flashed my bootloader to 0x08002000, to the STM32duino-bootloader run ones. It works. Then via STM-link i uploaded second part of program to 0x0800FF00.
In my bootloader i included hardware.h and some others parts of STM32duino-bootloader to use it for jump to my program.
I use function jumpToUser(progAddr), where progAddr is 0x0800FF00.

This is code:

Code: Select all

#include "hardware.h"
uint32_t progAddr = 0x0800FF00;

void setup() {
   pinMode(PC13, OUTPUT);
}
void loop() {
  for(int i = 0; i<50; i++)
  {
    blink(50);
  }
 jumpToUser(progAddr);
}

void blink(int interval)
{
  digitalWrite(PC13, HIGH);
  delay(interval);
  digitalWrite(PC13, LOW);
  delay(interval);
}


My bootloader runs successful, but second program doesn't start (it simply to, just LED blinking).

Can anybody tell me, where is my mistake? Or I should go by another way?
Big thanks!!

edogaldo
Posts: 167
Joined: Fri Jun 03, 2016 8:19 am

Re: Help with custom bootloader

Postby edogaldo » Fri Feb 10, 2017 3:53 pm

Hi @razzil, I think you should compile the second sketch using VECT_TAB_ADDR=0x800FF00, did you do it?

Best, E.

User avatar
leavesw
Posts: 19
Joined: Fri Jun 24, 2016 2:25 am

Re: Help with custom bootloader

Postby leavesw » Sun Feb 12, 2017 12:13 am

edogaldo wrote:Hi @razzil, I think you should compile the second sketch using VECT_TAB_ADDR=0x800FF00, did you do it?

Best, E.


I made that exact mistake a month ago :)

User avatar
RogerClark
Posts: 5466
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Help with custom bootloader

Postby RogerClark » Sun Feb 12, 2017 3:00 am

razzil wrote:I flashed my bootloader to 0x08002000, to the STM32duino-bootloader run ones.


Execution starts from address 0x800000, so I'm not sure why you would be flashing your bootloader to 0x08002000

If you already have the maple / stm32duino bootloader in the base of flash, it would jump to 0x8002000 and run your bootloader, but I can't quite see why you'd have a system will a chain of multiple bootloaders

Just write your own bootload to run from 0x800000

razzil
Posts: 3
Joined: Fri Feb 10, 2017 12:36 pm

Re: Help with custom bootloader

Postby razzil » Mon Feb 13, 2017 11:59 am

Thanks guys for your answers! All that i want is having two programs. One program should update another, from SD or LAN. I haven't enough experience for low-level stm32 programming, but can something with arduino ;)
I guess that simple program compiled by stm32duino compiller, and uploaded to 0x08000000 wouldn't work without stm32duino-bootloader(which configures peripherals)? Its true?

So in my first program i do:

Code: Select all

void setMspAndJump(u32 usrAddr) {
  typedef void (*funcPtr)(void);
  u32 jumpAddr = *(vu32 *)(usrAddr + 0x04); /* reset ptr in vector table */

  funcPtr usrMain = (funcPtr) jumpAddr;

  SET_REG(SCB_VTOR, (vu32) (usrAddr));

  asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));

  usrMain();                                /* go! */
}

it's function from stm32duino-bootloader.
Where SCB_VTOR is:

Code: Select all

#define SCS      0xE000E000
#define SCB      (SCS+0xD00)
#define SCB_VTOR (SCB+0x08)

and usrAddr is address of my second program(0x08002000).
But nothing happens...

And what this code do?

Code: Select all

 asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));

victor_pv
Posts: 947
Joined: Mon Apr 27, 2015 12:12 pm

Re: Help with custom bootloader

Postby victor_pv » Tue Feb 14, 2017 1:49 pm

razzil wrote:Thanks guys for your answers! All that i want is having two programs. One program should update another, from SD or LAN. I haven't enough experience for low-level stm32 programming, but can something with arduino ;)
I guess that simple program compiled by stm32duino compiller, and uploaded to 0x08000000 wouldn't work without stm32duino-bootloader(which configures peripherals)? Its true?

So in my first program i do:

Code: Select all

void setMspAndJump(u32 usrAddr) {
  typedef void (*funcPtr)(void);
  u32 jumpAddr = *(vu32 *)(usrAddr + 0x04); /* reset ptr in vector table */

  funcPtr usrMain = (funcPtr) jumpAddr;

  SET_REG(SCB_VTOR, (vu32) (usrAddr));

  asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));

  usrMain();                                /* go! */
}

it's function from stm32duino-bootloader.
Where SCB_VTOR is:

Code: Select all

#define SCS      0xE000E000
#define SCB      (SCS+0xD00)
#define SCB_VTOR (SCB+0x08)

and usrAddr is address of my second program(0x08002000).
But nothing happens...

And what this code do?

Code: Select all

 asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));


Your main program needs to be compiled for the address in which it will be loaded and executed. Check the thread about running code from FSMC memory, there are multiple posts explaining that.

mamrezo
Posts: 2
Joined: Sun Feb 26, 2017 12:49 pm

Re: Help with custom bootloader

Postby mamrezo » Sun Feb 26, 2017 2:01 pm

razzil wrote:Thanks guys for your answers! All that i want is having two programs. One program should update another, from SD or LAN. I haven't enough experience for low-level stm32 programming, but can something with arduino ;)
I guess that simple program compiled by stm32duino compiller, and uploaded to 0x08000000 wouldn't work without stm32duino-bootloader(which configures peripherals)? Its true?

So in my first program i do:

Code: Select all

void setMspAndJump(u32 usrAddr) {
  typedef void (*funcPtr)(void);
  u32 jumpAddr = *(vu32 *)(usrAddr + 0x04); /* reset ptr in vector table */

  funcPtr usrMain = (funcPtr) jumpAddr;

  SET_REG(SCB_VTOR, (vu32) (usrAddr));

  asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));

  usrMain();                                /* go! */
}

it's function from stm32duino-bootloader.
Where SCB_VTOR is:

Code: Select all

#define SCS      0xE000E000
#define SCB      (SCS+0xD00)
#define SCB_VTOR (SCB+0x08)

and usrAddr is address of my second program(0x08002000).
But nothing happens...

And what this code do?

Code: Select all

 asm volatile("msr msp, %0"::"g"
               (*(volatile u32 *)usrAddr));

I have the same problem,
Do you have any answer for it?

razzil
Posts: 3
Joined: Fri Feb 10, 2017 12:36 pm

Re: Help with custom bootloader

Postby razzil » Sun Feb 26, 2017 2:56 pm

mamrezo wrote:Do you have any answer for it?

Yes, I have! Your program needs to know, from which address it starts.

First, you shold edit boards.txt file and VECT_TAB_ADDR property for your build config.
For example, my program is on 0x8008000 in flash. So VECT_TAB_ADDR=0x8008000.

And second, your build config has a reference to *.ld file, like this: "build.ldscript=ld/bootloader_20.ld". You should edit this file in "variants\YOUR_BUILD_NAME\ld" directory, and change "rom (rx) : ORIGIN =" property to your start address.

mamrezo
Posts: 2
Joined: Sun Feb 26, 2017 12:49 pm

Re: Help with custom bootloader

Postby mamrezo » Sun Feb 26, 2017 6:07 pm

razzil wrote:
mamrezo wrote:Do you have any answer for it?

Yes, I have! Your program needs to know, from which address it starts.

First, you shold edit boards.txt file and VECT_TAB_ADDR property for your build config.
For example, my program is on 0x8008000 in flash. So VECT_TAB_ADDR=0x8008000.

And second, your build config has a reference to *.ld file, like this: "build.ldscript=ld/bootloader_20.ld". You should edit this file in "variants\YOUR_BUILD_NAME\ld" directory, and change "rom (rx) : ORIGIN =" property to your start address.

Thank you very much.
you solved my problem.


Return to “General discussion”

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 3 guests