MG32F10x Standard Peripherals Firmware Library
SPIM2_SPI_FLASH example
  *************** (C) COPYRIGHT 2020 - 2023 megawin Technology ***************
  * @file    SPI/SPIM2_SPI_FLASH/readme.txt 
  * @author  megawin Application Team
  * @version V0.1.10
  * @date    05-January-2023
  * @brief   Description of the SPI SPIM2_SPI_FLASH example.
  ******************************************************************************
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, MEGAWIN SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
  * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM
  * THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  ******************************************************************************
Example Description

This example describes how to use the SPI firmware library communicate with a SPI FLASH.

In this example, Main clock is from PLL clock and it is configured at 96MHz. The PLL clock is based on 8MHz HSE. APB1 and APB2 clock is from Main clock.

This example performs the following operations:

  1. Initialize and configure the QSPI bit rate to 12 Mbit/s.
  2. Read the SPI Flash ID and print via UART.
  3. Using SPI FLASH driver the program performs an erase of the sector to be accessed,a write of a WriteData, defined in the main.c file, to the memory followed by a read.
  4. Data read from the memory stored in the ReadBuffer are compared with the expected values of the WriteData and print the result of this comparison.
Directory contents
  • SPI/SPIM2_SPI_FLASH/SPIM2_SPI_FLASH.uvprojx MDK5 project file
  • SPI/SPIM2_SPI_FLASH/SPIM2_SPI_FLASH.uvoptx MDK5 project options file
  • SPI/SPIM2_SPI_FLASH/JLinkSettings.ini Jlink settings file
  • SPI/SPIM2_SPI_FLASH/main.c Main program
  • SPI/SPIM2_SPI_FLASH/drv_spi_flash.c SPI Flash driver
  • SPI/SPIM2_SPI_FLASH/drv_spi_flash.h SPI Flash driver header file
Hardware and Software environment
  • Hardware environment
    • HSE crystal is 8MHz
    • The chip pins and SPI FLASH are connected as follows:
      • PC0 (SPIM2_NSS0) pin is connected to SPI Flash CS (pin1)
      • PC1 (SPIM2_SCK) pin is connected to SPI Flash CLK (pin6)
      • PC2 (SPIM2_MI) pin is connected to SPI Flash DO (pin2)
      • PC3 (SPIM2_MO) pin is connected to SPI Flash DI (pin5)
      • SPI Flash WP (pin3) is connected to Vdd
      • SPI Flash HOLD (pin7) is connected to Vdd
How to use it ?

In order to make the program work, you must do the following :

  • Open SPIM2_SPI_FLASH.uvprojx from this example folder by Keil MDK5
  • Rebuild all files and load your image into target memory
  • Run the example

    © COPYRIGHT 2020 - 2023 megawin Technology