cancel
Showing results for 
Search instead for 
Did you mean: 

How to declare a struct in CCM

jean
Senior
Posted on December 22, 2016 at 18:10

Hello,

I work on a STM32F4 and I want use the CCM memory to declare my structures.

For example I want this kind of structure to be always declared in the CCM memory:

typedef struct Assign_Pot Assign_Pot;

struct Assign_Pot {

uint8_t variable1;

uint8_t variable2;

uint16_t variable3;

};

Assign_Pot* Assign_Tab[100];

I've been looking across the forum but I can't find a solution that works.

If I declare my structure like this:

struct Assign_Pot {

uint8_t variable1;

uint8_t variable2;

uint16_t variable3;

} __attribute__ ((section('.ccm')));

I have the warning: 'section' attribute does not apply to types [-Wattributes]

And the structure is not created in the CCM

Do you have some experience to share with this problem?

Thanks a lot, have a great day!

Note: this post was migrated and contained many threaded conversations, some content may be missing.
12 REPLIES 12
Posted on December 23, 2016 at 16:43

Ok, but that is an array of pointers, not the data struct itself. You can't apply the attribute to the struct definition/typedef, just the static allocation.

How are you allocating the addresses you are stuffing in the pointers? malloc()?

You'd need to put the heap into the CCM for the allocator to pull from there, or modify the allocator to pull from multiple memory arenas.

typedef struct _Assign_Pot {
 uint8_t variable1;
 uint8_t variable2;
 uint16_t variable3;
} Assign_Pot;
 
Assign_Pot Assign_Element[1000] __attribute__ ((section('.ccm')));
Assign_Pot* Assign_Tab[100] __attribute__ ((section('.ccm')));
Assign_Tab[12] = &Assign_Element[123];�?�?�?�?�?�?�?�?�?�?�?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 23, 2016 at 18:09

I do not use any malloc, I just declare a table of structures as aglobal variable:

Assign_Pot* Assign_Tab[100];

This declaration should create a hundred of myAssign_Pot structure in .data, isn't it?

Sorry, I do not understand yourcode:

Assign_Pot Assign_Element[1000] __attribute__ ((section('.ccm')));
Assign_Pot* Assign_Tab[100] __attribute__ ((section('.ccm')));
Assign_Tab[12] = &Assign_Element[123];

Posted on December 23, 2016 at 18:13

This declaration should create a hundred of myAssign_Pot structure in .data, isn't it?

No, I'd expect it to allocate 100 32-bit pointers. What does sizeof() suggest? ** Put a larger 'int buffer[16]' in the structure to make it clearly apparent.

My code allocates 1000 structures, and 100 pointers, and then assigns one of the pointers with the physical address of one of the structures.

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