SDRAM - Read not working correctly on M4

Hi Arduino Guys,

There is an issue with reading the SDRAM on the M4 core.

with this slightly modified existing test code:

    memset(mem_base, 0, HW_SDRAM_SIZE);

    /* test all ram cells */
    if (!fast) {
        for (uint32_t i = 0; i < HW_SDRAM_SIZE; ++i) {
            mem_base[i] = pattern;
            printf("%p = %u\n", &mem_base[i], mem_base[i]);
            if (mem_base[i] != pattern) {
                printf("address bus test failed! address (%p)\n", &mem_base[i]);
                //__asm__ volatile ("BKPT");
            }
        }
    } else {
        memset(mem_base, pattern, HW_SDRAM_SIZE);
    }

We get:

0x6FMC_SDRAM_DEVICE->SDCMR: 0
initializing external ram
remap ram to 0x60000000
malloc_addblock: allocate 6852608 bytes
0x60000000 = 170
0x60000001 = 170
0x60000002 = 170
0x60000003 = 170
0x60000004 = 170
0x60000005 = 170
0x60000006 = 170
0x60000007 = 0
address bus test failed! address (0x60000007)
0x60000008 = 170
0x60000009 = 170
0x6000000a = 170
0x6000000b = 170
0x6000000c = 170
0x6000000d = 170
0x6000000e = 170
0x6000000f = 0
address bus test failed! address (0x6000000f)
...

Same issue for any address ending in 0x7 or 0xf.

Memory is written correctly, I have included an image from the debugger:

Screenshot 2023-10-27 at 15.16.09

which debugger is this? I'm having similar issues to you but on M7 with large structs. If you found any solutions I would love to hear. In my case I'm having bits flip/corruption. Here is an example of 64 bit pieces of data in bytes, left column is what was written, right was what was read:

0 0
0 0
0 0
0 0
0 0
0 0
8 8
40 40

fc fc
a9 a9
f1 f9
d2 c3
4d 4d
62 62
50 50
3f 3f

0 0
0 0
0 0
0 0
0 0
0 0
2e 2e
40 40

c8 c8
0 0
0 c8
0 0
0 0
0 0
0 0
0 0

0 0
0 0
0 0
0 0
0 0
0 0
8 8
40 40

fc fc
a9 a9
f1 fd
d2 e3
4d 4d
62 62
50 58
3f 3f

It is platform io with cortex debug plugin.

They did add some fixes for the M4 side, I have not seen problems with the M7 side but I have not used the SDRAM that much, sorry.

Hopefully someone from Arduino can help...