cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L452 QSPI no output

Mads Skov
Associate

Hi

I am using a STM32L452 MCU with a quadspi flash from Micron.

I configured the board using CubeMX and have tried making a test code based on the example in: STM32Cube_FW_L4_V1.15.1\Projects\STM32L476G-EVAL\Examples\QSPI\QSPI_ReadWrite_DMA

I'm trying to read the Manufacturer ID on the flash but I'm not getting any of the signals on the datalines.

0693W000000V9CwQAK.png

static void MX_QUADSPI_Init(void)

{

 /* QUADSPI parameter configuration*/

 hqspi.Instance = QUADSPI;

 hqspi.Init.ClockPrescaler = 125;

 hqspi.Init.FifoThreshold = 4;

 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_3;

 hqspi.Init.FlashID = QSPI_FLASH_ID_1;

 hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;

 if (HAL_QSPI_Init(&hqspi) != HAL_OK)

 {

  Error_Handler();

 }

}

void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hqspi->Instance==QUADSPI)

 {

  /* Peripheral clock enable */

  __HAL_RCC_QSPI_CLK_ENABLE();

  

  __HAL_RCC_GPIOA_CLK_ENABLE();

  __HAL_RCC_GPIOB_CLK_ENABLE();

  /**QUADSPI GPIO Configuration   

  PA2   ------> QUADSPI_BK1_NCS

  PA3   ------> QUADSPI_CLK

  PA6   ------> QUADSPI_BK1_IO3

  PA7   ------> QUADSPI_BK1_IO2

  PB0   ------> QUADSPI_BK1_IO1

  PB1   ------> QUADSPI_BK1_IO0 

  */

  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_6|GPIO_PIN_7;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;

  GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* QUADSPI DMA Init */

  /* QUADSPI Init */

  hdma_quadspi.Instance = DMA1_Channel5;

  hdma_quadspi.Init.Request = DMA_REQUEST_5;

  hdma_quadspi.Init.Direction = DMA_MEMORY_TO_PERIPH;

  hdma_quadspi.Init.PeriphInc = DMA_PINC_DISABLE;

  hdma_quadspi.Init.MemInc = DMA_MINC_ENABLE;

  hdma_quadspi.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;

  hdma_quadspi.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;

  hdma_quadspi.Init.Mode = DMA_NORMAL;

  hdma_quadspi.Init.Priority = DMA_PRIORITY_LOW;

  if (HAL_DMA_Init(&hdma_quadspi) != HAL_OK)

  {

   Error_Handler();

  }

  __HAL_LINKDMA(hqspi,hdma,hdma_quadspi);

 }

}

int main(void)

{

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* Configure the system clock */

 SystemClock_Config();

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_RTC_Init();

 MX_USB_DEVICE_Init();

 MX_QUADSPI_Init();

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

 HAL_Delay(10);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);

 if(QSPIFlashWriteEnable(&hqspi) != HAL_OK) {

  sprintf(usartTxBuffer, "Error: Write Enable Failed");

  HAL_UART_Transmit(&huart4, usartTxBuffer, sizeof(usartTxBuffer), HAL_UART_TIMEOUT_VALUE);

 }

 else {

  sprintf(usartTxBuffer,"Write Enable done");

  HAL_UART_Transmit(&huart4, usartTxBuffer, sizeof(usartTxBuffer), HAL_UART_TIMEOUT_VALUE);

 }

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);

 /* Infinite loop */

 while (1)

 {

 }

}

HAL_StatusTypeDef QSPIFlashReadRDID(QSPI_HandleTypeDef *hqspi, uint8_t *rxData) {

 QSPI_CommandTypeDef qspiCmd;

 qspiCmd.Instruction = FLASH_READ_ID;

 qspiCmd.DummyCycles = 0;

 qspiCmd.InstructionMode = QSPI_INSTRUCTION_1_LINE;

 qspiCmd.AddressMode = QSPI_ADDRESS_NONE;

 qspiCmd.AlternateByteMode = QSPI_ALTERNATE_BYTES_NONE;

 qspiCmd.DataMode = QSPI_DATA_1_LINE;

 qspiCmd.DdrMode = QSPI_DDR_MODE_DISABLE;

 qspiCmd.NbData = 2;

 qspiCmd.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;

 if(HAL_QSPI_Command(hqspi, &qspiCmd, HAL_QSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)

 {

  return HAL_ERROR;

 }

 return HAL_QSPI_Receive(hqspi, rxData, HAL_QSPI_TIMEOUT_DEFAULT_VALUE);

}

1 ACCEPTED SOLUTION

Accepted Solutions
Mads Skov
Associate

Turns out there was a faulty connction on the PCB.

Thank you for the help though.

View solution in original post

2 REPLIES 2

Pin initialization looks Ok.

Size, Clocking and Prescaler look incorrect.

Check for error responses.

QSPI_CommandTypeDef qspiCmd = {0}; // ensure local/auto variables are clear

sizeof() in Transmit gives wrong length for use case, try

  HAL_UART_Transmit(&huart4, usartTxBuffer, sprintf(usartTxBuffer, "Error: Write Enable Failed"), HAL_UART_TIMEOUT_VALUE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Mads Skov
Associate

Turns out there was a faulty connction on the PCB.

Thank you for the help though.