cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_QSPI_COMMAND locks up the QSPI FLASH

Aarra.1
Senior

Dear All,

I'm using STM32H757I-EVAL board. My stm32 cube ide version is 1.7.0.

I'm trying the basic operation of reading the manufacture ID of the QSPI Flash.

Below is the initialization code, which I have configured using STM32CubeMX.

static void MX_QUADSPI_Init(void)
{
 
  /* USER CODE BEGIN QUADSPI_Init 0 */
 
  /* USER CODE END QUADSPI_Init 0 */
 
  /* USER CODE BEGIN QUADSPI_Init 1 */
 
  /* USER CODE END QUADSPI_Init 1 */
  /* QUADSPI parameter configuration*/
  hqspi.Instance = QUADSPI;
  hqspi.Init.ClockPrescaler = 3;
  hqspi.Init.FifoThreshold = 4;
  hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
  hqspi.Init.FlashSize = 26;
  hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_2_CYCLE;
  hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
  hqspi.Init.FlashID = QSPI_FLASH_ID_1;
  hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
  if (HAL_QSPI_Init(&hqspi) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN QUADSPI_Init 2 */
 
  /* USER CODE END QUADSPI_Init 2 */
 
}

And below is my code for reading the Device ID

/* Function to read Manufacturer ID, Memory type & Memory density */
unsigned char QFlash_ID_RDID(unsigned char *rdid)
{
 
	QSPI_CommandTypeDef sCommand;
 
	sCommand.Instruction = READ_ID_CMD;
	sCommand.InstructionMode = QSPI_INSTRUCTION_1_LINE;
	sCommand.AddressMode = QSPI_ADDRESS_NONE;
	sCommand.DataMode = QSPI_DATA_1_LINE;
	sCommand.NbData = 3;
	sCommand.DummyCycles = 0;
	sCommand.SIOOMode = QSPI_SIOO_INST_EVERY_CMD;
 
  qspi_error = HAL_QSPI_Command(hqspi, &sCommand,HAL_QSPI_TIMEOUT_DEFAULT_VALUE);
		if (qspi_error != HAL_OK)
		{
			return(qspi_error);
		}
 
qspi_error = HAL_QSPI_Receive(hqspi, rdid, HAL_QSPI_TIMEOUT_DEFAULT_VALUE);
		if (qspi_error != HAL_OK)
		{
			return(qspi_error);
		}
 
	return(qspi_error);
 
}

While Debugging When the HAL_QSPI_Command is executing

__HAL_LOCK(hqspi); process occurs and enter Hard fault Interrupt.

Kindly please help me rectify this issue

6 REPLIES 6

Perhaps clear the auto/local variable so it doesn't contain random junk

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

Sorry I don't understand could you please elaborate.

The stack contains junk, if you don't initialize local structures/variables completely down stream code can malfunction. Suggest you remove that as a potential cause of the issue, and keep debugging if necessary. Perhaps use some of the Board specific BSP code to initialize and access them memory, rather than hope/expect CubeMX to do it properly.

QSPI_CommandTypeDef sCommand = {0}; // Clears this so initial content is KNOWN and PREDICTABLE

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

Thank you so much for your response.

I have done exactly as you mentioned

Still the error of entering into the Hard fault Interrupt hasn't solved.

I have been trying all means kindly help me out with this.@Community member​ 

Should you be using &hqspi ​and not hqspi ?

I​f you don't have a good HardFault Handler you might want to use one that outputs comprehensive data

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

Thanks for your reponse@Community member​ 

Well Now the HardFault has been rectified.

The problem was I had defined the hqspi as "QSPI_HandleTypeDef hqspi;" in my .c file instead of "extern QSPI_HandleTypeDef hqspi;"

And My clock speed was 200Mhz which I reduced it to 50MHz.

Which solved the HardFault error.

Now I'm able to send the command successfully.