日韩一区二区三区精品,欧美疯狂xxxxbbbb牲交,热99re久久免费视精品频,人妻互换 综合,欧美激情肉欲高潮视频

GD32F303固件庫開發(fā)(16)----移植兆易創(chuàng)新SPI Nor Flash之GD25Q64Flash

發(fā)布者:superstar11最新更新時間:2024-12-05 來源: elecfans關(guān)鍵字:GD32F303  固件庫開發(fā)  SPI  Nor  Flash 手機看文章 掃描二維碼
隨時隨地手機看文章

#define W25Q128FV_FLASH_SIZE                  0x1000000 /* 128 MBits = > 16MBytes */

#define W25Q128FV_SECTOR_SIZE                 0x10000   /* 256 sectors of 64KBytes */

#define W25Q128FV_SUBSECTOR_SIZE              0x1000    /* 4096 subsectors of 4kBytes */

#define W25Q128FV_PAGE_SIZE                   0x100     /* 65536 pages of 256 bytes */


#define W25Q128FV_DUMMY_CYCLES_READ           4

#define W25Q128FV_DUMMY_CYCLES_READ_QUAD      10


#define W25Q128FV_BULK_ERASE_MAX_TIME         250000

#define W25Q128FV_SECTOR_ERASE_MAX_TIME       10000

#define W25Q128FV_SUBSECTOR_ERASE_MAX_TIME    800

#define W25Qx_TIMEOUT_VALUE 1000


/** 

  * @brief  W25Q128FV Commands  

  */  

/* Reset Operations */

#define RESET_ENABLE_CMD                     0x66

#define RESET_MEMORY_CMD                     0x99


#define ENTER_QPI_MODE_CMD                   0x38

#define EXIT_QPI_MODE_CMD                    0xFF


/* Identification Operations */

#define READ_ID_CMD                          0x90

#define DUAL_READ_ID_CMD                     0x92

#define QUAD_READ_ID_CMD                     0x94

#define READ_JEDEC_ID_CMD                    0x9F


/* Read Operations */

#define READ_CMD                             0x03

#define FAST_READ_CMD                        0x0B

#define DUAL_OUT_FAST_READ_CMD               0x3B

#define DUAL_INOUT_FAST_READ_CMD             0xBB

#define QUAD_OUT_FAST_READ_CMD               0x6B

#define QUAD_INOUT_FAST_READ_CMD             0xEB


/* Write Operations */

#define WRITE_ENABLE_CMD                     0x06

#define WRITE_DISABLE_CMD                    0x04


/* Register Operations */

#define READ_STATUS_REG1_CMD                  0x05

#define READ_STATUS_REG2_CMD                  0x35

#define READ_STATUS_REG3_CMD                  0x15


#define WRITE_STATUS_REG1_CMD                 0x01

#define WRITE_STATUS_REG2_CMD                 0x31

#define WRITE_STATUS_REG3_CMD                 0x11



/* Program Operations */

#define PAGE_PROG_CMD                        0x02

#define QUAD_INPUT_PAGE_PROG_CMD             0x32



/* Erase Operations */

#define SECTOR_ERASE_CMD                     0x20

#define CHIP_ERASE_CMD                       0xC7


#define PROG_ERASE_RESUME_CMD                0x7A

#define PROG_ERASE_SUSPEND_CMD               0x75



/* Flag Status Register */

#define W25Q128FV_FSR_BUSY                    ((uint8_t)0x01)    /*!< busy */

#define W25Q128FV_FSR_WREN                    ((uint8_t)0x02)    /*!< write enable */

#define W25Q128FV_FSR_QE                      ((uint8_t)0x02)    /*!< quad enable */



#define W25Qx_Enable()             gpio_bit_reset(GPIOD,GPIO_PIN_14)

#define W25Qx_Disable()         gpio_bit_set(GPIOD,GPIO_PIN_14)


#define W25Qx_OK            ((uint8_t)0x00)

#define W25Qx_ERROR         ((uint8_t)0x01)

#define W25Qx_BUSY          ((uint8_t)0x02)

#define W25Qx_TIMEOUT                ((uint8_t)0x03)



uint8_t BSP_W25Qx_Init(void);

static void    BSP_W25Qx_Reset(void);

static uint8_t BSP_W25Qx_GetStatus(void);

uint8_t BSP_W25Qx_WriteEnable(void);

void BSP_W25Qx_Read_ID(uint8_t *ID);

uint8_t BSP_W25Qx_Read(uint8_t* pData, uint32_t ReadAddr, uint32_t Size);

uint8_t BSP_W25Qx_Write(uint8_t* pData, uint32_t WriteAddr, uint32_t Size);

uint8_t BSP_W25Qx_Erase_Block(uint32_t Address);

uint8_t BSP_W25Qx_Erase_Chip(void);


/**

  * @}

  */


/** @defgroup W25Q128FV_Exported_Functions

  * @{

  */ 

/**

  * @}

  */ 


/**

  * @}

  */ 


/**

  * @}

  */ 


/**

  * @}

  */


#ifdef __cplusplus

}

#endif


#endif /* __W25Qx_H */

案例

向0扇區(qū)(0塊0扇區(qū)),17扇區(qū)(1塊1扇區(qū)),34扇區(qū)(2塊2扇區(qū))分別寫入0x200的數(shù)據(jù)。


頭文件定義

/* USER CODE BEGIN Includes */

#include 'stdio.h'


#include 'W25Qx.h'

/* USER CODE END Includes */

串口接收和flash數(shù)組定義

#define SET_SPI0_NSS_HIGH          gpio_bit_set(GPIOD,GPIO_PIN_14);

#define SET_SPI0_NSS_LOW           gpio_bit_reset(GPIOD,GPIO_PIN_14);



#define BUFFERSIZE 255           //可以接收的最大字符個數(shù)       

uint8_t ReceiveBuff[BUFFERSIZE]; //接收緩沖區(qū)

uint8_t recv_end_flag = 0,Rx_len;//接收完成中斷標(biāo)志,接收到字符長度


uint8_t wData1[0x200];

uint8_t wData2[0x200];

uint8_t wData3[0x200];


uint8_t rData1[0x200];

uint8_t rData2[0x200];

uint8_t rData3[0x200];

uint8_t ID[4];

uint32_t i;


uint8_t flag[1] ;

int i_flag = 0;

void uart_data(void);

串口重定向

/* retarget the C library printf function to the USART */

int fputc(int ch, FILE *f)

{

    usart_data_transmit(USART0, (uint8_t)ch);

    while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));


    return ch;

}

串口中斷設(shè)置

/* 串口0中斷服務(wù)程序 */

void USART0_IRQHandler(void)    

{

    if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) //空閑中斷

    {

        usart_interrupt_flag_clear(USART0,USART_INT_FLAG_IDLE);    /* 清除空閑中斷標(biāo)志位 */

        usart_data_receive(USART0);                                /* 清除接收完成標(biāo)志位 */

        dma_channel_disable(DMA0, DMA_CH4);                        /* 關(guān)閉DMA傳輸 */

        uint32_t temp;

        temp  = dma_transfer_number_get(DMA0,DMA_CH4);//獲取DMA當(dāng)前還有多少未填充

    Rx_len =  BUFFERSIZE - temp; //計算串口接收到的數(shù)據(jù)個數(shù)

    recv_end_flag = 1;



//        USART_RX_NUM = sizeof(dma_buffer) - dma_transfer_number_get(DMA0,DMA_CH4);

//        printf('RECV %d date:%srn', USART_RX_NUM, dma_buffer);

//        memset(&dma_buffer ,'?',sizeof(dma_buffer));        

//        /* 重新設(shè)置DMA傳輸 */

//        dma_memory_address_config(DMA0,DMA_CH4,(uint32_t)dma_buffer);

//        dma_transfer_number_config(DMA0,DMA_CH4,sizeof(dma_buffer));

//        dma_channel_enable(DMA0, DMA_CH4);        /* 開啟DMA傳輸 */

    }

}

主程序

讀取ID和flash數(shù)據(jù)及擦除。


printf('GD Nor Flash案例n');


    /*##-1- Read the device ID  ########################*/ 

    BSP_W25Qx_Init();//鍒濆鍖朩25Q64

    BSP_W25Qx_Read_ID(ID);//璇誨彇ID

//get_DeviceId();

    if((ID[0] != 0xC8) | (ID[1] != 0x16))

    {

    printf('error');

    while(1);

//    Error_Handler();//濡傛灉 ID涓嶅鎵撳嵃閿欒

    }

    else//ID姝g‘錛屾墦鍗癐D

    {

        printf('W25Q64 ID : ');

        for(i=0;i< 2;i++)

        {

            printf('0x%02X ',ID[i]);

        }

        printf('rnrn');

    }


/**************************讀取第0扇區(qū)數(shù)據(jù)**************************************************************/


    /*##-3- Read the flash     ########################*/ 

    /*讀取數(shù)據(jù),rData讀取數(shù)據(jù)的指針,起始地址0x00,讀取數(shù)據(jù)長度0x200*/

    if(BSP_W25Qx_Read(rData1,0x0,0x200)== W25Qx_OK)

        printf('讀取原始的0個扇區(qū)數(shù)據(jù)成功!n');

    else

    {

        printf('error');

        while(1);

    }

    /*打印數(shù)據(jù)*/    

    printf('讀取原始的0個扇區(qū)數(shù)據(jù)為: rn');


    for(i =0;i< 0x200;i++)

    {

        if(i%20==0)

            printf('n0扇區(qū)第%d到%d的數(shù)據(jù)為:rn',i,i+19);

                printf('0x%02X  ',rData1[i]);

    }


    printf('n');



/**************************讀取第17扇區(qū)數(shù)據(jù)**************************************************************/


    /*##-3- Read the flash     ########################*/ 

    /*讀取數(shù)據(jù),rData讀取數(shù)據(jù)的指針,起始地址0x1000,讀取數(shù)據(jù)長度0x200*/

    if(BSP_W25Qx_Read(rData2,0x11000,0x200)== W25Qx_OK)

        printf('讀取原始的17個扇區(qū)數(shù)據(jù)成功!n');

[1] [2] [3] [4] [5] [6]
關(guān)鍵字:GD32F303  固件庫開發(fā)  SPI  Nor  Flash 引用地址:GD32F303固件庫開發(fā)(16)----移植兆易創(chuàng)新SPI Nor Flash之GD25Q64Flash

上一篇:基于GD32E503主控芯片實現(xiàn)直流數(shù)控電源的設(shè)計
下一篇:STM32CUBEMX開發(fā)GD32F303(2)----讀保護與寫保護

小廣播
設(shè)計資源 培訓(xùn) 開發(fā)板 精華推薦

最新單片機文章

 
EEWorld訂閱號

 
EEWorld服務(wù)號

 
汽車開發(fā)圈

 
機器人開發(fā)圈

電子工程世界版權(quán)所有 京ICP證060456號 京ICP備10001474號-1 電信業(yè)務(wù)審批[2006]字第258號函 京公網(wǎng)安備 11010802033920號 Copyright ? 2005-2025 EEWORLD.com.cn, Inc. All rights reserved