Write in OSPI
Hello,
I'm working on STM32H7B3I-EVAL with STM32CubeIDE. I would like to write in the OSPI, so I made the following code:
void OSPI_Write(uint32_t address, uint8_t *data, uint32_t size) {
OSPI_RegularCmdTypeDef sCommand;
// Désactivation du mode mappé
HAL_OSPI_Abort(&hospi1);
// Configuration de la commande pour l'écriture en mode indirect
sCommand.OperationType = HAL_OSPI_OPTYPE_WRITE_CFG;
sCommand.FlashId = HAL_OSPI_FLASH_ID_1;
sCommand.Instruction = MX25LM51245G_OCTA_WRITE_ENABLE_CMD;
sCommand.InstructionMode = HAL_OSPI_INSTRUCTION_8_LINES;
sCommand.Address = address;
sCommand.AddressMode = HAL_OSPI_ADDRESS_8_LINES;
sCommand.AddressSize = HAL_OSPI_ADDRESS_32_BITS;
sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
sCommand.NbData = size;
sCommand.DummyCycles = 0;
sCommand.DQSMode = HAL_OSPI_DQS_DISABLE;
// Envoye de la commande d'écriture
if (HAL_OSPI_Command(&hospi1, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) { //5s
Error_Handler();
}
// Écrire les données dans la mémoire
if (HAL_OSPI_Transmit(&hospi1, data, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
Error_Handler();
}
// Attendre que l'opération soit terminée
OSPI_AutoPollingMemReady(&hospi1);
}
void OSPI_AutoPollingMemReady(OSPI_HandleTypeDef *hospi) {
OSPI_AutoPollingTypeDef sConfig;
// Configuration pour la lecture du statut de la mémoire pour vérifier si elle est prête
sConfig.Match = 0x00;
sConfig.Mask = 0x01;
sConfig.MatchMode = HAL_OSPI_MATCH_MODE_AND;
sConfig.Interval = 0x10;
sConfig.AutomaticStop = HAL_OSPI_AUTOMATIC_STOP_ENABLE;
OSPI_RegularCmdTypeDef sCommand;
sCommand.Instruction = 0x05;
sCommand.InstructionMode= HAL_OSPI_INSTRUCTION_8_LINES;
sCommand.AddressMode = HAL_OSPI_ADDRESS_NONE;
sCommand.DataMode = HAL_OSPI_DATA_8_LINES;
sCommand.NbData = 1;
HAL_OSPI_Command(hospi, &sCommand, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
HAL_OSPI_AutoPolling(hospi, &sConfig, HAL_OSPI_TIMEOUT_DEFAULT_VALUE);
}
Sorry the comments are in french.
The problem is that it can't write to the OSPI, on the first if it does Error_Handler.
Could you please help me to understand where the error comes from?
