cancel
Showing results for 
Search instead for 
Did you mean: 

Execute code in CCM SRAM failure (IAR, STM32G474)

YWang.15
Associate II

Hello,

I wanted to put some complicated calculation into CCM SRAM in my STM32G474RE MCU. I basically followed instructions of AN4296, unfortunately I found an issue when programming the MCU.

A few attaches as below:

1. The link script

YWang15_0-1698216341612.png

2. The code change

YWang15_3-1698216549128.png

 

3. The error reported 

The updated code can compile and link successfully, but I just report an error when click "Download and Debug" button

YWang15_2-1698216444813.png

4. The map file

YWang15_4-1698216581002.png

As the map file indicated, the link successfully put the function into CCM SRAM.

 

Any help would be greatly appreciated.

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hello @YWang.15 

Here is an example project.

I hope this helps.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

8 REPLIES 8
FBL
ST Employee

Hello @YWang.15 

 

It seems there is an issue linked to generation of flash loader input. Are you executing interrupt handler?

It is possible that the issue is linked to data structure being defined SUD_t.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

The code is not executed in interrupt handler.  Code snippet for SUD and its instance as below

SUD_Info_t SUD_Info = {
    .shunt_resistor = 0.01f,   
    .vbus = 24.0f,     
};

SUD_Data_t SUD_Data = 
{
    .state_machine = SUD_SM_IDLE,
    .status = 0,
};

SUD_t const SUD_Instance = {
    .info = &SUD_Info,
    .data = &SUD_Data,
};
typedef struct str_SUD_t{
    SUD_Info_t *info;
    SUD_Data_t *data;
}SUD_t;

 Is it caused by the "SUD_Instance"? since it is a constant variable that shall be initialized(copied)to CCM SRAM as well?

Toneski
Associate II

Hi,

Just a thought here:-

If your CPU is anything like the F407 (it looks like your CPU is in the same family), then code can't run from the CCM - the CCM is only connected to the Data databus (as in can only access the CCM as a data address - not an execution address).. 

Just a thought...

Tone

 

Pavel A.
Evangelist III

From the error message it looks like the IAR debugger tries to "flash" the stuff in the .ccmram section. Of course this won't work. Data and code in internal RAMs should be placed in the flash image and initialized by the app startup by copying from the flash image.

Your link script contains "initialize by copy {readwrite, section .cmram}" - but this does not have the desired effect. Check the IAR fine manual for correct syntax?

FBL
ST Employee

Hello @YWang.15 

Here is an example project.

I hope this helps.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Pavel A.
Evangelist III

The icf file in that example looks same as in the OP (what concerns the ccmram)

 

Indeed, it works as mentioned in the application note. .ccmram section should be initialized by copy at startup since the code is located in an internal CCM SRAM.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

YWang.15
Associate II

Hi All,

I am sorry I was OOO last couple of days. I tried the code from F.Belaid. It worked well with my nucleoG4 board. I even did some further modifications, and it still worked as expected. This means that there must be something wrong with my previous code. I need to set back and review that code again.

typedef struct {
    uint32_t time;
    GPIO_TypeDef *port;
    uint16_t pin;
}toggle_info_t;

const toggle_info_t player = {
    .time = 200u,
    .port = LD2_GPIO_Port,
    .pin = LD2_Pin,
};
#pragma location=".ccmram"
void toggle_led(toggle_info_t const *t)
{
    HAL_GPIO_TogglePin(t->port, t->pin);
    HAL_Delay(t->time);
}