2021-02-03 11:04 PM
Hi
I'm using a STM32H753 with external SDRAM connected to FMC.
I'm working with Keil and the compiler is armclang.
This is my MPU configuration for the SDRAM (base address is 0xC0000000) :
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = 0xC0000000;
MPU_InitStruct.Size = MPU_REGION_SIZE_64MB;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_NOT_SHAREABLE;
MPU_InitStruct.Number = MPU_REGION_NUMBER0;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL1;
MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_DISABLE;
This code initializes the MPU so that the SDRAM memory area is considered as Normal Memory type instead of Device Memory type. This disables the access alignment restrictions.
When I use memcpy with following code, everything is copied correctly:
volatile uint32_t len = 10;
uint8_t* src = (uint8_t*)0xc0000002; // 2-byte aligned
uint8_t* dst = (uint8_t*)(0xc0000002 + 20); // 2-byte aligned
memcpy(dst, src, len); // ok
But with following addresses (src 2byte aligned and dst 4byte aligned):
src = (uint8_t*)0xC0000002; // 2-byte aligned
dst = (uint8_t*)(0xC0000002 + 22); // 4-byte aligned
memcpy(dst, src, len);
This is the result of the memory after memcpy:
Memcpy does not have any problems when using internal RAM.
Is this a bug in memcpy? Is my MPU configuration wrong?
Please advise.
Thanks a lot.
/jimmii
2021-02-04 01:41 AM
And what happens if you memcpy first from SDRAM offset 0x02 to internal RAM, and the from internal RAM to SDRAM offset 0x18?
JW
2021-02-04 02:40 AM
Hi @Community member
Thanks. When I'm copying from external to internal RAM and then back to external everything is ok. Data is correct.
Do you have any assumptions?
/jimmii
2021-02-04 04:48 AM
No ideas.
You may want to contact ST directly, through FAE or the web support form.
JW
2021-02-04 04:53 AM
Thanks anyway.