Skip to main content
KGojo
Associate
April 26, 2019
Question

Writing to external Flash through QSPI using an STM32L4

  • April 26, 2019
  • 4 replies
  • 1537 views

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.

This topic has been closed for replies.

4 replies

Tesla DeLorean
Guru
April 26, 2019

Review BSP code examples for assorted DISCO and EVAL series boards.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
KGojo
KGojoAuthor
Associate
April 26, 2019

Hello Clive,

I actually have been able to work with the QUADSPI Flash on a B-L475e-iot01a board. I started to move away from the BSP_QSPI functions because I had trouble envisioning how I would integrate the BSP files into a custom build. I just found this link for integrating BSP files into a project so I'll check it out. Is there any other recommended approach for integrating BSP files into builds?

KGojo
KGojoAuthor
Associate
April 27, 2019

I actually looked into the BSP programs in depth and I can see the code behind the BSP abstraction. I don't know how I missed it before but I can just emulate those