flash8 2.0.0.0
flash8.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef FLASH8_H
29#define FLASH8_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52
53
74#define FLASH8_CMD_READ_CELL_ARRAY 0x13
75#define FLASH8_CMD_READ_BUFFER 0x03
76#define FLASH8_CMD_READ_BUFFER_1 0x0B
77#define FLASH8_CMD_PROGRAM_LOAD 0x02
78#define FLASH8_CMD_PROGRAM_EXECUTE 0x10
79#define FLASH8_CMD_PROTECT_EXECUTE 0x2A
80#define FLASH8_CMD_PROGRAM_LOAD_RANDOM_DATA 0x84
81#define FLASH8_CMD_BLOCK_ERASE 0xD8
82#define FLASH8_CMD_RESET 0xFF
83#define FLASH8_CMD_RESET_1 0xFE
84#define FLASH8_CMD_WRITE_ENABLE 0x06
85#define FLASH8_CMD_WRITE_DISABLE 0x04
86#define FLASH8_CMD_GET_FEATURE 0x0F
87#define FLASH8_CMD_SET_FEATURE 0x1F
88#define FLASH8_CMD_READ_ID 0x9F
89#define FLASH8_FEATURE_A0 0xA0
90#define FLASH8_FEATURE_B0 0xB0
91#define FLASH8_FEATURE_C0 0xC0
92#define FLASH8_FEATURE_10 0x10
93#define FLASH8_FEATURE_20 0x20
94#define FLASH8_FEATURE_30 0x30
95#define FLASH8_FEATURE_40 0x40
96#define FLASH8_FEATURE_50 0x50
97#define FLASH8_FEATURE_60 0x60
98#define FLASH8_FEATURE_70 0x70
99
100 // flash8_cmd
101
116#define FLASH8_SET_BRWD_ENABLE 0x00
117#define FLASH8_SET_BRWD_DISABLE 0x01
118#define FLASH8_SET_BL_ALL_UNLOCKED 0x00
119#define FLASH8_SET_BL_UPPER_1_64_LOCKED 0x01
120#define FLASH8_SET_BL_UPPER_1_32_LOCKED 0x02
121#define FLASH8_SET_BL_UPPER_1_16_LOCKED 0x03
122#define FLASH8_SET_BL_UPPER_1_8_LOCKED 0x04
123#define FLASH8_SET_BL_UPPER_1_4_LOCKED 0x05
124#define FLASH8_SET_BL_UPPER_1_2_LOCKED 0x06
125#define FLASH8_SET_BL_ALLLOCKED 0x07
126
131#define FLASH8_SET_IDR_E_NORMAL_OPERATION 0x00
132#define FLASH8_SET_IDR_E_PARAMETER_PAGE_READ 0x01
133#define FLASH8_SET_ECC_E_INTERNAL_ECC_DISABLE 0x00
134#define FLASH8_SET_ECC_E_INTERNAL_ECC_ENABLE 0x01
135#define FLASH8_SET_PRT_E_NORMAL_OPERATION 0x00
136#define FLASH8_SET_PRT_EBLOCK_PROTECTION_ENABLE 0x01
137#define FLASH8_SET_HSE_HIGH_SPEED_MODE_DISABLE 0x00
138#define FLASH8_SET_HSE_HIGH_SPEED_MODE_ENABLE 0x01
139#define FLASH8_SET_HOLD_D_HOLD_IS_ENABLED 0x00
140#define FLASH8_SET_HOLD_D_HOLD_IS_DISABLED 0x01
141
146#define FLASH8_SET_WEL_WRITE_DISABLE 0x00
147#define FLASH8_SET_WEL_WRITE_ENABLE 0x01
148
149
150 // flash8_set
151
166#define FLASH8_GET_ECCS_NO_BIT_FLIPS_WERE_DETECT 0x00
167#define FLASH8_GET_ECCS_BIT_FLIPS_DETECT_CORRECT 0x10
168#define FLASH8_GET_ECCS_MULTI_BIT_FLIPS_NOT_CORRECT 0x20
169#define FLASH8_GET_ECCS_BIT_FLIPS_DETECT_CORRECTED 0x30
170#define FLASH8_GET_PRG_F_PROGRAM_PASS 0x00
171#define FLASH8_GET_PRG_F_PROGRAM_FAIL 0x08
172#define FLASH8_GET_PRG_F_PROGRAM_PASS 0x00
173#define FLASH8_GET_ERS_F_ERASE_FAIL 0x04
174#define FLASH8_GET_WEL_WRITE_DISABLE 0x00
175#define FLASH8_GET_WEL_WRITE_ENABLE 0x02
176#define FLASH8_GET_OIP_READY_STATE 0x00
177#define FLASH8_GET_OIP_BUSY_STATE 0x01
178
179
180 // flash8_get
181
196#define FLASH8_MAP_MIKROBUS( cfg, mikrobus ) \
197 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
198 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
199 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
200 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
201 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
202 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
203
204 // flash8_map
205 // flash8
206
211typedef struct
212{
213 // Output pins
214 digital_out_t wp;
215 digital_out_t hld;
217 // Modules
218 spi_master_t spi;
220 pin_name_t chip_select;
222} flash8_t;
223
228typedef struct
229{
230 // Communication gpio pins
231 pin_name_t miso;
232 pin_name_t mosi;
233 pin_name_t sck;
234 pin_name_t cs;
236 // Additional gpio pins
237 pin_name_t wp;
238 pin_name_t hld;
240 // static variable
241 uint32_t spi_speed;
242 spi_master_mode_t spi_mode;
243 spi_master_chip_select_polarity_t cs_polarity;
246
251typedef struct
252{
253 uint8_t brwd;
254 uint8_t bl;
255 uint8_t idr_e;
256 uint8_t ecc_e;
257 uint8_t prt_e;
258 uint8_t hse;
259 uint8_t hold_d;
260 uint8_t eccs;
261 uint8_t prg_f;
262 uint8_t ers_f;
263 uint8_t wel;
264 uint8_t oip;
265
267
272typedef enum
273{
275 FLASH8_ERROR = -1
276
278
295
310err_t flash8_init ( flash8_t *ctx, flash8_cfg_t *cfg );
311
323
339err_t flash8_generic_write ( flash8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
340
356err_t flash8_generic_read ( flash8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
357
368
379
390
401
418err_t flash8_read_cell_array ( flash8_t *ctx, uint32_t row_address, uint16_t column_address, uint8_t *feature_status_out );
419
434err_t flash8_read_buffer ( flash8_t *ctx, uint16_t column_address, uint8_t *read_data );
435
451err_t flash8_program_load ( flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint16_t len );
452
468err_t flash8_program_execute ( flash8_t *ctx, uint32_t row_address );
469
486err_t flash8_program_load_random ( flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint8_t len );
487
504err_t flash8_block_erase ( flash8_t *ctx, uint32_t row_address, uint8_t *feat_data );
505
520err_t flash8_sw_reset ( flash8_t *ctx, uint8_t *feat_data );
521
535
549
564err_t flash8_set_feature ( flash8_t *ctx, uint8_t feature_addr, uint8_t feature_data );
565
580
595err_t flash8_get_feature ( flash8_t *ctx, uint8_t feature_addr, uint8_t *feature_data );
596
611
625
641err_t flash8_protect_execute ( flash8_t *ctx, uint32_t row_address, uint8_t *feature_status_out );
642
658err_t flash8_read_id ( flash8_t *ctx, uint8_t *manufacture_id, uint8_t *device_id, uint8_t *organization_id );
659
679err_t flash8_write_memory ( flash8_t *ctx, uint32_t row_address, uint16_t column_address,
680 uint8_t *data_in, uint16_t len, uint8_t *feature_status_out );
681
701err_t flash8_read_memory ( flash8_t *ctx, uint32_t row_address, uint16_t column_address,
702 uint8_t *data_out, uint16_t len, uint8_t *feature_status_out );
703
704#ifdef __cplusplus
705}
706#endif
707#endif // FLASH8_H
708
709 // flash8
710
711// ------------------------------------------------------------------------ END
flash8_return_value_t
Flash 8 Click return value data.
Definition flash8.h:273
@ FLASH8_ERROR
Definition flash8.h:275
@ FLASH8_OK
Definition flash8.h:274
err_t flash8_get_config_feature(flash8_t *ctx, feature_cfg_t *feature_data)
Flash 8 get config feature function.
err_t flash8_get_feature(flash8_t *ctx, uint8_t feature_addr, uint8_t *feature_data)
Flash 8 get feature function.
void flash8_hold_disable(flash8_t *ctx)
Flash 8 hold disable function.
err_t flash8_read_buffer(flash8_t *ctx, uint16_t column_address, uint8_t *read_data)
Flash 8 read buffer function.
err_t flash8_write_enable(flash8_t *ctx)
Flash 8 write enable function.
err_t flash8_program_load(flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint16_t len)
Flash 8 program load function.
err_t flash8_sw_reset(flash8_t *ctx, uint8_t *feat_data)
Flash 8 soft reset function.
err_t flash8_set_config_feature(flash8_t *ctx, feature_cfg_t feature_data)
Flash 8 set config feature function.
void flash8_write_protect_disable(flash8_t *ctx)
Flash 8 disable write protection function.
err_t flash8_protect_execute(flash8_t *ctx, uint32_t row_address, uint8_t *feature_status_out)
Flash 8 protect execute function.
err_t flash8_program_execute(flash8_t *ctx, uint32_t row_address)
Flash 8 program execute function.
err_t flash8_write_memory(flash8_t *ctx, uint32_t row_address, uint16_t column_address, uint8_t *data_in, uint16_t len, uint8_t *feature_status_out)
Flash 8 write memory function.
err_t flash8_init(flash8_t *ctx, flash8_cfg_t *cfg)
Flash 8 initialization function.
err_t flash8_block_erase(flash8_t *ctx, uint32_t row_address, uint8_t *feat_data)
Flash 8 block erase function.
err_t flash8_generic_write(flash8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Flash 8 data writing function.
err_t flash8_read_cell_array(flash8_t *ctx, uint32_t row_address, uint16_t column_address, uint8_t *feature_status_out)
Flash 8 read cell array function.
void flash8_hold_enable(flash8_t *ctx)
Flash 8 hold enable function.
err_t flash8_read_id(flash8_t *ctx, uint8_t *manufacture_id, uint8_t *device_id, uint8_t *organization_id)
Flash 8 read ID function.
err_t flash8_write_disable(flash8_t *ctx)
Flash 8 write disable function.
void flash8_write_protect_enable(flash8_t *ctx)
Flash 8 enable write protection function.
err_t flash8_set_feature(flash8_t *ctx, uint8_t feature_addr, uint8_t feature_data)
Flash 8 set feature function.
err_t flash8_generic_read(flash8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Flash 8 data reading function.
err_t flash8_protected_area_all_unlocked(flash8_t *ctx)
Flash 8 protected area all unlocked function.
void flash8_default_cfg(flash8_t *ctx)
Flash 8 default configuration function.
err_t flash8_program_load_random(flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint8_t len)
Flash 8 program load random function.
err_t flash8_read_memory(flash8_t *ctx, uint32_t row_address, uint16_t column_address, uint8_t *data_out, uint16_t len, uint8_t *feature_status_out)
Flash 8 read memory function.
void flash8_cfg_setup(flash8_cfg_t *cfg)
Flash 8 configuration object setup function.
Flash 8 Feature operation object.
Definition flash8.h:252
uint8_t idr_e
Definition flash8.h:255
uint8_t prg_f
Definition flash8.h:261
uint8_t hold_d
Definition flash8.h:259
uint8_t ecc_e
Definition flash8.h:256
uint8_t ers_f
Definition flash8.h:262
uint8_t bl
Definition flash8.h:254
uint8_t oip
Definition flash8.h:264
uint8_t prt_e
Definition flash8.h:257
uint8_t brwd
Definition flash8.h:253
uint8_t wel
Definition flash8.h:263
uint8_t hse
Definition flash8.h:258
uint8_t eccs
Definition flash8.h:260
Flash 8 Click configuration object.
Definition flash8.h:229
pin_name_t hld
Definition flash8.h:238
spi_master_chip_select_polarity_t cs_polarity
Definition flash8.h:243
pin_name_t sck
Definition flash8.h:233
spi_master_mode_t spi_mode
Definition flash8.h:242
pin_name_t mosi
Definition flash8.h:232
uint32_t spi_speed
Definition flash8.h:241
pin_name_t wp
Definition flash8.h:237
pin_name_t miso
Definition flash8.h:231
pin_name_t cs
Definition flash8.h:234
Flash 8 Click context object.
Definition flash8.h:212
digital_out_t hld
Definition flash8.h:215
spi_master_t spi
Definition flash8.h:218
pin_name_t chip_select
Definition flash8.h:220
digital_out_t wp
Definition flash8.h:214