Hello,
in our project we are extensively using SDRAM memory. Recently we encounter a problem when using designated initializers of a struct members, when the struct itself is located in SDRAM.
The sample code is below:
typedef struct {
uint16_t array[5];
} tsArray;
typedef struct {
tsArray var;
} tsVar;
__attribute__((far)) volatile tsVar Global;
void main(void)
{
//System init & SDRAM initialization is here
//struct members initialization uses PREAD instruction & causing crash in some cases:
Global.var = (tsArray) { .array = {0, 1, 2, 3, 4} };
//manual struct initialization not using PREAD:
uint16_t i;
for (i=0; i<5; i++)
Global.var.array[i] = i;
while(1)
{ }
}
The designated initialization is using PREAD instruction, which I belive is forbidden for far SDRAM variables - according to this application note:
https://www.ti.com/lit/an/spraby4/spraby4.pdf
In our case the struct is very large and the code crashes at the struct members initialization. Then we inspected the generated assembly and saw the PREAD instructions.
Is this a compiler bug?
Best regards,
Andy
