flash4  2.0.0.0
flash4.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 FLASH4_H
36 #define FLASH4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define FLASH4_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59  cfg.io2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60  cfg.io3 = MIKROBUS( mikrobus, MIKROBUS_INT )
61 
67 #define FLASH4_RETVAL uint8_t
68 
69 #define FLASH4_OK 0x00
70 #define FLASH4_INIT_ERROR 0xFF
71 
76 #define FLASH4_MANUFACTURER_ID 0x01
77 #define FLASH4_DEVICE_ID 0x19
78 
83 #define FLASH4_CMD_READ_ID 0x90
84 #define FLASH4_CMD_READ_IDENTIFICATION 0x9F
85 #define FLASH4_CMD_READ_ELECTRONIC_SIGNATURE 0xAB
86 #define FLASH4_CMD_READ_SERIAL_FLASH_PARAMETERS 0x5A
87 #define FLASH4_CMD_READ_STATUS_REG_1 0x05
88 #define FLASH4_CMD_READ_STATUS_REG_2 0x07
89 #define FLASH4_CMD_READ_CONFIGURATION_REG 0x35
90 #define FLASH4_CMD_READ_BANK_REG 0x16
91 #define FLASH4_CMD_WRITE_BANK_REG 0x17
92 #define FLASH4_CMD_ACCESS_BANK_REG 0xB9
93 #define FLASH4_CMD_WRITE_REGISTER_WRR 0x01
94 #define FLASH4_CMD_WRITE_ENABLE_WREN 0x06
95 #define FLASH4_CMD_WRITE_DISABLE_WRDI 0x04
96 #define FLASH4_CMD_CLEAR_STATUS_REG 0x30
97 #define FLASH4_CMD_READ_ECC_STATUS_REG 0x18
98 #define FLASH4_CMD_READ_AUTO_BOOT_REG 0x14
99 #define FLASH4_CMD_WRITE_AUTO_BOOT_REG 0x15
100 #define FLASH4_CMD_PROGRAM_NVDLR 0x43
101 #define FLASH4_CMD_WRITE_VDLR 0x4A
102 #define FLASH4_CMD_READ_DATA_LEARNING_PATTERN 0x41
103 #define FLASH4_CMD_READ_FLASH 0x03
104 #define FLASH4_CMD_4READ_FLASH 0x13
105 #define FLASH4_CMD_FAST_READ_FLASH 0x0B
106 #define FLASH4_CMD_FAST_4READ_FLASH 0x0C
107 #define FLASH4_CMD_FAST_READ_DDR 0x0D
108 #define FLASH4_CMD_FAST_4READ_DDR 0x0E
109 #define FLASH4_CMD_PAGE_PROGRAM 0x02
110 #define FLASH4_CMD_PAGE_4PROGRAM 0x12
111 #define FLASH4_CMD_PROGRAM_SUSPEND 0x85
112 #define FLASH4_CMD_PROGRAM_RESUME 0x8A
113 #define FLASH4_CMD_SECTOR_ERASE 0xD8
114 #define FLASH4_CMD_SECTOR_4ERASE 0xDC
115 #define FLASH4_CMD_BULK_ERASE 0xC7
116 #define FLASH4_CMD_ERASE_SUSPEND 0x75
117 #define FLASH4_CMD_ERASE_RESUME 0x7A
118 #define FLASH4_CMD_WRITE_OTP_PROGRAM 0x42
119 #define FLASH4_CMD_READ_OTP 0x4B
120 #define FLASH4_CMD_READ_ASP 0x2B
121 #define FLASH4_CMD_WRITE_ASP_PROGRAM 0x2F
122 #define FLASH4_CMD_READ_DYB 0xE0
123 #define FLASH4_CMD_WRITE_DYB 0xE1
124 #define FLASH4_CMD_READ_PPB 0xE2
125 #define FLASH4_CMD_WRITE_PPB 0xE3
126 #define FLASH4_CMD_ERASE_PPB 0xE4
127 #define FLASH4_CMD_READ_PPB_LOCK_BIT 0xA7
128 #define FLASH4_CMD_WRITE_PPB_LOCK_BIT 0xA6
129 #define FLASH4_CMD_SOFTWARE_RESET 0xF0
130 #define FLASH4_CMD_MODE_BIT_RESET 0xFF
131  // End group macro
133 // --------------------------------------------------------------- PUBLIC TYPES
142 typedef struct
143 {
144  // Output pins
145 
146  digital_out_t cs;
147  digital_out_t rst;
148  digital_out_t io3;
149  digital_out_t io2;
150 
151  // Modules
152 
153  spi_master_t spi;
154  pin_name_t chip_select;
155 
156 } flash4_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t miso;
166  pin_name_t mosi;
167  pin_name_t sck;
168  pin_name_t cs;
169 
170  // Additional gpio pins
171 
172  pin_name_t rst;
173  pin_name_t io2;
174  pin_name_t io3;
175 
176  // static variable
177 
178  uint32_t spi_speed;
179  spi_master_mode_t spi_mode;
180  spi_master_chip_select_polarity_t cs_polarity;
181 
182 } flash4_cfg_t;
183  // End types group
185 
186 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
204 void flash4_cfg_setup ( flash4_cfg_t *cfg );
205 
215 
227 void flash4_generic_transfer ( flash4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
228 
237 void flash4_read_manufacturer_id ( flash4_t *ctx, uint8_t *device_id );
238 
248 void flash4_read_identification ( flash4_t *ctx, uint8_t *out_data, uint8_t n_data );
249 
250 
258 uint8_t flash4_read_electronic_id ( flash4_t *ctx );
259 
269 void flash4_read_serial_flash_parameters ( flash4_t *ctx, uint8_t *out_params, uint8_t c );
270 
279 uint8_t flash4_read_byte ( flash4_t *ctx, uint8_t reg );
280 
290 void flash4_write_byte ( flash4_t *ctx, uint8_t reg, uint8_t data_buff );
291 
300 void flash4_write_command ( flash4_t *ctx, uint8_t cmd );
301 
311 void flash4_write_reg ( flash4_t *ctx, uint8_t status, uint8_t config );
312 
322 void flash4_read_ecc ( flash4_t *ctx, uint8_t *out_ecc, uint8_t n_dummy);
323 
332 void flash4_read_auto_boot ( flash4_t *ctx, uint8_t *out_ab );
333 
344 void flash4_read_flash( flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data);
345 
356 void flash4_read_flash_4 ( flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data );
357 
368 void flash4_fast_read_flash ( flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data_dummy);
369 
380 void flash4_fast_read_flash_4 ( flash4_t *ctx, uint8_t *out_data,uint8_t addr, uint8_t n_data );
381 
392 void flash4_page_program_4 ( flash4_t *ctx, uint8_t *in_data, uint32_t addr, uint8_t n_data );
393 
402 void flash4_sector_erase ( flash4_t *ctx, uint32_t addr );
403 
412 void flash4_sector_erase_4( flash4_t *ctx, uint32_t addr );
413 
421 uint8_t flash4_check_wip ( flash4_t *ctx );
422 
430 uint8_t flash4_check_wel ( flash4_t *ctx );
431 
439 uint8_t flash4_check_ps ( flash4_t *ctx );
440 
448 uint8_t flash4_check_es ( flash4_t *ctx );
449 
457 void flash4_reset ( flash4_t *ctx );
458 
459 #ifdef __cplusplus
460 }
461 #endif
462 #endif // _FLASH4_H_
463  // End public_function group
466 
467 // ------------------------------------------------------------------------- END
flash4_t::chip_select
pin_name_t chip_select
Definition: flash4.h:154
flash4_read_ecc
void flash4_read_ecc(flash4_t *ctx, uint8_t *out_ecc, uint8_t n_dummy)
Read ECC Status Register function.
flash4_read_manufacturer_id
void flash4_read_manufacturer_id(flash4_t *ctx, uint8_t *device_id)
Read Manufacturer ID function.
flash4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash4.h:180
flash4_write_byte
void flash4_write_byte(flash4_t *ctx, uint8_t reg, uint8_t data_buff)
Write one byte to register function.
flash4_check_es
uint8_t flash4_check_es(flash4_t *ctx)
Function for es.
flash4_fast_read_flash
void flash4_fast_read_flash(flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data_dummy)
Fast read Flash function.
flash4_reset
void flash4_reset(flash4_t *ctx)
Function for reset.
flash4_cfg_setup
void flash4_cfg_setup(flash4_cfg_t *cfg)
Config Object Initialization function.
flash4_t::cs
digital_out_t cs
Definition: flash4.h:146
flash4_read_serial_flash_parameters
void flash4_read_serial_flash_parameters(flash4_t *ctx, uint8_t *out_params, uint8_t c)
Read Serial Flash Discoverable Parameters function.
flash4_read_auto_boot
void flash4_read_auto_boot(flash4_t *ctx, uint8_t *out_ab)
Read AutoBoot Register function.
flash4_cfg_t::mosi
pin_name_t mosi
Definition: flash4.h:166
flash4_page_program_4
void flash4_page_program_4(flash4_t *ctx, uint8_t *in_data, uint32_t addr, uint8_t n_data)
Write data to address with 4 byte address function.
flash4_check_wip
uint8_t flash4_check_wip(flash4_t *ctx)
Function for wip.
flash4_cfg_t::sck
pin_name_t sck
Definition: flash4.h:167
flash4_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash4.h:178
FLASH4_RETVAL
#define FLASH4_RETVAL
Definition: flash4.h:67
flash4_cfg_t::rst
pin_name_t rst
Definition: flash4.h:172
flash4_check_wel
uint8_t flash4_check_wel(flash4_t *ctx)
Function for wel.
flash4_init
FLASH4_RETVAL flash4_init(flash4_t *ctx, flash4_cfg_t *cfg)
Initialization function. *.
flash4_t::rst
digital_out_t rst
Definition: flash4.h:147
flash4_cfg_t::io3
pin_name_t io3
Definition: flash4.h:174
flash4_t::spi
spi_master_t spi
Definition: flash4.h:153
flash4_t::io2
digital_out_t io2
Definition: flash4.h:149
flash4_cfg_t::io2
pin_name_t io2
Definition: flash4.h:173
flash4_read_flash_4
void flash4_read_flash_4(flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data)
Read Flash with 4 byte address function.
flash4_cfg_t
Click configuration structure definition.
Definition: flash4.h:161
flash4_cfg_t::cs
pin_name_t cs
Definition: flash4.h:168
flash4_t
Click ctx object definition.
Definition: flash4.h:142
flash4_check_ps
uint8_t flash4_check_ps(flash4_t *ctx)
Function for ps.
flash4_sector_erase_4
void flash4_sector_erase_4(flash4_t *ctx, uint32_t addr)
Sector Erase for 4 bytes address function.
flash4_cfg_t::miso
pin_name_t miso
Definition: flash4.h:165
flash4_sector_erase
void flash4_sector_erase(flash4_t *ctx, uint32_t addr)
Sector Erase function.
flash4_read_flash
void flash4_read_flash(flash4_t *ctx, uint8_t *out_data, uint32_t addr, uint8_t n_data)
Read Flash function.
flash4_read_identification
void flash4_read_identification(flash4_t *ctx, uint8_t *out_data, uint8_t n_data)
Read Identification function.
flash4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash4.h:179
flash4_read_byte
uint8_t flash4_read_byte(flash4_t *ctx, uint8_t reg)
Read byte from register function.
flash4_generic_transfer
void flash4_generic_transfer(flash4_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
flash4_t::io3
digital_out_t io3
Definition: flash4.h:148
flash4_write_command
void flash4_write_command(flash4_t *ctx, uint8_t cmd)
Write command function.
flash4_write_reg
void flash4_write_reg(flash4_t *ctx, uint8_t status, uint8_t config)
Write data to register function.
flash4_read_electronic_id
uint8_t flash4_read_electronic_id(flash4_t *ctx)
Read Electronic Signature function.
flash4_fast_read_flash_4
void flash4_fast_read_flash_4(flash4_t *ctx, uint8_t *out_data, uint8_t addr, uint8_t n_data)
Fast read Flash with 4 byte address function.