flash2 2.0.0.0
flash2.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 FLASH2_H
36#define FLASH2_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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define FLASH2_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
77#define FLASH2_STATUS_WEL 0x02
78#define FLASH2_STATUS_WSE 0x04
79#define FLASH2_STATUS_WSP 0x08
80#define FLASH2_STATUS_WPLD 0x10
81#define FLASH2_STATUS_SEC 0x20
82#define FLASH2_STATUS_RES 0x40
83#define FLASH2_STATUS_BUSY 0x80
84
85
86#define FLASH2_CFG_RES 0x01
87#define FLASH2_CFG_IOC 0x02
88#define FLASH2_CFG_BPNV 0x08
89#define FLASH2_CFG_WPEN 0x80
90
91
92#define FLASH2_INSTR_NOP 0x00
93#define FLASH2_INSTR_RSTEN 0x66
94#define FLASH2_INSTR_RST 0x99
95#define FLASH2_INSTR_EQIO 0x38
96#define FLASH2_INSTR_RSTQIO 0xFF
97#define FLASH2_INSTR_RDSR 0x05
98#define FLASH2_INSTR_WRSR 0x01
99#define FLASH2_INSTR_RDCR 0x35
100#define FLASH2_INSTR_READ 0x03
101#define FLASH2_INSTR_HS_READ 0x0B
102#define FLASH2_INSTR_SQOR 0x6B
103#define FLASH2_INSTR_SQIOR 0xEB
104#define FLASH2_INSTR_SDOR 0x3B
105#define FLASH2_INSTR_SDIOR 0xBB
106#define FLASH2_INSTR_SB 0xC0
107#define FLASH2_INSTR_RBSQI 0x0C
108#define FLASH2_INSTR_RBSPI 0xEC
109#define FLASH2_INSTR_JEDECID 0x9F
110#define FLASH2_INSTR_QUAD_JID 0xAF
111#define FLASH2_INSTR_SFDP 0x5A
112#define FLASH2_INSTR_WREN 0x06
113#define FLASH2_INSTR_WRDI 0x04
114#define FLASH2_INSTR_SE 0x20
115#define FLASH2_INSTR_BE 0xD8
116#define FLASH2_INSTR_CE 0xC7
117#define FLASH2_INSTR_PP 0x02
118#define FLASH2_INSTR_SPI_QUAD 0x32
119#define FLASH2_INSTR_WRSU 0xB0
120#define FLASH2_INSTR_WRRE 0x30
121#define FLASH2_INSTR_RBPR 0x72
122#define FLASH2_INSTR_WBPR 0x42
123#define FLASH2_INSTR_LBPR 0x8D
124#define FLASH2_INSTR_NVWLDR 0xE8
125#define FLASH2_INSTR_ULBPR 0x98
126#define FLASH2_INSTR_RSID 0x88
127#define FLASH2_INSTR_PSID 0xA5
128#define FLASH2_INSTR_LSID 0x85
131#define FLASH2_START_PAGE_ADDRESS 0x010000
132#define FLASH2_END_PAGE_ADDRESS 0x7FFFFF
133#define FLASH2_FLASH_PAGE_SIZE 256
138#define FLASH2_RETVAL uint8_t
139
140#define FLASH2_OK 0x00
141#define FLASH2_INIT_ERROR 0xFF
144 // End group macro
145// --------------------------------------------------------------- PUBLIC TYPES
154typedef struct
155{
156 digital_out_t cs;
157
158 // Output pins
159
160 digital_out_t hld;
161 digital_out_t wp;
162
163 // Modules
164
165 spi_master_t spi;
166 pin_name_t chip_select;
167
168} flash2_t;
169
173typedef struct
174{
175 // Communication gpio pins
176
177 pin_name_t miso;
178 pin_name_t mosi;
179 pin_name_t sck;
180 pin_name_t cs;
181
182 // Additional gpio pins
183
184 pin_name_t hld;
185 pin_name_t wp;
186
187 // static variable
188
189 uint32_t spi_speed;
190 spi_master_mode_t spi_mode;
191 spi_master_chip_select_polarity_t cs_polarity;
192
194
195 // End types group
196// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
197
202#ifdef __cplusplus
203extern "C"{
204#endif
205
215
225
237void flash2_generic_transfer ( flash2_t *ctx, uint8_t *wr_buf,
238 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
239
250uint8_t flash2_busy( flash2_t *ctx );
251
263
273
285
297
309
320
332
342
352
362
372
397
398
422
432void flash2_spi_get_security_id( flash2_t *ctx, uint8_t *buffer, uint32_t data_count);
433
444void flash2_sqi_get_security_id( flash2_t *ctx, uint8_t *buffer, uint32_t data_count);
445
461void flash2_set_security_id( flash2_t *ctx, uint8_t *buffer, uint32_t data_count );
462
473
486void flash2_spi_get_bpr( flash2_t *ctx, uint8_t *buffer, uint32_t data_count );
487
500void flash2_sqi_get_bpr( flash2_t *ctx, uint8_t *buffer, uint32_t data_count );
501
512void flash2_set_bpr( flash2_t *ctx, uint8_t *buffer );
513
527
539void flash2_nonvolatile_write_lock( flash2_t *ctx, uint8_t *buffer);
540
553
576void flash2_read_generic( flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count );
577
594void flash2_highspeedRread( flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count );
595
614void flash2_quadWrite( flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count );
615
633void flash2_write_generic( flash2_t *ctx, uint32_t address, uint8_t *buffer,
634 uint32_t data_count );
635
651
668void flash2_quad_out_read( flash2_t *ctx, uint32_t address, uint8_t *buffer,
669 uint32_t data_count);
670
688void flash2_quad_io_read( flash2_t *ctx, uint32_t address, uint8_t mode, uint8_t *buffer, uint32_t data_count);
689
710
730void flash2_set_burst( flash2_t *ctx, uint8_t length );
731
758void flash2_read_sqi_burst_wrap( flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count );
759
788void flash2_read_spi_burst_wrap( flash2_t *ctx, uint32_t address, uint8_t *buffer,
789 uint32_t data_count );
790
804void flash2_read_dual_output( flash2_t *ctx, uint32_t address, uint8_t *buffer,
805 uint32_t data_count );
806
846void flash2_read_dual_io ( flash2_t *ctx, uint32_t address, uint8_t *buffer,
847 uint32_t data_count );
848
860void flash2_sector_erase( flash2_t *ctx, uint32_t address );
861
876void flash2_block_erase( flash2_t *ctx, uint32_t address );
877
890
907void flash2_get_sfdp_params( flash2_t *ctx, uint32_t address, uint8_t *buffer,
908 uint32_t data_count );
909
923
937
951
965
979
993
1005
1015void flash2_write_status_reg( flash2_t *ctx, uint8_t s_reg );
1016
1028
1039
1040#ifdef __cplusplus
1041}
1042#endif
1043#endif // _FLASH2_H_
1044
1045 // End public_function group
1047
1048// ------------------------------------------------------------------------- END
#define FLASH2_RETVAL
Definition flash2.h:138
void flash2_sqi_get_bpr(flash2_t *ctx, uint8_t *buffer, uint32_t data_count)
Flash 2 Get Block Protection Register SQI.
void flash2_hold_disable(flash2_t *ctx)
Flash 2 Hold Disable.
uint8_t flash2_device_type(flash2_t *ctx)
Flash 2 Device Type.
uint8_t flash2_quad_device_type(flash2_t *ctx)
Flash 2 Quad Device Type.
void flash2_generic_transfer(flash2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void flash2_set_security_id(flash2_t *ctx, uint8_t *buffer, uint32_t data_count)
Flash 2 Set Security ID.
void flash2_spi_get_security_id(flash2_t *ctx, uint8_t *buffer, uint32_t data_count)
Flash 2 Get Security ID SPI.
void flash2_read_spi_burst_wrap(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Read Burst with Wrap through SPI.
void flash2_set_bpr(flash2_t *ctx, uint8_t *buffer)
Flash 2 Set Block Protection Register.
uint8_t flash2_write_status(flash2_t *ctx)
Flash 2 Write Status.
void flash2_quad_reset(flash2_t *ctx)
Flash 2 Quad Reset.
uint8_t flash2_device_id(flash2_t *ctx)
Flash 2 Device ID.
void flash2_nonvolatile_write_lock(flash2_t *ctx, uint8_t *buffer)
Flash 2 Non-Volatile Write-Lock.
void flash2_cfg_setup(flash2_cfg_t *cfg)
Config Object Initialization function.
void flash2_read_dual_io(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Read Dual I/O.
void flash2_set_burst(flash2_t *ctx, uint8_t length)
Flash 2 Set Burst.
void flash2_block_erase(flash2_t *ctx, uint32_t address)
Flash 2 Block Erase.
void flash2_sector_erase(flash2_t *ctx, uint32_t address)
Flash 2 Sector Erase.
void flash2_sqi_get_security_id(flash2_t *ctx, uint8_t *buffer, uint32_t data_count)
Flash 2 Get Security ID SQI.
void flash2_quad_io_read(flash2_t *ctx, uint32_t address, uint8_t mode, uint8_t *buffer, uint32_t data_count)
Flash 2 Quad I/O Read.
void flash2_read_sqi_burst_wrap(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Read Burst with Wrap through SQI.
void flash2_chip_erase(flash2_t *ctx)
Flash 2 Chip Erase.
uint8_t flash2_program_status(flash2_t *ctx)
Flash 2 Program Status.
void flash2_write_generic(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Write.
FLASH2_RETVAL flash2_init(flash2_t *ctx, flash2_cfg_t *cfg)
Initialization function.
void flash2_write_enable(flash2_t *ctx)
Flash 2 Write Enable.
void flash2_lockBpr(flash2_t *ctx)
Flash 2 Lock Block Protection Register.
void flash2_quad_out_read(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Quad Output Read.
uint8_t flash2_get_config_reg(flash2_t *ctx)
Flash 2 Get Config Register.
void flash2_get_sfdp_params(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 get Serial Flash Discoverable \ Parameters.
void flash2_spi_get_bpr(flash2_t *ctx, uint8_t *buffer, uint32_t data_count)
Flash 2 Get Block Protection Register SPI.
uint8_t flash2_erase_status(flash2_t *ctx)
Flash 2 Erase Status.
void flash2_write_protect_enable(flash2_t *ctx)
Flash 2 Write Protect Enable.
void flash2_write_protect_disable(flash2_t *ctx)
Flash 2 Write Protect Disable.
void flash2_write_resume(flash2_t *ctx)
Flash 2 Write Resume.
void flash2_highspeedRread(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 High Speed Read.
void flash2_quadWrite(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Quad Write.
void flash2_quad_enable(flash2_t *ctx)
Flash 2 Quad Enable.
void flash2_global_block_unlock(flash2_t *ctx)
Flash 2 Global Block Unlock.
void flash2_hold_enable(flash2_t *ctx)
Flash 2 Hold Enable.
void flash2_lock_security_id(flash2_t *ctx)
flash2_lock_security_id
void flash2_write_status_reg(flash2_t *ctx, uint8_t s_reg)
Flash 2 Write Status Register.
uint8_t flash2_busy(flash2_t *ctx)
Flash 2 Busy.
void flash2_write_disable(flash2_t *ctx)
Flash 2 Write Disable.
void flash2_reset(flash2_t *ctx)
Flash 2 Reset.
void flash2_write_suspend(flash2_t *ctx)
Flash 2 Write Suspend.
uint8_t flash2_quad_device_id(flash2_t *ctx)
Flash 2 Quad Device ID.
uint8_t flash2_quad_device_manufac(flash2_t *ctx)
Flash 2 Quad Device Manufacturer.
uint8_t flash2_device_manufac(flash2_t *ctx)
Flash 2 Device Manufacturer.
uint8_t flash2_security_status(flash2_t *ctx)
Flash 2 Security Status.
uint8_t flash2_get_status_reg(flash2_t *ctx)
Flash 2 Get Status Register.
void flash2_read_dual_output(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Read Dual Output.
void flash2_read_generic(flash2_t *ctx, uint32_t address, uint8_t *buffer, uint32_t data_count)
Flash 2 Read.
uint8_t flash2_protect_status(flash2_t *ctx)
Flash 2 Protect Status.
Click configuration structure definition.
Definition flash2.h:174
pin_name_t hld
Definition flash2.h:184
spi_master_chip_select_polarity_t cs_polarity
Definition flash2.h:191
pin_name_t sck
Definition flash2.h:179
spi_master_mode_t spi_mode
Definition flash2.h:190
pin_name_t mosi
Definition flash2.h:178
uint32_t spi_speed
Definition flash2.h:189
pin_name_t wp
Definition flash2.h:185
pin_name_t miso
Definition flash2.h:177
pin_name_t cs
Definition flash2.h:180
Click ctx object definition.
Definition flash2.h:155
digital_out_t cs
Definition flash2.h:156
digital_out_t hld
Definition flash2.h:160
spi_master_t spi
Definition flash2.h:165
pin_name_t chip_select
Definition flash2.h:166
digital_out_t wp
Definition flash2.h:161