SPI-W25QXX
Configuration STM32F746I
STM32CubeMX 4.12.0
MCU STM32F746IGTx
PERIPHERALS MODES FUNCTIONS PINS
RCC Crystal/Ceramic Resonator RCC_OSC_IN PH0/OSC_IN
RCC Crystal/Ceramic Resonator RCC_OSC_OUT PH1/OSC_OUT
SPI1 Full-Duplex Master SPI1_MISO PA6
SPI1 Full-Duplex Master SPI1_MOSI PA7
SPI1 Full-Duplex Master SPI1_SCK PA5
USART1 Asynchronous USART1_RX PA10
USART1 Asynchronous USART1_TX PA9
Pin Nb PINs FUNCTIONs LABELs
29 PH0/OSC_IN RCC_OSC_IN
30 PH1/OSC_OUT RCC_OSC_OUT
50 PA4 GPIO_Output CS
51 PA5 SPI1_SCK
52 PA6 SPI1_MISO
53 PA7 SPI1_MOSI
120 PA9 USART1_TX
121 PA10 USART1_RX
SOFTWARE PROJECT
Project Settings :
Project Name : STM32F746I
Project Folder : C:\Users\Administrator\Desktop\20.SPI-AT45DBXX
Toolchain / IDE : MDK-ARM V5
Firmware Package Name and Version : STM32Cube FW_F7 V1.3.0
Code Generation Settings :
STM32Cube Firmware Library Package : Copy all used libraries into the project folder
Generate peripheral initialization as a pair of '.c/.h' files per IP : Yes
Backup previously generated files when re-generating : No
Delete previously generated files when not re-generated : Yes
Set all free pins as analog (to optimize the power consumption) : No
Toolchains Settings :
Compiler Optimizations : Balanced Size/Speed
單片機源程序如下:
- /**
- ******************************************************************************
- * File Name : main.c
- * Description : Main program body
- ******************************************************************************
- *
- * COPYRIGHT(c) 2015 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f7xx_hal.h"
- #include "spi.h"
- #include "usart.h"
- #include "gpio.h"
- /* USER CODE BEGIN Includes */
- #include <string.h>
- #include "W25Qx.h"
- /* USER CODE END Includes */
- /* Private variables ---------------------------------------------------------*/
- /* USER CODE BEGIN PV */
- /* Private variables ---------------------------------------------------------*/
- uint8_t wData[0x100];
- uint8_t rData[0x100];
- uint32_t i;
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- /* USER CODE BEGIN PFP */
- /* Private function prototypes -----------------------------------------------*/
- static void Error_Handler(void);
- /* USER CODE END PFP */
- /* USER CODE BEGIN 0 */
- /* USER CODE END 0 */
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- uint8_t ID[4];
- int i;
- /* USER CODE END 1 */
- /* 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_SPI1_Init();
- MX_USART1_UART_Init();
- /* USER CODE BEGIN 2 */
- printf("\r\n SPI-W25Qxxx Example \r\n\r\n");
- /*##-1- Read the device ID ########################*/
- BSP_W25Qx_Init();
- BSP_W25Qx_Read_ID(ID);
- printf("W25Qxxx ID is : ");
- for(i=0;i<2;i++)
- {
- printf("0x%02X ",ID[i]);
- }
- printf("\r\n\r\n");
-
- /*##-2- Erase Block ##################################*/
- if(BSP_W25Qx_Erase_Block(0) == W25Qx_OK)
- printf(" QSPI Erase Block ok\r\n");
- else
- Error_Handler();
-
- /*##-2- Written to the flash ########################*/
- /* fill buffer */
- for(i =0;i<0x100;i ++)
- {
- wData[i] = i;
- rData[i] = 0;
- }
-
- if(BSP_W25Qx_Write(wData,0x00,0x100)== W25Qx_OK)
- printf(" QSPI Write ok\r\n");
- else
- Error_Handler();
- /*##-3- Read the flash ########################*/
- if(BSP_W25Qx_Read(rData,0x00,0x100)== W25Qx_OK)
- printf(" QSPI Read ok\r\n\r\n");
- else
- Error_Handler();
-
- printf("QSPI Read Data : \r\n");
- for(i =0;i<0x100;i++)
- printf("0x%02X ",rData[i]);
- printf("\r\n\r\n");
-
- /*##-4- check date ########################*/
- if(memcmp(wData,rData,0x100) == 0 )
- printf(" W25Q128FV QuadSPI Test OK\r\n");
- else
- printf(" W25Q128FV QuadSPI Test False\r\n");
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- /* USER CODE END WHILE */
- /* USER CODE BEGIN 3 */
- }
- /* USER CODE END 3 */
- }
- /** System Clock Configuration
- */
- void SystemClock_Config(void)
- {
- RCC_OscInitTypeDef RCC_OscInitStruct;
- RCC_ClkInitTypeDef RCC_ClkInitStruct;
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
- __PWR_CLK_ENABLE();
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 4;
- RCC_OscInitStruct.PLL.PLLN = 200;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 2;
- HAL_RCC_OscConfig(&RCC_OscInitStruct);
- HAL_PWREx_ActivateOverDrive();
- RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
- |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
- RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
- RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
- RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
- HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_6);
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_USART1;
- PeriphClkInitStruct.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK2;
- HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
- HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
- HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
- /* SysTick_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
- }
- /* USER CODE BEGIN 4 */
- /**
- * @brief This function is executed in case of error occurrence.
- * @param None
- * @retval None
- */
- static void Error_Handler(void)
- {
- printf("something wrong ....\r\n");
- /* User may add here some code to deal with this error */
- while(1)
- {
- }
- }
- /* USER CODE END 4 */
- #ifdef USE_FULL_ASSERT
- /**
- * @brief Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * @param file: pointer to the source file name
- * @param line: assert_param error line source number
- * @retval None
- */
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* USER CODE BEGIN 6 */
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* USER CODE END 6 */
- }
- #endif
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
復制代碼
所有資料51hei提供下載:
10.SPI-W25QXX.7z
(1.37 MB, 下載次數: 38)
2022-12-16 04:56 上傳
點擊文件名下載附件
SPI-W25QXX STM32F746I
|