Spi-Flash-ex
SPI Flash Ex Tension库将闪光记忆的集合合并为MCU中的存储库
- Notice : This library has not free in this time
发布
概述
初始化和去原始化功能:
uint8_t SPI_FlashEx_Init (SPI_Flash_BankTypeDef *_flashBank);
操作功能:
/* :::::::::::::::::::: Flash Erase :::::::::::::::::::: */ uint8_t SPI_FlashEx_ChipErase (SPI_Flash_BankTypeDef *_flashBank); uint8_t SPI_FlashEx_SectorErase (SPI_Flash_BankTypeDef *_flashBank, uint32_t _sector); uint8_t SPI_FlashEx_BlockErase (SPI_Flash_BankTypeDef *_flashBank, uint32_t _block); /* :::::::::::::::::::: Flash Write :::::::::::::::::::: */ uint8_t SPI_FlashEx_Write (SPI_Flash_BankTypeDef *_flashBank, uint8_t _data, uint32_t _address); uint8_t SPI_FlashEx_PageWrite (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _page, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_SectorWrite (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _sector, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_BlockWrite (SPI_Flash_BankTypeDef *_flashBank, uint8_t * _pData, uint32_t _block, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_BurstWrite (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _address, uint32_t _size); /* :::::::::::::::::::: Flash Read ::::::::::::::::::::: */ uint8_t SPI_FlashEx_Read (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_data, uint32_t _address); uint8_t SPI_FlashEx_PageRead (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _page, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_SectorRead (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _sector, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_BlockRead (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _block, uint32_t _offset, uint32_t _size); uint8_t SPI_FlashEx_BurstRead (SPI_Flash_BankTypeDef *_flashBank, uint8_t *_pData, uint32_t _address, uint32_t _size);
宏:
None
指导
该库可用如下:
1。添加SPI Flash库作为基础库并进行配置
2。在项目中添加SPI Flash Ex tension库标头和源文件
3。在“ spi_flash_ex_conf.h”中配置库,例如:
/* ----------- Configuration ------------ */ # define _SPI_FLASH_EX_USE_LAST_WRITE_ADD
4。创建闪存对象的数组,设置特定的GPIO,例如:
- 例子:
SPI_Flash_TypeDef MainFlashList[ 3 ]; MainFlashList[ 0 ].CS_GPIO_Port = 0 ; MainFlashList[ 0 ].CS_GPIO_Pin = ( 1 << 2 ); MainFlashList[ 1 ].CS_GPIO_Port = 0 ; MainFlashList[ 1 ].CS_GPIO_Pin = ( 1 << 3 ); MainFlashList[ 2 ].CS_GPIO_Port = 0 ; MainFlashList[ 2 ].CS_GPIO_Pin = ( 1 << 4 );
5。创建闪存库对象,设置flashlist,numberofchip并初始化它,例如:
-
初始化器:
SPI_FlashEx_Init (SPI_Flash_BankTypeDef *_flashBank); -
参数:
- _flashbank:指向Flash Bank结构的指针
-
例子:
Code of step 4 ... SPI_Flash_BankTypeDef FlashBank; FlashBank.FlashList = MainFlashList; FlashBank.NumberOfChip = 3 ; SPI_FlashEx_Init (&FlashBank);
6。使用闪存扩展操作功能
SPI_FlashEx_ChipErase (&FlashBank); SPI_FlashEx_SectorWrite (&FlashBank, Tx_Buf, 0 , 10 , 44 );
例子
示例1:与LPC1768初始化并使用外部闪存
# include \" lpc17xx.h \" # include \" lpc17xx_gpio.h \" # include \" lpc17xx_spi.h \" # include \" lpc17xx_libcfg.h \" # include \" lpc17xx_pinsel.h \" # include \" lpc_spi_ex.h \" # include \" spi_flash.h \" SPI_CFG_Type SPI_ConfigStruct; uint8_t Tx_Buf[ 44 ] = \" Hello from master!, this is an test program \\n \" ; uint8_t Rx_Buf[ 50 ]; int main () { SystemInit (); /* ---------- Setup GPIO --------- */ PINSEL_CFG_Type PinCfg; /* * Initialize SPI pin connect * P0.15 - SCK; * P0.0 / P0.1 - SSEL - used as GPIO * P0.17 - MISO * P0.18 - MOSI */ PinCfg. Funcnum = 3 ; PinCfg. OpenDrain = 0 ; PinCfg. Pinmode = 0 ; PinCfg. Portnum = 0 ; PinCfg. Pinnum = 15 ; PINSEL_ConfigPin (&PinCfg); PinCfg. Pinnum = 17 ; PINSEL_ConfigPin (&PinCfg); PinCfg. Pinnum = 18 ; PINSEL_ConfigPin (&PinCfg); /* Set GPIO Direction */ GPIO_SetDir ( 0 , ( 1 << 16 ), 1 ); GPIO_SetDir ( 0 , ( 1 << 19 ), 1 ); GPIO_SetDir ( 0 , ( 1 << 7 ), 1 ); GPIO_SetValue ( 0 , ( 1 << 16 )); GPIO_SetValue ( 0 , ( 1 << 19 )); GPIO_SetValue ( 0 , ( 1 << 7 )); /* ---------- Setup SPI ---------- */ SPI_ConfigStruct. CPHA = SPI_CPHA_FIRST; SPI_ConfigStruct. CPOL = SPI_CPOL_HI; SPI_ConfigStruct. ClockRate = 300000 ; SPI_ConfigStruct. DataOrder = SPI_DATA_MSB_FIRST; SPI_ConfigStruct. Databit = SPI_DATABIT_8; SPI_ConfigStruct. Mode = SPI_MASTER_MODE; SPI_Init (LPC_SPI, &SPI_ConfigStruct); /* --------- Wait to init --------- */ SPI_Delay ( 1 ); /* ~~~~~~~~~~~~~~~~ Flash Bank Example ~~~~~~~~~~~~~~ */ /* --------- Setup Flash ---------- */ SPI_Flash_TypeDef MainFlashList[ 3 ]; SPI_Flash_BankTypeDef FlashBank; MainFlashList[ 0 ]. CS_GPIO_Port = 0 ; MainFlashList[ 0 ]. CS_GPIO_Pin = ( 1 << 16 ); MainFlashList[ 1 ]. CS_GPIO_Port = 0 ; MainFlashList[ 1 ]. CS_GPIO_Pin = ( 1 << 19 ); MainFlashList[ 2 ]. CS_GPIO_Port = 0 ; MainFlashList[ 2 ]. CS_GPIO_Pin = ( 1 << 7 ); FlashBank. FlashList = MainFlashList; FlashBank. NumberOfChip = 3 ; /* ----------- Commands ----------- */ SPI_FlashEx_Init (&FlashBank); SPI_FlashEx_ChipErase (&FlashBank); SPI_FlashEx_SectorWrite (&FlashBank, Tx_Buf, 0 , 10 , 44 ); SPI_FlashEx_SectorRead (&FlashBank, Rx_Buf, 0 , 10 , 44 ); while ( 1 ) { } /* Loop forever */ }
进行的测试:
- 在LPC17 XX核心上运行
- 在STM32 FX内核上运行
开发人员:
-
Majid Derhambakhsh
