凌云物联网实验室ISKBoard(IoT Starter Kits Board)开发板项目源码
guowenxue
2023-04-04 5937444d8c50fd85f603fae272f46bf10679fe28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**********************************************************************
*   Copyright: (C)2023 LingYun IoT System Studio
*      Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
* Description: ISKBoard W25Qxx SPI norflash Hardware Abstract Layer driver
*
*   ChangeLog:
*        Version    Date       Author            Description
*        V1.0.0  2023.04.3    GuoWenxue      Release initial version
***********************************************************************/
#ifndef _w25Q32_H
#define _W25Q32_H
 
#include "stm32l4xx_hal.h"
 
typedef enum
{
    W25Q80,
    W25Q16,
    W25Q32,
} w25q_chip_t;
 
typedef enum
{
    REG_SR1=1,
    REG_SR2,
    REG_SR3,
} w25q_sreg_t;
 
typedef struct flash_info_s
{
    char        *name;       /* Chip name */
    uint32_t     id;         /* JEDEC ID  */
    uint32_t     pagesize;   /* page size */
    uint32_t     npages;     /* page count */
    uint32_t     sectorsize; /* sector size */
    uint32_t     nsectors;   /* sector count */
    uint32_t     blocksize;  /* block size */
    uint32_t     nblocks;    /* block count */
} flash_info_t;
 
extern flash_info_t   *w25q;
 
int w25q_Init(void);
void w25q_EraseChip(void);
void w25q_EraseSector(uint32_t SectorAddr);
void w25q_EraseBlock(uint32_t BlockAddr);
 
uint32_t w25q_PageToSector(uint32_t PageAddress);
uint32_t w25q_PageToBlock(uint32_t PageAddress);
uint32_t w25q_SectorToBlock(uint32_t SectorAddress);
uint32_t w25q_SectorToPage(uint32_t SectorAddress);
uint32_t w25q_BlockToPage(uint32_t BlockAddress);
 
int w25q_IsEmptyPage(uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_PageSize);
int w25q_IsEmptySector(uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_SectorSize);
int w25q_IsEmptyBlock(uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToCheck_up_to_BlockSize);
 
void w25q_WriteByte(uint8_t pBuffer, uint32_t Bytes_Address);
void w25q_WritePage(uint8_t *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_PageSize);
void w25q_WriteSector(uint8_t *pBuffer, uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_SectorSize);
void w25q_WriteBlock(uint8_t *pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToWrite_up_to_BlockSize);
 
void w25q_ReadByte(uint8_t *pBuffer, uint32_t Bytes_Address);
void w25q_ReadBytes(uint8_t *pBuffer, uint32_t ReadAddr, uint32_t NumByteToRead);
void w25q_ReadPage(uint8_t *pBuffer, uint32_t Page_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_PageSize);
void w25q_ReadSector(uint8_t *pBuffer, uint32_t Sector_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_SectorSize);
void w25q_ReadBlock(uint8_t *pBuffer, uint32_t Block_Address, uint32_t OffsetInByte, uint32_t NumByteToRead_up_to_BlockSize);
 
#endif