How to exchange variable values in two programs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 1: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.
- Labels:
-
STM32CubeIDE
-
STM32H7 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 2:35 AM
- Define one common struct that holds all variables. Find out its size in bytes.
- Decide which memory are (DTCM/D1/D2/D3) should hold the values.
- Find the corresponding memory definition line in the *.ld file, decrease LENGTH to free up some memory space to accomodate the variables.
- Declare a pointer to the common struct type, pointing to the area feed up in step 3, i.e. to ORIGIN+LENGTH
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 2:35 AM
- Define one common struct that holds all variables. Find out its size in bytes.
- Decide which memory are (DTCM/D1/D2/D3) should hold the values.
- Find the corresponding memory definition line in the *.ld file, decrease LENGTH to free up some memory space to accomodate the variables.
- Declare a pointer to the common struct type, pointing to the area feed up in step 3, i.e. to ORIGIN+LENGTH
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 6: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 7: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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 9: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 11:22 PM
@berendi
If you don't mind, can you give me an example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2020-04-20 11:53 PM
Thank you, berendi!!
Thanks to this, I was able to confirm that my program was working normally.
