Writing to external Flash through QSPI using an STM32L4
Hello all,
I am working with a board that features an STM32L4 and I would appreciate some pointers on writing and reading to the external flash. The device I am using is the MX25R6435F and I have been able to read the device ID without any problem with the following code.
#define RDID 0x9F
QSPI_HandleTypeDef hqspi;
QSPI_CommandTypeDef sCommand;
uint8_t reg[3];
sCommand.InstructionMode=QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction=RDID;
sCommand.AddressMode=QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode=QSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode=QSPI_DATA_1_LINE;
sCommand.DummyCycles=0;
sCommand.Address=0;
sCommand.DdrMode=QSPI_DDR_MODE_DISABLE;
sCommand.SIOOMode=QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData=3;
HAL_QSPI_Command(&hqspi, sCommand, 1000)
HAL_QSSPI_Receive(&hqspi, reg, 1000);However, problems arise when I try to modify the above code to write values to the device.
The MX25R64's datasheet mentions PP, Page Program, and WREN, Write Enable. I initially set both instructions and then tried to transmit and receive data, but I did not read the right value back from the flash.
#define WREN 0x06
#define PP 0x02
sCommand.InstructionMode=QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction=WREN;
sCommand.AddressMode=QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode=QSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode=QSPI_DATA_1_LINE;
sCommand.DummyCycles=0;
sCommand.Address==Addr;
sCommand.DdrMode=QSPI_DDR_MODE_DISABLE;
sCommand.SIOOMode=QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData=3;
sCommand.InstructionMode=QSPI_INSTRUCTION_1_LINE;
sCommand.Instruction=PP;
sCommand.AddressMode=QSPI_ADDRESS_NONE;
sCommand.AlternateByteMode=QSPI_ALTERNATE_BYTES_NONE;
sCommand.DataMode=QSPI_DATA_1_LINE;
sCommand.DummyCycles=0;
sCommand.Address=Addr;
sCommand.DdrMode=QSPI_DDR_MODE_DISABLE;
sCommand.SIOOMode=QSPI_SIOO_INST_EVERY_CMD;
sCommand.NbData=3;I am confused about where to proceed from here because I'm not sure if following the above code with HAL_QSPI TX and RX commands is enough
HAL_QSPI_Transmit(&hqspi, pData, Timeout);
HAL_QSPI_Receive(&hqspi, pData, Timeout);I was wondering if anyone had any insight into writing to this device. I am new to QSPI so I'm not sure if my problems are related to my misinterpretation of the datasheet or the interface.
