cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected behaviour with using STM32 QSPI over HAL

chmanie
Associate

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.

2 REPLIES 2
chmanie
Associate

I figured it out. Was a dumb mistake.

`qspiCommand` needs to be static.

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
Up vote any posts that you find helpful, it shows what's working..