2016-01-28 08:56 AM
Hello everybody,
I often declare my variables in the CCM memory, very useful as I use a lot of RAM memory. For example I can declare this variable:static
uint8_t VARIABLE __attribute__ ((section(
''.ccm''
)));
Is it possible to declare a structure like this in the CCM:
struct
Pyramid_Core {
uint8_t VARIABLE1;
bool_t VARIABLE2;
A_typedef_enum VARIABLE3;
A_pointer* VARIABLE4;
uint16_t VARIABLE6;
uint64_t VARIABLE7;
};
Thanks a lot for your help! It will help to save a lot of RAM memory, my structure handles a lot of variables...
#understand-your-tools
2016-01-28 09:41 AM
I'd attack it like this
typedef struct _PYRAMID_CORE {
uint8_t VARIABLE1;
bool_t VARIABLE2;
A_typedef_enum VARIABLE3;
A_pointer* VARIABLE4;
uint16_t VARIABLE6;
uint64_t VARIABLE7;
} PYRAMID_CORE;
static PYRAMID_CORE Pyramid_Core __attribute__ ((section(''.ccm'')));
But I'd expect this would also work, I just prefer using typedefs as there's no reason to clutter code with struct
struct Pyramid_Core {
uint8_t VARIABLE1;
bool_t VARIABLE2;
A_typedef_enum VARIABLE3;
A_pointer* VARIABLE4;
uint16_t VARIABLE6;
uint64_t VARIABLE7;
} __attribute__ ((section(''.ccm'')));
2016-01-29 01:25 AM
You're on the right path. Just remember, you're not trying to put the structure definition in to CCM memory, just an instance of the structure. So as Clyde has indicated the
__attribute__
is marking the variable (and not how it's defined).
This is different to__attribute__
((packed)) which does mark the structure as packed - where-ever it's used.2016-01-29 03:42 AM
Ok... If I understand this method will declare in the CCM memory only the structure, not all the variables declared in the structure.
My goal is to declare in the CCM all the variable in the structure. Maybe it's not possible?2016-01-29 03:54 AM
I tested that:
typedef
struct
Pyramid_Core Pyramid_Core;
struct
Pyramid_Core {
uint8_t VARIABLE1;
bool_t VARIABLE2;
A_typedef_enum VARIABLE3;
A_pointer* VARIABLE4;
uint16_t VARIABLE6;
uint64_t VARIABLE7;
} __attribute__ ((section(
''.ccm''
)));
I have this error from my compiler:
[cc] C:\Users\Jean\Desktop\PYRAMID CODE\src\User_Program\Core/Pyramid_Core.h:408:1: warning:
'section'
attribute does not apply to types [-Wattributes]
2016-01-29 03:54 PM
You still do not understand. I'll add some more lines to hopefully make it clear.
typedef
structPyramid_Core Pyramid_Core;
structPyramid_Core {
uint8_t VARIABLE1; bool_t VARIABLE2; A_typedef_enum VARIABLE3; A_pointer* VARIABLE4; uint16_t VARIABLE6; uint64_t VARIABLE7; } __attribute__ ((packed)); Pyramid_Core VarInSRAM; Pyramid_Core VarInCCM __attribute__ ((section(
''.ccm'' ))); constPyramid_Core VarInFLASH = { etc };The ''packed'' attribute is applied to the structure (this is not required, but included to show the difference), the ''section'' attribute is applied to the variable. VarInSRAM is a packed structure located in the processor (non-CCM) SRAM. VarInCCM is a packed strcture located in the CCM memory (because of the section attribute). VarInFLASH is a packed structure located in FLASH memory (because of the const keyword). In each case (!!) space for the whole structure is allocated. VarInSRAM.VARIABLE1 = VarInCCM.VARIABLE1; // Copy from CCM to SRAM VarInCCM.VARIABLE1 = VarInFLASH.VARIABLE1; // Copy from FLASH to CCM
2016-01-31 05:18 AM
2016-02-01 09:10 AM
Hello everybody,
Thanks for these explanations! Now it's working, I have no error. But I'm not sure that my packed structure will go in the CCM, as I do a malloc. I coded it:typedef
struct
Pyramid_Core Pyramid_Core;
struct
Pyramid_Core {
uint8_t VARIABLE1;
bool_t VARIABLE2;
A_typedef_enum VARIABLE3;
A_pointer* VARIABLE4;
uint16_t VARIABLE6;
uint64_t VARIABLE7;
} __attribute__ ((packed));
static
Pyramid_Core *Pyramid_Core_P __attribute__ ((section(
''.ccm''
)));
Now, to allocate the size of the structure, I have to do a malloc.
void
Create_Pyramid_Core(
void
)
{
Pyramid_Core *core = pvPortMalloc(
sizeof
(*core));
Pyramid_Core_P = core;
What do you think about it? Is it possible to malloc into the CCM?
Thanks a lot!
2016-02-01 09:34 AM
Is it possible to malloc into the CCM?
Of course, put your heap there, or code your allocater appropriately. [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20extending%20the%20heap%20to%20seperate%20RAM%20regions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=54]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/STM32F4%20extending%20the%20heap%20to%20seperate%20RAM%20regions&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=54