flash3 2.0.0.0
flash3.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef FLASH3_H
36#define FLASH3_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define FLASH3_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso= MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi= MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck= MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs= MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.hlo= MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.wp= MIKROBUS( mikrobus, MIKROBUS_PWM )
80#define FLASH3_RETVAL uint8_t
81
82#define FLASH3_OK 0x00
83#define FLASH3_INIT_ERROR 0xFF
90#define FLASH3_STATUS_WIP 0x01
91#define FLASH3_STATUS_WEL 0x02
92#define FLASH3_STATUS_BP_0 0x04
93#define FLASH3_STATUS_BP_1 0x08
94#define FLASH3_STATUS_BP_2 0x10
95#define FLASH3_STATUS_BP_3 0x20
96#define FLASH3_STATUS_QE 0x40
97#define FLASH3_STATUS_SRWD 0x80
104#define FLASH3_FUNC_TBS 0x02
105#define FLASH3_FUNC_PSUS 0x04
106#define FLASH3_FUNC_ESUS 0x08
107#define FLASH3_FUNC_IRL_0 0x10
108#define FLASH3_FUNC_IRL_1 0x20
109#define FLASH3_FUNC_IRL_2 0x40
110#define FLASH3_FUNC_IRL_3 0x80
117#define FLASH3_NOP 0x00
118#define FLASH3_WRSR 0x01
119#define FLASH3_PP 0x02
120#define FLASH3_WRDI 0x04
121#define FLASH3_RDSR 0x05
122#define FLASH3_WREN 0x06
123#define FLASH3_RDFR 0x48
124#define FLASH3_WRFR 0x42
125#define FLASH3_PERSUS 0x75
126#define FLASH3_PERRSM 0x7A
127#define FLASH3_DP 0xB9
128#define FLASH3_RDID 0xAB
129#define FLASH3_SRP 0xC0
130#define FLASH3_RDJDID 0x9F
131#define FLASH3_RDMDID 0x90
132#define FLASH3_RDJDIDQ 0xAF
133#define FLASH3_RDUID 0x4B
134#define FLASH3_RDSFDP 0x5A
135#define FLASH3_RSTEN 0x66
136#define FLASH3_RST 0x99
137#define FLASH3_IRER 0x64
138#define FLASH3_IRP 0x62
139#define FLASH3_IRRD 0x68
140#define FLASH3_SECUN_LOCK 0x26
141#define FLASH3_SECLOCK 0x24
148#define FLASH3_SECTOR_ER 0xD7
149#define FLASH3_BLOCK_ER32 0x52
150#define FLASH3_BLOCK_ER64 0xD8
151#define FLASH3_CHIP_ER 0xC7
158#define FLASH3_NORMAL_RD 0x03
159#define FLASH3_FAST_RD 0x0B
162 // End group macro
163// --------------------------------------------------------------- PUBLIC TYPES
172typedef struct
173{
174 // Output pins
175
176 digital_out_t hlo;
177 digital_out_t wp;
178 digital_out_t cs;
179
180 // Modules
181
182 spi_master_t spi;
183 pin_name_t chip_select;
184
185} flash3_t;
186
190typedef struct
191{
192 // Communication gpio pins
193
194 pin_name_t miso;
195 pin_name_t mosi;
196 pin_name_t sck;
197 pin_name_t cs;
198
199 // Additional gpio pins
200
201 pin_name_t hlo;
202 pin_name_t wp;
203
204 // static variable
205
206 uint32_t spi_speed;
207 spi_master_mode_t spi_mode;
208 spi_master_chip_select_polarity_t cs_polarity;
209
211
212 // End types group
213
214// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
215
220#ifdef __cplusplus
221extern "C"{
222#endif
223
233
243
255void flash3_generic_transfer ( flash3_t *ctx, uint8_t *wr_buf,
256 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
257
265void flash3_pause ( flash3_t *ctx );
266
275
284
293
302
311
320
329void flash3_write_cmd ( flash3_t *ctx, uint8_t cmd );
330
341void flash3_write_adv_cmd ( flash3_t *ctx, uint8_t cmd, uint8_t *arg, uint32_t cnt );
342
351
359void flash3_wr_stat_reg ( flash3_t *ctx, uint8_t status );
360
369
378void flash3_wr_func_reg ( flash3_t *ctx, uint8_t function );
379
390void flash3_normal_read( flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt );
391
402void flash3_fast_read ( flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt );
403
414void flash3_write ( flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt );
415
424
433void flash3_sector_erase ( flash3_t *ctx, uint32_t address );
434
443void flash3_block32_erase( flash3_t *ctx, uint32_t address );
444
453void flash3_block64_erase( flash3_t *ctx, uint32_t address );
454
455
456#ifdef __cplusplus
457}
458#endif
459#endif // _FLASH3_H_
460
461 // End public_function group
463
464// ------------------------------------------------------------------------- END
#define FLASH3_RETVAL
Definition flash3.h:80
void flash3_generic_transfer(flash3_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void flash3_write_cmd(flash3_t *ctx, uint8_t cmd)
Write command function.
void flash3_normal_read(flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt)
Normal data read function.
void flash3_block64_erase(flash3_t *ctx, uint32_t address)
Block 64 erase function.
void flash3_wr_prot_enable(flash3_t *ctx)
Write Protect enable function.
void flash3_write(flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt)
Fast data read function.
void flash3_wr_prot_disable(flash3_t *ctx)
Disable write function.
void flash3_write_disable(flash3_t *ctx)
Enable write function.
FLASH3_RETVAL flash3_init(flash3_t *ctx, flash3_cfg_t *cfg)
Initialization function.
void flash3_fast_read(flash3_t *ctx, uint32_t addr, uint8_t *buff, uint32_t cnt)
Fast data read function.
void flash3_cfg_setup(flash3_cfg_t *cfg)
Config Object Initialization function.
void flash3_write_adv_cmd(flash3_t *ctx, uint8_t cmd, uint8_t *arg, uint32_t cnt)
Flash 3 Command Advanced function.
void flash3_pause(flash3_t *ctx)
Pause function.
uint8_t flash3_rd_stat_reg(flash3_t *ctx)
Reads Status Register function.
void flash3_block32_erase(flash3_t *ctx, uint32_t address)
Block 32 erase function.
void flash3_chip_erase(flash3_t *ctx)
Chip erase function.
void flash3_wr_stat_reg(flash3_t *ctx, uint8_t status)
Write Status Register function.
void flash3_wr_func_reg(flash3_t *ctx, uint8_t function)
Reads Function Register function.
uint8_t flash3_rd_func_reg(flash3_t *ctx)
Reads Function Register function.
void flash3_write_enable(flash3_t *ctx)
Enable write function.
void flash3_setting(flash3_t *ctx)
Initialisation function.
void flash3_unpause(flash3_t *ctx)
Unpause function.
void flash3_sector_erase(flash3_t *ctx, uint32_t address)
Sector erase function.
Click configuration structure definition.
Definition flash3.h:191
pin_name_t hlo
Definition flash3.h:201
spi_master_chip_select_polarity_t cs_polarity
Definition flash3.h:208
pin_name_t sck
Definition flash3.h:196
spi_master_mode_t spi_mode
Definition flash3.h:207
pin_name_t mosi
Definition flash3.h:195
uint32_t spi_speed
Definition flash3.h:206
pin_name_t wp
Definition flash3.h:202
pin_name_t miso
Definition flash3.h:194
pin_name_t cs
Definition flash3.h:197
Click ctx object definition.
Definition flash3.h:173
digital_out_t cs
Definition flash3.h:178
spi_master_t spi
Definition flash3.h:182
digital_out_t hlo
Definition flash3.h:176
pin_name_t chip_select
Definition flash3.h:183
digital_out_t wp
Definition flash3.h:177