Memory Mapped QSPI reads nonsensical data
I am using a STM32F746zg uc connected to a W25Q80 Flash memory. In my initialization I erase a page then memory map the flash and then I read a pointer to that address. I expect to read 0xFF as the flash has just been erased, however I read 0x88. I'm not sure what is causing this behavior. Have I improperly wired the flash or is this an issue with my code (see snippets below)?
More Info:
- I'm using Cube IDE and created the project using Cube MX.
- I am able to properly read the manufacturer and device ID so I know that atleast vcc, gnd, cs, clk, io0 are wired properly.
- I followed the cubef7 example for memory mapped qspi as closely as possible
int EraseSector(QSPI_HandleTypeDef* hqspi, QSPI_CommandTypeDef* sCommand, QSPI_AutoPollingTypeDef* sConfig, uint32_t addr)
{
sCommand->Instruction = SECTOR_ERASE_CMD;
sCommand->AddressMode = QSPI_ADDRESS_1_LINE;
sCommand->Address = addr;
sCommand->DataMode = QSPI_DATA_NONE;
sCommand->DummyCycles = 0;
if (HAL_QSPI_Command(hqspi, sCommand, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return 0;
}
/* Configure automatic polling mode to wait for memory ready ------ */
sCommand->InstructionMode = QSPI_INSTRUCTION_1_LINE;
sCommand->Instruction = READ_STATUS_REG_CMD;
sCommand->AddressMode = QSPI_ADDRESS_NONE;
sCommand->AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
sCommand->DataMode = QSPI_DATA_1_LINE;
sCommand->DummyCycles = 0;
sCommand->DdrMode = QSPI_DDR_MODE_DISABLE;
sCommand->DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;
sCommand->SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
sConfig->Match = 0x00;
sConfig->Mask = 0x01;
sConfig->MatchMode = QSPI_MATCH_MODE_AND;
sConfig->StatusBytesSize = 1;
sConfig->Interval = 0x10;
sConfig->AutomaticStop = QSPI_AUTOMATIC_STOP_ENABLE;
if (HAL_QSPI_AutoPolling(hqspi, sCommand, sConfig, HAL_QPSI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
{
return 0;
}
return 1;
}int SetMemoryMap(QSPI_HandleTypeDef* hqspi, QSPI_CommandTypeDef* sCommand)
{
// Memory Map the External flash
QSPI_MemoryMappedTypeDef s_mem_mapped_cfg;
/* Configure the command for the read instruction */
sCommand->InstructionMode = QSPI_INSTRUCTION_4_LINES;
sCommand->Instruction = QUAD_OUT_FAST_READ_CMD;
sCommand->AddressMode = QSPI_ADDRESS_4_LINES;
sCommand->DataMode = QSPI_DATA_4_LINES;
sCommand->DummyCycles = DUMMY_CLOCK_CYCLES_READ_QUAD;
/* Configure the memory mapped mode */
s_mem_mapped_cfg.TimeOutActivation = QSPI_TIMEOUT_COUNTER_DISABLE;
s_mem_mapped_cfg.TimeOutPeriod = 0;
if (HAL_QSPI_MemoryMapped(hqspi, sCommand, &s_mem_mapped_cfg) != HAL_OK)
{
return 0;
}
return 1;
} /* Reading Sequence ------------------------------------------------ */
__IO uint8_t *qspi_addr = (__IO uint8_t *)(0x90000000);
for (int idx = 0; idx < BUFFERSIZE; idx++)
{
if (*qspi_addr != aTxBuffer[idx])
{
HAL_GPIO_TogglePin(GPIOB, LD3_Pin);
}
qspi_addr++;
}