181 lines
5.2 KiB
C
181 lines
5.2 KiB
C
/*
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2020-07-07 thread-liu first version
|
|
*/
|
|
|
|
#include <board.h>
|
|
#include <drv_qspi.h>
|
|
#include <rtdevice.h>
|
|
#include <rthw.h>
|
|
#include <finsh.h>
|
|
|
|
#ifdef BSP_USING_QSPI_FLASH
|
|
|
|
#include "spi_flash.h"
|
|
#include "spi_flash_sfud.h"
|
|
|
|
/**
|
|
* @brief QSPI MSP Initialization
|
|
* This function configures the hardware resources used in this example
|
|
* @param hqspi: QSPI handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_QSPI_MspInit(QSPI_HandleTypeDef* hqspi)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
|
|
|
if(hqspi->Instance==QUADSPI)
|
|
{
|
|
/* USER CODE BEGIN QUADSPI_MspInit 0 */
|
|
if (IS_ENGINEERING_BOOT_MODE())
|
|
{
|
|
PeriphClkInit.Sdmmc12ClockSelection = RCC_QSPICLKSOURCE_ACLK;
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_QSPI;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
Error_Handler();
|
|
}
|
|
}
|
|
/* USER CODE END QUADSPI_MspInit 0 */
|
|
/* Peripheral clock enable */
|
|
__HAL_RCC_QSPI_CLK_ENABLE();
|
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
/**QUADSPI GPIO Configuration
|
|
PF6 ------> QUADSPI_BK1_IO3
|
|
PF7 ------> QUADSPI_BK1_IO2
|
|
PF8 ------> QUADSPI_BK1_IO0
|
|
PF9 ------> QUADSPI_BK1_IO1
|
|
PF10 ------> QUADSPI_CLK
|
|
PB6 ------> QUADSPI_BK1_NCS
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_7 | GPIO_PIN_6;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
|
|
HAL_GPIO_Init(GPIOF, &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_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
|
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
|
|
|
/**QUADSPI GPIO Configuration
|
|
PC0 ------> QUADSPI_BK2_NCS
|
|
PH3 ------> QUADSPI_BK2_IO1
|
|
PG7 ------> QUADSPI_BK2_IO3
|
|
PG10 ------> QUADSPI_BK2_IO2
|
|
PH2 ------> QUADSPI_BK2_IO0
|
|
*/
|
|
GPIO_InitStruct.Pin = GPIO_PIN_0;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
|
|
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.Pin = GPIO_PIN_7|GPIO_PIN_10;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
|
GPIO_InitStruct.Alternate = GPIO_AF11_QUADSPI;
|
|
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
|
|
|
|
/* USER CODE BEGIN QUADSPI_MspInit 1 */
|
|
|
|
/* USER CODE END QUADSPI_MspInit 1 */
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief QSPI MSP De-Initialization
|
|
* This function freeze the hardware resources used in this example
|
|
* @param hqspi: QSPI handle pointer
|
|
* @retval None
|
|
*/
|
|
void HAL_QSPI_MspDeInit(QSPI_HandleTypeDef* hqspi)
|
|
{
|
|
if(hqspi->Instance==QUADSPI)
|
|
{
|
|
/* USER CODE BEGIN QUADSPI_MspDeInit 0 */
|
|
|
|
/* USER CODE END QUADSPI_MspDeInit 0 */
|
|
/* Peripheral clock disable */
|
|
__HAL_RCC_QSPI_CLK_DISABLE();
|
|
|
|
/**QUADSPI GPIO Configuration
|
|
PC0 ------> QUADSPI_BK2_NCS
|
|
PF10 ------> QUADSPI_CLK
|
|
PB6 ------> QUADSPI_BK1_NCS
|
|
PH3 ------> QUADSPI_BK2_IO1
|
|
PG7 ------> QUADSPI_BK2_IO3
|
|
PG10 ------> QUADSPI_BK2_IO2
|
|
PF7 ------> QUADSPI_BK1_IO2
|
|
PF6 ------> QUADSPI_BK1_IO3
|
|
PH2 ------> QUADSPI_BK2_IO0
|
|
PF8 ------> QUADSPI_BK1_IO0
|
|
PF9 ------> QUADSPI_BK1_IO1
|
|
*/
|
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_0);
|
|
|
|
HAL_GPIO_DeInit(GPIOF, GPIO_PIN_6|GPIO_PIN_7|GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10);
|
|
|
|
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6);
|
|
|
|
HAL_GPIO_DeInit(GPIOH, GPIO_PIN_3|GPIO_PIN_2);
|
|
|
|
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_7|GPIO_PIN_10);
|
|
|
|
/* USER CODE BEGIN QUADSPI_MspDeInit 1 */
|
|
|
|
/* USER CODE END QUADSPI_MspDeInit 1 */
|
|
}
|
|
|
|
}
|
|
|
|
static int rt_hw_qspi_flash_with_sfud_init(void)
|
|
{
|
|
stm32_qspi_bus_attach_device("qspi1", "qspi10", RT_NULL, 4, RT_NULL, RT_NULL);
|
|
/* init MX25L51245G */
|
|
if (RT_NULL == rt_sfud_flash_probe("MX25L51245G", "qspi10"))
|
|
{
|
|
return -RT_ERROR;
|
|
}
|
|
|
|
return RT_EOK;
|
|
}
|
|
INIT_DEVICE_EXPORT(rt_hw_qspi_flash_with_sfud_init);
|
|
|
|
#endif /* BSP_USING_QSPI_FLASH */
|