[STM32H7B0][OSPI] Not able to activate Memory Mapped mode in Read and Write modes
Hello Dear Community,
I am having a real strange issue while using OSPI peripheral in STM32H7B0 custom board.
I am trying to use OSPI with PSRAM but I wanna make sure it works fine, so I am using it with a NOR Flash for test.
When I try to activate the MMM using this code, it fails:
uint8_t
SHIP_XSPI_EnableMemoryMappedMode_RW(void) {
/* -------------------------- Enable Memory-Mapped mode------------------------ */
OSPI_RegularCmdTypeDef sCommand = {0};
OSPI_MemoryMappedTypeDef sMemMappedCfg = {0};
sCommand.OperationType = HAL_OSPI_OPTYPE_Read_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_1_LINE;
sCommand.AddressSize = HAL_OSPI_ADDRESS_24_BITS;
sCommand.DataMode = HAL_OSPI_DATA_4_LINES;
sCommand.Instruction = QUAD_IN_OUT_FAST_READ_CMD;
sCommand.AddressMode = HAL_OSPI_ADDRESS_4_LINES;
sCommand.DummyCycles = DUMMY_CLOCK_CYCLES_READ_QUAD;
sCommand.AlternateBytesMode = HAL_OSPI_ALTERNATE_BYTES_NONE;
sCommand.SIOOMode = HAL_OSPI_SIOO_INST_EVERY_CMD;
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE)
!= HAL_OK) {
return HAL_ERROR;
}
sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
sCommand.DummyCycles = NO_DUMMY_CYCLES;
sCommand.Instruction = QUAD_IN_FAST_PROG_CMD;
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE)
!= HAL_OK) {
return HAL_ERROR;
}
sMemMappedCfg.TimeOutActivation = HAL_OSPI_TIMEOUT_COUNTER_DISABLE;
if (HAL_OSPI_MemoryMapped(&hospi1, &sMemMappedCfg) != HAL_OK) {
return HAL_ERROR;
}
return HAL_OK;
}
/*****************************************************************************/
Also I see a weird implementation in function HAL_OSPI_MemoryMapped.
/* Check the state */
if (hospi->State == HAL_OSPI_STATE_CMD_CFG)
Here the function checks the state of the periph which can be other than HAL_OSPI_STATE_CMD_CFG, the case when I tried to use MMM only for read. That logically, doesn't work with this implementation as hospi->State will be equal to HAL_OSPI_OPTYPE_READ_CFG and the MMM not activated.
Now, my real problem is that with the above code, I cannot access the NOR flash with MMM in write mode. Could you please help and give hints here?
Thanks,
Ayoub