2019-08-20 02:24 AM
I am experiencing an issue using STM32F469I-DISCOVERY board, Atollic TrueSTUDIO and STM32CUBEMX.
When writing to a memory address in SDRAM, let's say I'm writing 0xAA in memory address 0xC0000004, the data is not written to that address but instead it is written to 0xC0000000, which is 0xC0000004 - 4. Same for any other address in the SDRAM memory space, so writing one byte to 0xC000000C will affect the byte at address 0xC0000008. The writing address has an offset of -4 bytes, while the read operation (even the debugger read) seems to be correct.
Step to reproduce the issue:
{
int i;
unsigned char *pointerToSdram= (unsigned char *)0xC0000000;
// write a pattern to SDRAM one byte at a time
for (i = 0; i < 2000; i++)
{
HAL_SDRAM_Write_8b(&hsdram1, pointerToSdram, &i, 1);
pointerToSdram++;
}
// read the pattern
pointerToSdram= (unsigned char *)0xC0000000;
for (i = 0; i < 2000; i++)
{
uint8_t valueRead;
HAL_SDRAM_Read_8b(&hsdram1, pointerToSdram, &valueRead, 1);
if (valueRead != i )
{
int a;
a = 0; // wrong value!
}
else
{
int b;
b = 0; // OK
}
pointerToSdram++;
}
// retry using 32bit type
pointerToSdram= (unsigned char *)0xC0000000;
for (i = 0; i < 2000; i++)
{ // write to SDRAM using 4 bytes at a time
HAL_SDRAM_Write_32b(&hsdram1, pointerToSdram, &i, 1);
pointerToSdram = pointerToSdram + 4;
}
pointerToSdram= (unsigned char *)0xC0000000;
for (i = 0; i < 2000; i++)
{
uint8_t valueRead;
HAL_SDRAM_Read_32b(&hsdram1, pointerToSdram, &valueRead, 1);
if (valueRead != i )
{
int a;
a = 0; // wrong value!
}
else
{
int b;
b = 0; // OK
}
pointerToSdram = pointerToSdram + 4;
}
}
I am pretty much stuck, I tried to hack the initialization of the SDRAM in system_stm32f4xx.c (which the one contained in STM32CUBEMX is not completely correct, btw, since it is missing PC0 pin) without success.
Do you have any suggestions?