STM32F051 firmware update

General discussion on mikroBasic PRO for ARM.
Post Reply
Author
Message
orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

STM32F051 firmware update

#1 Post by orpheedulogis » 20 Apr 2023 08:26

Hi,

MikroBootloader example works (I can see the downloaded soft working) if I use those adresses:

Code: Select all

#define AdresseBase 0x6C00
#define INIT_PROGRAM_ADRESS 0x7C00
#define START_PROGRAM_ADDR 0x300
And

Code: Select all

if ((Adresse < START_PROGRAM_ADDR)FLASH_EraseWritePage(Adresse);
But, I tried to change adresses to

Code: Select all

#define AdresseBase 0x200
#define INIT_PROGRAM_ADRESS 0x1500
#define START_PROGRAM_ADDR 0x1600
Using

Code: Select all

if ((Adresse >= START_PROGRAM_ADDR) && (Adresse<INIT_PROGRAM_ADRESS))    FLASH_EraseWritePage(Adresse);
And, here, nothing happen anymore.
Did this mean assembler codes has to be changed ? (I suppose)

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: STM32F051 firmware update

#2 Post by orpheedulogis » 21 Apr 2023 08:24

Here the code for vectors

Code: Select all

void Write_Begin()
{
    signed char Sens;
    unsigned int i;
    unsigned long* ptr;
    unsigned char appResetVector[16];
    unsigned long arm_m0_inst;
    unsigned int dataToWrite;


    switch(BOOTLOADER_START_ADDR)
    {
        case 0x5C00:
        Sens=1;
        break;
        
        case 0x300:
        Sens=-1;
        break;
    }

    //LDR R0, PC-X
    arm_m0_inst = 0x4800 + Sens;
    appResetVector[0] = arm_m0_inst;
    appResetVector[1] = arm_m0_inst >> 8;

    //MOV SP, R0    arm_m
    arm_m0_inst = 0x4685;
    appResetVector[2] = arm_m0_inst;
    appResetVector[3] = arm_m0_inst >> 8;

    //LDR R0, PC-Y
    arm_m0_inst = 0x4800 + Sens;
    appResetVector[4] = arm_m0_inst;
    appResetVector[5] = arm_m0_inst >> 8;

    //BX R0
    arm_m0_inst = 0x4700;
    appResetVector[6] = arm_m0_inst;
    appResetVector[7] = arm_m0_inst >> 8;

    //SP
    appResetVector[8] = block[0];
    appResetVector[9] = block[1];
    appResetVector[10] = block[2];
    appResetVector[11] = block[3];

    //PC
    appResetVector[12] = block[4];
    appResetVector[13] = block[5];
    appResetVector[14] = block[6];
    appResetVector[15] = block[7];
    FLASH_Unlock();
    FLASH_ErasePage(INIT_PROGRAM_ADRESS);

    for (i = 0; i < 8; i++)
    {
        dataToWrite = appResetVector[i * 2] | (appResetVector[i * 2 + 1] << 8);
        FLASH_Write_HalfWord(INIT_PROGRAM_ADRESS + i*2, dataToWrite);
    }
    FLASH_Lock();
    
    ptr = (unsigned long*)0x00000000;
    block[0] = LoWord(*ptr);
    block[1] = LoWord(*ptr) >> 8;
    block[2] = HiWord(*ptr);
    block[3] = HiWord(*ptr) >> 8;

    ptr++;

    block[4] = LoWord(*ptr);
    block[5] = LoWord(*ptr) >> 8;
    block[6] = HiWord(*ptr);
    block[7] = HiWord(*ptr) >> 8;
}

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: STM32F051 firmware update

#3 Post by orpheedulogis » 21 Apr 2023 10:29

I thinks my problem is about this : I have to set SP to 0x08003FFF (maximum adress value).
How can I do this ?

orpheedulogis
Posts: 240
Joined: 16 Jan 2010 22:26

Re: STM32F051 firmware update

#4 Post by orpheedulogis » 21 Apr 2023 11:08

And it works: need to add this line at main

Code: Select all

asm{LDR R0, =0x08003FFF; MOV SP,R0}

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: STM32F051 firmware update

#5 Post by filip » 28 Apr 2023 10:00

Hi,

Have you got this working ?

Regards,
Filip.

Post Reply

Return to “mikroBasic PRO for ARM General”