Postionning functions adresses

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

Postionning functions adresses

#1 Post by orpheedulogis » 31 Jan 2023 11:20

Hi,

A "simple" question.
I'm using bootloader example
I want to write some functions in "bootloader" and some other in "program" , but is there a method to tell one function is in s specific flash area or did I have to use "org" for each one (so looking the binary code to see emply areas) ?
#define BOOTLOADER_START_ADDR 0xC0
#define START_PROGRAM_ADDR 0x1800
#define FLASH_SIZE_STM32F051K6U6 16000

//------------------------------------------------------------------------------
void Fct_boot()
{

}

//------------------------------------------------------------------------------

void Fct_Program()
{

}

//------------------------------------------------------------------------------

void Start_Program() org START_PROGRAM_ADDR
{
SetInterrupts();
Soft_I2C_Init();
delay_ms(10);

while(1)
{
Led_Green_Reverse
delay_ms(500);
}

}

//------------------------------------------------------------------------------

void main() org BOOTLOADER_START_ADDR
{
// Main program
SetIOs();
Led_Red
UART1_Init(9600);
Delay_100ms();

if (UART1_Write_Loop('g','r'))
{
Start_Bootload();
}
else
{
Start_Program();
}
}

//------------------------------------------------------------------------------
I tried following code and it seem working but perhaps not a good solution. "x1=0" so "Fct_boot" will not called but is included in boot area (if I write "if(0)Fct_boot;" the compiler will not write Fct_boot in flash)
//------------------------------------------------------------------------------

void main() org BOOTLOADER_START_ADDR
{
char x1=0;
SetIOs();
Led_Red
UART1_Init(9600);
Delay_100ms();

if(x1)Fct_boot;
if (0) //UART1_Write_Loop('g','r'))
{
Start_Bootload();
}
else
{
Start_Program();
}
}

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

Re: Postionning functions adresses

#2 Post by orpheedulogis » 01 Feb 2023 09:25

Is there really a solution ?
Of course the problem is that, if I can't modify the Start_Program without increasing bootloader size, it will be completely useless.

Code: Select all

#define BOOTLOADER_START_ADDR   0x00C0 
#define START_PROGRAM_ADDR      0x0600
...

void Start_Program() org START_PROGRAM_ADDR
{
    char x1;
    
    strcpy(Chaine,"EFAB");
    x1++;
    
    while(1)
    {

        delay_ms(250);
//P_Led1=0;
    }

}

void main() org BOOTLOADER_START_ADDR 
{
   char x1=1;

   strcpy(Chaine,"ABCD");
   x1++;
  Start_Program();
}
Image

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

Re: Postionning functions adresses

#3 Post by orpheedulogis » 02 Feb 2023 10:14

Did someone can answer to this ?

I resume:
Main boot loader area:

Code: Select all

void main() org BOOTLOADER_START_ADDR 
{
   char TestStr[10];
   strcpy(TestStr,"ABCD");
   Start_Program1();
   Start_Program2();
}
Here, of course, I can see "ABCD" when reading code with Mikroprog.

But, about "Program1" and "Program2" ( "void Start_Program1()" org 0x400 or "void Start_Program2() org 0x600 )
with this same code

Code: Select all

{
    char TestStr[10]; 
    strcpy(TestStr,"EFAB");  
    while(1)
    {
        delay_ms(250);
    }
}
I can see "EFAB" datas in bootloader area, not in Program1 or Program2 area . Program1 and Program2 have the same content reading code but not "EFAB" data at all.

Please explain me what I can do, this because it means my bootloader will have is size increased .

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Postionning functions adresses

#4 Post by AntiMember » 02 Feb 2023 13:58

#pragma orgall .......
OR
#pragma makesection(ROM_SPACE, ......)
Read about in help->Linker Directives

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

Re: Postionning functions adresses

#5 Post by orpheedulogis » 02 Feb 2023 14:18

Thanks a lot for your anwer.

But I don't understand exactly what to do.
Actually I have this

Code: Select all

//#pragma orgall 0x00C0  
#define BOOTLOADER_START_ADDR   0x00C0 
#define START_PROGRAM_ADDR      0x0600
#define START_PROGRAM_ADDR2     0x0800
As you can see, I put comment to "pragma orgall" because it doesn't change anything.
is 'org adressxxx" not enough to fix adress from procedure area ?
Please send me a simple example so I didn't see datas from other areas moving to bootloader area.

Here is my code now:

Code: Select all



//------------------------------------------------------------------------------
#include <built_in.h>
//------------------------------------------------------------------------------
#define BOOTLOADER_START_ADDR    0x00C0 
#define START_PROGRAM_ADDR1      0x0500
#define START_PROGRAM_ADDR2      0x0600
#define ROM_SPACE_SECTION __attribute__((section("ROM_PROG1")))
#pragma makesection(ROM_PROG1, 0x700, 2048, CODE)

//------------------------------------------------------------------------------

ROM_SPACE_SECTION void Program3()
{
    char StrX[10];
    strcpy(StrX,"DDDD");
    while(1)
    {
        delay_ms(250);
    }
}

//------------------------------------------------------------------------------

void Program2() org START_PROGRAM_ADDR1
{
    char x1=8;
    char StrX[10];
    strcpy(StrX,"CCCC");
    x1=4;
    
    while(1)
    {
        delay_ms(250);
    }
}

//------------------------------------------------------------------------------
//#pragma section("program2_section")
void Program1() org START_PROGRAM_ADDR2
{
    char x1=3;
    char StrX[10];

    strcpy(StrX,"BBBB");
    x1=6;

    while(1)
    {
        delay_ms(250);
    }
}

//------------------------------------------------------------------------------

void main() org BOOTLOADER_START_ADDR
{
   char x1=1;
   char StrX[10];

   x1=0;
   strcpy(StrX,"AAAA");

   Program1();
   Program2();
   Program3();
}
//------------------------------------------------------------------------------
It does excatly the same thing: AAAA,BBBB,CCCC,DDDD are in the same bootloader area.

Image
Last edited by orpheedulogis on 03 Feb 2023 10:01, edited 1 time in total.

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Postionning functions adresses

#6 Post by AntiMember » 02 Feb 2023 22:52

I had to install mikroc...
And the same thing happened...

AntiMember
Posts: 136
Joined: 02 Jan 2020 19:00

Re: Postionning functions adresses

#7 Post by AntiMember » 03 Feb 2023 08:16

It puts only the values of the variables in one place.

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

Re: Postionning functions adresses

#8 Post by orpheedulogis » 03 Feb 2023 09:57

So ... would it be a mikroe (big) bug ? no solution ? because I will have many many datas in my "prog" area so it would be unusuable, I would have to re-write in other langage/compiler

Post Reply

Return to “mikroC PRO for ARM General”