cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure QUADSPI in stm32h747bi ?

SLuit.1
Associate III

Hi,

I am using stm32h747bi chip in custom board and I want to communicate with GD25Q32C flash memory. I have generated the code for QSPI driver from cubemx. I initialised the GPIO pins as below:

/* Peripheral clock enable */

  __HAL_RCC_QSPI_CLK_ENABLE();

  __HAL_RCC_GPIOE_CLK_ENABLE();

  __HAL_RCC_GPIOF_CLK_ENABLE();

  __HAL_RCC_GPIOA_CLK_ENABLE();

  __HAL_RCC_GPIOB_CLK_ENABLE();

  /**QUADSPI GPIO Configuration

  PE2   ------> QUADSPI_BK1_IO2

  PF8   ------> QUADSPI_BK1_IO0

  PF9   ------> QUADSPI_BK1_IO1

  PA1   ------> QUADSPI_BK1_IO3

  PB2   ------> QUADSPI_CLK

  PB10   ------> QUADSPI_BK1_NCS

  */

  GPIO_InitStruct.Pin = GPIO_PIN_2;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;

  HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;

  HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_1;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_10;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;

  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

and I have initialised the QUADSPI as below:

static void MX_QUADSPI_Init(void)

{

 /* QUADSPI parameter configuration*/

 hqspi.Instance = QUADSPI;

 hqspi.Init.ClockPrescaler = 5;

 hqspi.Init.FifoThreshold = 4;

 hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_NONE;

 hqspi.Init.FlashSize = 21;

 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;

 if (HAL_QSPI_Init(&hqspi) != HAL_OK)

 {

  Error_Handler();

 }

 else{

 printf("successfully initialised\n");

 }

}

According to the documentaion of STM, QSPI can be configured in 3 different modes but there is not any document how to configure it. Could you please let me know how to configure QSPI in indirect mode.

Another thing after doing all of these I still see that all the functions are inactive in stm32h7xx_hal_qspi.h. In top of the file there is one line #if defined(QUADSPI) and QUADSPI is not defined anywhere so it is inactive. Doesn't HAL_QSPI_Init(&hqspi) defines the QUADSPI and makes it active.

This was not the only place where the QUADSPI was inactive. It was inactive in stm32h7xx_hal_gpio_ex.h.

#if defined(QUADSPI)

#define GPIO_AF9_QUADSPI    ((uint8_t)0x09) /* QUADSPI Alternate Function mapping */

#endif /* QUADSPI */

So how do you configure QUADSPI and make all places where define(QUADSPI) is called active. I cannot go in each page and make those active. I think I am missing something about configuring the QUADSPI.

This is the first time I am working with QUADSPI and stm32. Is there any tutorial where it is guided step by step how to configure QUADSPI in stm32cubeide.

9 REPLIES 9
Mike_ST
ST Employee

Hello,

>> Another thing after doing all of these I still see that all the functions are inactive in stm32h7xx_hal_qspi.h. In top of the file there is one line #if defined(QUADSPI)

>> and QUADSPI is not defined anywhere so it is inactive.

QUADSPI symbol is defined in stm32h747xx.h.

Check stm32h7xx_hal_conf.h

#define HAL_QSPI_MODULE_ENABLED

And at the compiler command line the MCU is passed as a define

STM32H747xx

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

Yes I know it is defined in stm32h747xx.h but what do I need implement. In every file where if defined(QUADSPI) is called the function is inactive. I downloaded one example project from cubemx and in that one all the functions are active.

I have uncommented #define HAL_QSPI_MODULE_ENABLED and I have initialised the QUADSPI in main.c as I have explained above. Compiler is not showing any error but all the functions, macros and typedefs are inactive in stm32h7xx_hal_qspi.h. 

And the functions were inactive wherever #if defined(QUADSPI) was called.

I don't know if I can make you understand or not.

Yes I uncommented #define HAL_QSPI_MODULE_ENABLED and compiled the program with initialisation of QUADSPI. Compiler is not showing any error but all the fucntions,macros and typedefs are inactive in stm32h7xx_hal_qspi.h.

And the functions were inactive where ever  #if defined(QUADSPI) were called.

I don't know if I can make you understand or not but I want to make all of them active.

I downloaded one example project from cubemx to check it and all of those were active in example project. I tried to find the difference but I could not. So I think I am missing something and don't know what.

All the functions are active in stm32h7xx_hal_qspi.c and it recognizes QUADSPI as defined. It is inactive only in the stm32h7xx_hal_qspi.h. Does the .h file become active only during runtime ?

>> In every file where if defined(QUADSPI) is called the function is inactive.

What make you think that the code is not compiled ? What actual error message do you get ?

>> Does the .h file become active only during runtime ?

I feel like this is just an editor problem.

It's not called, it is a preprocessor directive, so it is more indicative of an order of inclusion​, include paths ordering, or command line defines issue.

Start by looking at the compiler command line sent. Perhaps inspect the project file in a text editor and check assorted meta data settings related to CPU selection, defines and paths.

Should also be possible to have preprocessor generate intermediate file so you can see what the compiler actually processes.​

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

>>What make you think that the code is not compiled ? What actual error message do you get ?

 I checked the file stm32h7xx_hal_qspi.h and I found the whole file inactive(functions, typedefs and macros). I am trying to communicate with quadspi flash and I am not able to communicate.

So, I just wanted to make sure that it doesnot matter if everything in stm32h7xx_hal_qspi.h file is inactive. However, as I have mentioned before in file stm32h7xx_hal_qspi.c file all the functions are active and it finds that QUADSPI is defined.

To inform you, I am working on dual core stm32h747 MCU and I have implemented QSPI in core 7. I have linked the stm32h7xx_hal_qspi.c file inside core 7 driver. Header and source file for all the drivers are outside core 7.