cancel
Showing results for 
Search instead for 
Did you mean: 

Custom external bootloader on custom F769I based Board

enia ami
Associate II
Posted on March 16, 2017 at 18:29

Hi community,

I need to write an external bootloader for my custom board based on the stm32f769I MCU.

According to the 'STM32 ST-LINK utility software description' manual, I have to modify one of the exemple provided and which supposed to be avaiable for three toolchain.

But, the most recent exemple (STM32L4) is only avaible on EWARM and the others exemples seem to be outdated and not relevant (M3 based board).

So, I assume that I have to adapt the whole code to the F769I. If someone already done that, it will be much appreciated to have some advice on how to do that.

Also I have a (stupid ?) question : where is the main function and how I compile this code ? gcc ?

Thanks a lot.

6 REPLIES 6
ChrisH
Associate III
Posted on March 16, 2017 at 19:26

I have written bootloader using SW4STM32 for L4 which flashes MCU from uSD card and also registers device through USB as MSC for easy firmware download onto the board. Ther isn't much you have to do.

First of all copy command.c and h files those both are high level files which will interface with provided flash_if file. Then take flash_if header modify all defines so they fit your micro and also modify accordingly C file (take L4 as a base).

Also as a matter of fact along with project there is readme file which explains all.

Posted on March 16, 2017 at 19:31

I think you're misusing 'bootloader', in the context of the ST-LINK Utilities, there is the ability to provide an applet capable of flashing an external memory that is unique to your board design. ST refers to this as an 'External Loader'

In this context it doesn't have a main() function, but rather an number of specific functions/entry points for erasing, writing and reading this memory device.

The concept is not unique to the Cortex-M7, all the parts share a common method/concept, and most of the uniqueness stems from the specific memory part you have attached, and its block sizes and function.

In GNU/GCC you'd use the linker script to describe the entry point, and the SRAM addresses the code resides.

You want to start with some bullet-proof code you have written to configure the external bus, and interact with your memory chip. Once you have all the core functionality working you'd then need to port that into the applet frame work so it can be used by the ST-LINK Utilities.

I've worked on these things, but it is beyond the scope of my forum participation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 17, 2017 at 10:23

Thank you Chris, but I made a mistake, as clive said, I meant external loader. I don't know why I added the 'boot'...

Anyway thanks for the help. 

Posted on March 17, 2017 at 12:25

Exactly, I meant external loader. It was just under my eyes but I wrote 'Bootloader'.

Turvey.Clive.002 wrote:

You want to start with some bullet-proof code you have written to configure the external bus, and interact with your memory chip. 

I've already done that work and it's fully opperational

Turvey.Clive.002 wrote:

you'd then need to port that into the applet frame work so it can be used by the ST-LINK Utilities.

THIS is where I do not have any idea...

Her is the part where the manual mention the customised external loader :

Using the examples available under the ExternalLoader directory, users can develop their

custom loaders for a given external memory .

These examples are available for three toolchains, i.e. MDK-ARMâ„¢, EWARM and

TrueSTUDIO®. The development of the custom loaders can be performed using one of the

three toolchains keeping the same compiler/linker configurations, as in the examples.

To create a new external memory loader, follow the steps below:

1.Update the device information in StorageInfo structure in the Dev_Inf.c file with the correct information concerning the external memory.

2. Rewrite the corresponding functions code in the Loader_Src.c file.

3. Change the output file name.

What I need to do, is to generate the output file without having any of the three toolchain mentioned for the STM32L4 example.

I opened the STM3210E with keil but it doesn't seem to be relevant or I'm missing something.

For the moment I have the source and the header files, correctly configured for my hw but I don't know what to do for the next step

Thx

ChrisH
Associate III
Posted on March 17, 2017 at 16:05

 First create project in CubeMX with minimal functionality so SDIO, FatFS and maybe one interrupt for uSD card detect. Don't even use DMA as dma drivers will eat more codespace. In main.c this is my personal routine:

FLASH_If_Init

()

;

while

(

HAL_GPIO_ReadPin

(

GPIOA

,

GPIO_PIN_9

)

==

GPIO_PIN_SET

)

{

//VBus is high - MSC Mode. Wait until device is unplugged.

HAL_GPIO_TogglePin

(

LD2_GPIO_Port

,

LD2_Pin

)

;

HAL_Delay

(

1000

)

;

}

//Clean after USB

HAL_Delay

(

1000

)

;

HAL_GPIO_WritePin

(

LD2_GPIO_Port

,

LD2_Pin

,

GPIO_PIN_SET

)

;

//Mount FS

if

(

f_mount

(

&

SDFat

,

SD_Path

,

0

))

{

 

HAL_Delay

(

1000

)

;

 

NVIC_SystemReset

()

;

}

if

(

f_stat

(

filename

,

NULL

))

{

 

//Go to user app

 

FATFS_UnLinkDriver

(

SD_Path

)

;

 

RunApplication

()

;

}

FlashProtection

=

FLASH_If_GetWriteProtectionStatus

()

;

HAL_GPIO_WritePin

(

LD2_GPIO_Port

,

LD2_Pin

,

GPIO_PIN_RESET

)

;

COMMAND_DOWNLOAD

(

&

FirFile

,

filename

)

;

HAL_GPIO_WritePin

(

LD2_GPIO_Port

,

LD2_Pin

,

GPIO_PIN_SET

)

;

f_close

(

&

FirFile

)

;

f_unlink

(

filename

)

;

NVIC_SystemReset

()

;

It's not bulletproof but works fine so far for my prototyping. RunApplication() is defined as follows:

void

RunApplication

(

void

)

{

 

/* Test if user code is programmed starting from address 'APPLICATION_ADDRESS' */

 

if

(((

*

(

__IO

uint32_t

*

)

APPLICATION_ADDRESS

)

&

0x2FFE0000

)

==

0x20000000

)

 

{

   

/* Jump to user application */

    JumpAddress

=

*

(

__IO

uint32_t

*

)

(

APPLICATION_ADDRESS

+

4

)

;

    JumpToApplication

=

(

pFunction

)

JumpAddress

;

   

/* Initialize user application's Stack Pointer */

#if

  (defined ( __GNUC__ ))

   

/* Compensation as the Stack Pointer is placed at the very end of RAM */

   

__set_MSP

((

*

(

__IO

uint32_t

*

)

APPLICATION_ADDRESS

)

-

64

)

;

#else

 

/* (defined  (__GNUC__ )) */

    __set_MSP

(

*

(

__IO uint32_t

*

)

APPLICATION_ADDRESS

)

;

#endif

/* (defined  (__GNUC__ )) */

    JumpToApplication

()

;

 

}

 

else

 

{

HAL_GPIO_WritePin

(

LD1_GPIO_Port

,

LD1_Pin

,

GPIO_PIN_RESET

)

;

HAL_Delay

(

5000

)

;

   

NVIC_SystemReset

()

;

 

}

}

You gonna have different offsets. Lastly compile whole thing the code should take around 16kb with optimization for size. Adding USB MSC stack in my case increased code size to 30kb still fits 32kb codespace:D

Posted on March 17, 2017 at 17:07

I pulled all the source files into a directory, and used GNU/GCC with a makefile and linker script. Did for an F1 part, should be able to replicate for an F7

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..