Skip to main content
chmanie
Associate
December 6, 2020
Question

Unexpected behaviour with using STM32 QSPI over HAL

  • December 6, 2020
  • 2 replies
  • 1010 views

I am using the QSPI (or dual-SPI) interface of the STM32L452 to create instructions for an LED driver using the HAL. I have managed to get it to work but I have to set quite absurd configuration options for the command to make it work.

Here's my initialization code:

 hqspi.Instance = QUADSPI;
 hqspi.Init.ClockPrescaler = 31;
 hqspi.Init.FifoThreshold = 1;
 hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;
 hqspi.Init.FlashSize = 31;
 hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_1_CYCLE;
 hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
 hqspi.Init.FlashID = QSPI_FLASH_ID_1;
 hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
 HAL_QSPI_Init(&hqspi);

Here's the code I'm using to set up the command:

 qspiCommand.InstructionMode = QSPI_INSTRUCTION_NONE;
 qspiCommand.AddressMode = QSPI_ADDRESS_NONE;
 qspiCommand.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;
 qspiCommand.DataMode = QSPI_DATA_2_LINES;
 qspiCommand.DummyCycles = 0;
 qspiCommand.NbData = 81;
 qspiCommand.DdrMode = QSPI_DDR_MODE_DISABLE;
 qspiCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY; // I have to set this
 qspiCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD; // I have to set this

Then I send it off using `HAL_QSPI_Command` and `HAL_QSPI_Transmit`.

Here's the output that I expect and that I can achieve using the code above:

0693W000006EkvPQAS.pngMind that this is a one-off transfer, and is only output when I call the two functions above.

The weird thing is that I have to set

qspiCommand.DdrHoldHalfCycle = QSPI_DDR_HHC_ANALOG_DELAY;

(which should not have an effect when `DdrMode` is disabled) and

qspiCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;

(which should not have an effect when `InstructionMode` is none).

If I do not set both of them, weird things happen. This is the output if I remove the `DdrHoldHalfCycle` parameter:

0693W000006EkvUQAS.pngMind that this is a continuous signal, which starts and won't stop after I called the transmit function.

What am I missing here? I really shouldn't need those parameters to make it work.

This topic has been closed for replies.

2 replies

chmanie
chmanieAuthor
Associate
December 6, 2020

I figured it out. Was a dumb mistake.

`qspiCommand` needs to be static.

Tesla DeLorean
Guru
December 6, 2020

Automatic/local variables are best explicit cleared. To ensure consistent behaviour.

ie

int foo[10] = {0};​

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