cancel
Showing results for 
Search instead for 
Did you mean: 

How to put a const array at 0x600 address

Zhang Lei
Associate II
Posted on October 25, 2017 at 05:21

I want to put the boot_loader_version of 'const unsigned char boot_loader_version[3]={1,0,0};' at 0x600 of code flash, so the application can read it. How could I do it?

7 REPLIES 7
Erwan YVIN
ST Employee
Posted on October 26, 2017 at 10:47

Hello Zhang ,

you shouldadd your sections in your linker files

SECTIONS
{
 . = ORIGIN(flash);
 .boot0 : ALIGN(16) SUBALIGN(16)
 {
 . += 0x00000000;
 KEEP(*(.boot))
 KEEP(*(.handlers))
 KEEP(*(.crt0))
 } > flash
 .boot1 : ALIGN(16) SUBALIGN(16)
 {
 /* The vectors table requires a 2kB alignment.*/
 . = ALIGN(0x800);
 KEEP(*(.vectors))
 /* The IVPR register requires a 4kB alignment.*/
 . = ALIGN(0x1000);
 __ivpr_base__ = .;
 KEEP(*(.ivors))
 } > flash
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

and

__attribute__ ((section ('.bootloadersection'))) const unsigned char boot_loader_version[3]={1,0,0};�?

you can try this 😉

Best Regards

Erwan

Posted on June 12, 2018 at 03:15

Hello Erwan:

   I have the similar question,but the difference is  I want to put the function at the permanent address,so that I can jump to it from the application program? what should I do ?Thanks.

Posted on June 12, 2018 at 08:56

Hello Wang ,

you should create a section located in 0x600 in user.ld.

and use __attribute__ in the function prototype.

There is a nice article about that

https://www.silabs.com/community/mcu/32-bit/knowledge-base.entry.html/2016/03/07/using_a_linker_scrip-s5bu

 

     Best Regards

                        Erwan

Posted on June 12, 2018 at 09:40

Hello Erwan:

Appreciate for your reply,I have tired the way that you suggested above, and I have seen the FUNC is already at the address where I put in the UDE. But I have problem with the jump, after the jump code is implement, the FUNC at the loadaddress(0x8000) does't run. Here is the my code ,could you help me to find the problem?

//**********************************************************************************

__attribute__ (( __section__ ('loadaddress'))) void Bootloader(void)

{

componentsInit();

/* Enable Interrupts */

irqIsrEnable();

Flash_Init();

mCanDrv_Init();

while(1){

// Process CAN driver

mCan_Drv_Process();

// Manage programming operations

mPrgm_Process();

pal_lld_togglepad(PORT_A,PIN_TEST);

}

}

MEMORY

{

flash : org = 0x00000000, len = 384k

dataflash : org = 0x00800000, len = 64k

ram : org = 0x40000000, len = 36k

bootload : org = 0x00008000, len = 1k

}

ENTRY(_reset_address)

/*

* Derived constants.

*/

__bootload_size__ = LENGTH(bootload);

__bootload_start__ = ORIGIN(bootload);

__bootload_end__ = ORIGIN(bootload) + LENGTH(bootload);

loadaddress : ALIGN(4) SUBALIGN(4)

{

PROVIDE(__loadaddress_start = .);

KEEP(*(.loadaddress))

KEEP(*(SORT(.loadaddress.*)))

PROVIDE(__loadaddress_end = .);

} > bootload

SPCSetPeripheralClockMode(SPC5_PIT_PCTL, SPC5_PIT_STOP_PCTL);

irqIsrDisable();

ME.DRUN.R = (0UL | SPC5_ME_MC_MVRON | SPC5_ME_MC_DFLAON_NORMAL | SPC5_ME_MC_CFLAON_NORMAL | SPC5_ME_MC_IRCON | SPC5_ME_MC_SYSCLK_IRC);

if (SPCSetRunMode(SPC5_RUNMODE_DRUN) == CLOCK_FAILED) {

SPC5_CLOCK_FAILURE_HOOK();

}

(*(APPFn)(CVECT_BOOT_ISPOS))();//&sharpdefine CVECT_BOOT_ISPOS 0x8000

__attribute__ (( __section__ ('loadaddress'))) void Bootloader(void)// @ CVECT_BOOT_ISPOS

{

0x00008000: 18 21 06 F8 E_STWU R1,-0x8(R1)

0x00008004: 00 80 SE_MFLR R0

0x00008006: D3 01 SE_STW R0,0xC(R1)
  1. componentsInit();

    0x00008008: 79 FF DC 49 E_BL componentsInit (0x00005C50)
Posted on June 12, 2018 at 10:53

Hello Wang,

Your linker is strange

there is a conflict between

flash : org = 0x00000000, len = 384k <==> bootload : org = 0x00008000, len = 1k

You have to be sure that flash and bootloader sections are not in conflict.

To analyze a crash , you have to checked R14 and PC

          Best regards

                   Erwan

Posted on June 12, 2018 at 11:23

Hello Erwan:

      I have changed it like below, but  it does not  work, and I am confused about the flash and the bootload section, the flash size should be the whole program size , and the  FUNC is located in the program, so I supposed the booload section should not be loacted beyond the flash size boundary, it seems not right. and how to check R14??  Thanks!

MEMORY

{

flash : org = 0x00000000, len = 48k

dataflash : org = 0x00800000, len = 64k

ram : org = 0x40000000, len = 36k

bootload(rwx) : org = 0x00008000, len = 0x40

}
Posted on June 13, 2018 at 06:02

Hello Erwan?

   I checked the PC pointer?and found that when I jumped from application program to bootloader FUNC which been located at 0x8000?the PC pointer was missing at the init FUNC? and I press the ?break? button ?the PC was always at the 0x00000C14?which is the vector address?but the R14 is always 0x00000000?the init FUNC is library function. Why could this happen?

0690X0000060LAFQA2.png