2021-12-03 11:28 PM
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
2021-12-03 11:51 PM
Perhaps clear the auto/local variable so it doesn't contain random junk
2021-12-04 01:20 AM
Sorry I don't understand could you please elaborate.
2021-12-04 06:15 AM
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
2021-12-06 10:00 PM
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
2021-12-07 04:48 AM
Should you be using &hqspi and not hqspi ?
If you don't have a good HardFault Handler you might want to use one that outputs comprehensive data
2021-12-07 09:21 PM
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.