2020-04-20 01:59 AM
Hello, everyone!
I am a user of STM32H753. I want to run two programs within STM32H753 and exchange the values of the variables between these two programs. (Program 1 is running on Flash memory bank 1 sector 0; Program 2 is running on Flash memory bank 2 sector 0.)
For reference, I use STM32CubeIDE 1.3.0 as a compile tool.
In the past, when IAR was used, two variables in the program were placed in the same address in the noinit area, and after changing the compilation tool to STM32CubeIDE, I do not know what to do.
What is the way to exchange variables between the two programs?
Solved! Go to Solution.
2020-04-20 02:35 AM
It would be possible to create a noinit section analogous to IAR, but the ordering of variables within a section can't be guaranteed.
So, my STM32H743IITX_FLASH.ld contains the following memory definitions
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
RAM_BACKUP (xrw) : ORIGIN = 0x38800000, LENGTH = 4K
}
I would place a struct not exceeding 1024 bytes at the end of RAM_D1, so I adjust that line
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 511K
Then I can declare my struct as
struct common_vars {
int a, b, c;
// ...
} *common_area = (void*)(0x24000000 + 511*1024);
and access values through common_area->a etc
2020-04-20 02:35 AM
It would be possible to create a noinit section analogous to IAR, but the ordering of variables within a section can't be guaranteed.
So, my STM32H743IITX_FLASH.ld contains the following memory definitions
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 2048K
RAM_BACKUP (xrw) : ORIGIN = 0x38800000, LENGTH = 4K
}
I would place a struct not exceeding 1024 bytes at the end of RAM_D1, so I adjust that line
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 511K
Then I can declare my struct as
struct common_vars {
int a, b, c;
// ...
} *common_area = (void*)(0x24000000 + 511*1024);
and access values through common_area->a etc
2020-04-20 06:49 PM
@berendi
Thank you, berendi.
I tried as you said, and my code uttered an error.
For reference, I placed the structure in DTCMRAM.
Next is my .ld file.
MEMORY
{
DTCMRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 127K
ITCMRAM (xrw) : ORIGIN = 0x00000000, LENGTH = 64K
RAM_D1 (xrw) : ORIGIN = 0x24000000, LENGTH = 512K
RAM_D2 (xrw) : ORIGIN = 0x30000000, LENGTH = 288K
RAM_D3 (xrw) : ORIGIN = 0x38000000, LENGTH = 64K
FLASH (rx) : ORIGIN = 0x8100000, LENGTH = 2048K
}
I also made the structure as follows.
struct common_vars {
uint8_t a;
uint8_t b;
uint8_t c;
uint16_t d;
} *common_area = (void*)(0x20000000 + 127*1024);
This is an error message that occurred to me.
I don’t know what’s wrong with you. Do you know what’s wrong?
2020-04-20 07:38 PM
Where did you define it? In an include file you pull into every file?
Perhaps you need it to be an extern and define the value once.
2020-04-20 09:01 PM
@Community member
I defined a structure in a single header file.
This header file is included in several .c files that require this header file among the source files in the project.
I think it's a matter of redefinition every time it's included, but I don't know how to solve it.
2020-04-20 11:06 PM
Separate the type declaration, variable declaration, and variable definition, as you would with any other variable that is used in more than one compilation unit.
2020-04-20 11:22 PM
@berendi
If you don't mind, can you give me an example?
2020-04-20 11:25 PM
type definition:
struct common_vars {
int a, b, c;
// ...
};
variable declaration:
extern struct common_vars *common_area;
The above goes into a header file. The variable definition goes into a .c source:
struct common_vars *common_area = (void*)(0x20000000 + 127*1024);
2020-04-20 11:53 PM
Thank you, berendi!!
Thanks to this, I was able to confirm that my program was working normally.