STM32 NORFALSH驱动程序

本文档详细介绍了如何在STM32上配置FSMC接口以驱动NOR FLASH,包括初始化设置、读写操作、擦除块和整个芯片的擦除方法,以及状态检查等关键步骤。通过示例代码,演示了读写缓冲区、读取ID和错误检查等功能,以确保NOR FLASH的正确操作。
摘要由CSDN通过智能技术生成
 

/* Includes ------------------------------------------------------------------*/
#include "fsmc_nor.h"

/* Private define ------------------------------------------------------------*/
#define NOR_FLASH_START_ADDR       ((uint32_t)0x64000000)
#define NOR_FLASH_END_ADDR         ((uint32_t)0x64FFFFFF)

/* Delay definition */  
#define BlockErase_Timeout         ((uint32_t)0x00A00000)
#define ChipErase_Timeout          ((uint32_t)0x30000000)
#define Program_Timeout            ((uint32_t)0x00001400)

#define ADDR_SHIFT(A)              (NOR_FLASH_START_ADDR + (2 * (A)))
#define NOR_WRITE(Address, Data)   (*(vu16 *)(Address) = (Data))

#define BUFFER_SIZE                0x400
#define WRITE_READ_ADDR            0x8000

/* Private variables ---------------------------------------------------------*/
static uint16_t TxBuffer[BUFFER_SIZE];
static uint16_t RxBuffer[BUFFER_SIZE];

/*******************************************************************************
* Function Name  : FSMC_NOR_Init
* Description    : Configures the FSMC and GPIOs to interface with the NOR memory.
*                  This function must be called before any write/read operation
*                  on the NOR.
* Input          : None
* Output         : None
* Return         : None
* Attention   : None
*******************************************************************************/
void FSMC_NOR_Init(void)
{
  FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;
  FSMC_NORSRAMTimingInitTypeDef  p;
  GPIO_InitTypeDef GPIO_InitStructure;

  /*使能FSMC总线时钟*/
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
   
  /*使能FSMC总线使用的GPIO组时钟*/
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF |
                         RCC_APB2Periph_GPIOG | RCC_APB2Periph_AFIO , ENABLE);

  /*FSMC数据线FSMC_D[0:15]初始化,推挽复用输出*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_8 | GPIO_Pin_9 |
                                GPIO_Pin_10 | GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
                                GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 |
                                GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /*FSMC地址线FSMC_A[0:17]初始化,推挽复用输出*/
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 |
                                GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12 | GPIO_Pin_13 |
                                GPIO_Pin_14 | GPIO_Pin_15;
  GPIO_Init(GPIOF, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 |
                                GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;                           
  GPIO_Init(GPIOG, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /*FSMC NOE和NWE初试化,推挽复用输出*/ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /*FSMC NE2初试化,推挽复用输出*/ 
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_Init(GPIOG, &GPIO_InitStructure);

  /*--------------FSMC 总线 存储器参数配置------------------------------*/
  p.FSMC_AddressSetupTime = 0x02;   //地址建立时间   
  p.FSMC_AddressHoldTime = 0x00;    //地址保持时间 
  p.FSMC_DataSetupTime = 0x05;      //数据建立时间
  p.FSMC_BusTurnAroundDuration = 0; //总线恢复时间x00
  p.FSMC_CLKDivision = 0x00;        // 时钟分频因子
  p.FSMC_DataLatency = 0x00;        //数据产生时间
  p.FSMC_AccessMode = FSMC_AccessMode_B; //FSMC NOR控制器时序

  FSMC_NORSRAMInitStruc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值