cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to declare in the CCM memory a structure?

jean_prieur
Associate III
Posted on January 28, 2016 at 17:56

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
8 REPLIES 8
Posted on January 28, 2016 at 18:41

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'')));

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
carl2399
Associate II
Posted on January 29, 2016 at 10:25

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.

jean_prieur
Associate III
Posted on January 29, 2016 at 12:42

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?

jean_prieur
Associate III
Posted on January 29, 2016 at 12:54

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]

carl2399
Associate II
Posted on January 30, 2016 at 00:54

You still do not understand. I'll add some more lines to hopefully make it clear.

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

));   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

re.wolff9
Senior
Posted on January 31, 2016 at 14:18

  •  Ok... If I understand this method will declare in the CCM memory only the structure, not all the variables declared in the structure.
 A structure consists of nothing BUT ''all the variables in the structure''. A structure is a way for the programmer to group a set of variables, making it easier to declare/use that ''group of variables'' in different places in your program.

So if you do:

int somevariable __attribute__ ((section(''.ccm'')));

the variable will go into CCM.

just like

struct somestruct somestructname __attribute__ ((section(''.ccm'')));

will place the variables grouped and named as ''somestructname'' all in CCM.

From: prieur.jean

Posted: Friday, January 29, 2016 12:42 PM

Subject: Is it possible to declare in the CCM memory a structure?

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?

From: CJacobs

Posted: Friday, January 29, 2016 10:28 AM

Subject: Is it possible to declare in the CCM memory a structure?

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.

From: prieur.jean

Posted: Thursday, January 28, 2016 5:56 PM

Subject: Is it possible to declare in the CCM memory a structure?

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...

         

jean_prieur
Associate III
Posted on February 01, 2016 at 18:10

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!
Posted on February 01, 2016 at 18:34

Is it possible to malloc into the CCM?

Of course, put your heap there, or code your allocater appropriately.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Locate%20Heap%20in%20SDRAM&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=349

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/32F429IDISCOVERY%20RAM%20extension&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=145

[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&currentviews=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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..