// look for the first PSRAM chip
flexspi2_command(0, 0); // exit quad mode
flexspi2_command(1, 0); // reset enable
flexspi2_command(2, 0); // reset (is this really necessary?)
if (!(flexspi2_psram_id(0) == 0x5D0D)) // * Force to enter the if without first chip
{
// first PSRAM chip is present, look for a second PSRAM chip
flexspi2_command(4, 0);
flexspi2_command(0, 0x800000); // exit quad mode
flexspi2_command(1, 0x800000); // reset enable
flexspi2_command(2, 0x800000); // reset (is this really necessary?)
if (flexspi2_psram_id(0x800000) == 0x5D0D)
{
flexspi2_command(4, 0x800000);
// Two PSRAM chips are present, 16 MByte
//external_psram_size = 16; // There's only one chip, so can't be 16
//}
//else
//{
// One PSRAM chip is present, 8 MByte
external_psram_size = 8;
}
// TODO: zero uninitialized EXTMEM variables
// TODO: copy from flash to initialize EXTMEM variables
sm_set_pool(&extmem_smalloc_pool, &_extram_end,
external_psram_size * 0x100000 -
((uint32_t)&_extram_end - (uint32_t)&_extram_start),
1, NULL);
} else {
// No PSRAM
memset(&extmem_smalloc_pool, 0, sizeof(extmem_smalloc_pool));
}