2020-12-06 03:20 AM
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:
Mind 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:
Mind 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.
2020-12-06 04:55 AM
I figured it out. Was a dumb mistake.
`qspiCommand` needs to be static.
2020-12-06 05:33 AM
Automatic/local variables are best explicit cleared. To ensure consistent behaviour.
ie
int foo[10] = {0};