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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 
49 
70 #define FLASH8_CMD_READ_CELL_ARRAY 0x13
71 #define FLASH8_CMD_READ_BUFFER 0x03
72 #define FLASH8_CMD_READ_BUFFER_1 0x0B
73 #define FLASH8_CMD_PROGRAM_LOAD 0x02
74 #define FLASH8_CMD_PROGRAM_EXECUTE 0x10
75 #define FLASH8_CMD_PROTECT_EXECUTE 0x2A
76 #define FLASH8_CMD_PROGRAM_LOAD_RANDOM_DATA 0x84
77 #define FLASH8_CMD_BLOCK_ERASE 0xD8
78 #define FLASH8_CMD_RESET 0xFF
79 #define FLASH8_CMD_RESET_1 0xFE
80 #define FLASH8_CMD_WRITE_ENABLE 0x06
81 #define FLASH8_CMD_WRITE_DISABLE 0x04
82 #define FLASH8_CMD_GET_FEATURE 0x0F
83 #define FLASH8_CMD_SET_FEATURE 0x1F
84 #define FLASH8_CMD_READ_ID 0x9F
85 #define FLASH8_FEATURE_A0 0xA0
86 #define FLASH8_FEATURE_B0 0xB0
87 #define FLASH8_FEATURE_C0 0xC0
88 #define FLASH8_FEATURE_10 0x10
89 #define FLASH8_FEATURE_20 0x20
90 #define FLASH8_FEATURE_30 0x30
91 #define FLASH8_FEATURE_40 0x40
92 #define FLASH8_FEATURE_50 0x50
93 #define FLASH8_FEATURE_60 0x60
94 #define FLASH8_FEATURE_70 0x70
95  // flash8_cmd
97 
112 #define FLASH8_SET_BRWD_ENABLE 0x00
113 #define FLASH8_SET_BRWD_DISABLE 0x01
114 #define FLASH8_SET_BL_ALL_UNLOCKED 0x00
115 #define FLASH8_SET_BL_UPPER_1_64_LOCKED 0x01
116 #define FLASH8_SET_BL_UPPER_1_32_LOCKED 0x02
117 #define FLASH8_SET_BL_UPPER_1_16_LOCKED 0x03
118 #define FLASH8_SET_BL_UPPER_1_8_LOCKED 0x04
119 #define FLASH8_SET_BL_UPPER_1_4_LOCKED 0x05
120 #define FLASH8_SET_BL_UPPER_1_2_LOCKED 0x06
121 #define FLASH8_SET_BL_ALLLOCKED 0x07
122 
127 #define FLASH8_SET_IDR_E_NORMAL_OPERATION 0x00
128 #define FLASH8_SET_IDR_E_PARAMETER_PAGE_READ 0x01
129 #define FLASH8_SET_ECC_E_INTERNAL_ECC_DISABLE 0x00
130 #define FLASH8_SET_ECC_E_INTERNAL_ECC_ENABLE 0x01
131 #define FLASH8_SET_PRT_E_NORMAL_OPERATION 0x00
132 #define FLASH8_SET_PRT_EBLOCK_PROTECTION_ENABLE 0x01
133 #define FLASH8_SET_HSE_HIGH_SPEED_MODE_DISABLE 0x00
134 #define FLASH8_SET_HSE_HIGH_SPEED_MODE_ENABLE 0x01
135 #define FLASH8_SET_HOLD_D_HOLD_IS_ENABLED 0x00
136 #define FLASH8_SET_HOLD_D_HOLD_IS_DISABLED 0x01
137 
142 #define FLASH8_SET_WEL_WRITE_DISABLE 0x00
143 #define FLASH8_SET_WEL_WRITE_ENABLE 0x01
144 
145  // flash8_set
147 
162 #define FLASH8_GET_ECCS_NO_BIT_FLIPS_WERE_DETECT 0x00
163 #define FLASH8_GET_ECCS_BIT_FLIPS_DETECT_CORRECT 0x10
164 #define FLASH8_GET_ECCS_MULTI_BIT_FLIPS_NOT_CORRECT 0x20
165 #define FLASH8_GET_ECCS_BIT_FLIPS_DETECT_CORRECTED 0x30
166 #define FLASH8_GET_PRG_F_PROGRAM_PASS 0x00
167 #define FLASH8_GET_PRG_F_PROGRAM_FAIL 0x08
168 #define FLASH8_GET_PRG_F_PROGRAM_PASS 0x00
169 #define FLASH8_GET_ERS_F_ERASE_FAIL 0x04
170 #define FLASH8_GET_WEL_WRITE_DISABLE 0x00
171 #define FLASH8_GET_WEL_WRITE_ENABLE 0x02
172 #define FLASH8_GET_OIP_READY_STATE 0x00
173 #define FLASH8_GET_OIP_BUSY_STATE 0x01
174 
175  // flash8_get
177 
192 #define FLASH8_MAP_MIKROBUS( cfg, mikrobus ) \
193  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
194  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
195  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
196  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
197  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
198  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
199  // flash8_map // flash8
202 
207 typedef struct
208 {
209  // Output pins
210  digital_out_t wp;
211  digital_out_t hld;
213  // Modules
214  spi_master_t spi;
216  pin_name_t chip_select;
218 } flash8_t;
219 
224 typedef struct
225 {
226  // Communication gpio pins
227  pin_name_t miso;
228  pin_name_t mosi;
229  pin_name_t sck;
230  pin_name_t cs;
232  // Additional gpio pins
233  pin_name_t wp;
234  pin_name_t hld;
236  // static variable
237  uint32_t spi_speed;
238  spi_master_mode_t spi_mode;
239  spi_master_chip_select_polarity_t cs_polarity;
241 } flash8_cfg_t;
242 
247 typedef struct
248 {
249  uint8_t brwd;
250  uint8_t bl;
251  uint8_t idr_e;
252  uint8_t ecc_e;
253  uint8_t prt_e;
254  uint8_t hse;
255  uint8_t hold_d;
256  uint8_t eccs;
257  uint8_t prg_f;
258  uint8_t ers_f;
259  uint8_t wel;
260  uint8_t oip;
261 
262 } feature_cfg_t;
263 
268 typedef enum
269 {
271  FLASH8_ERROR = -1
272 
274 
291 
306 err_t flash8_init ( flash8_t *ctx, flash8_cfg_t *cfg );
307 
319 
335 err_t flash8_generic_write ( flash8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
336 
352 err_t flash8_generic_read ( flash8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
353 
364 
375 
386 
397 
414 err_t flash8_read_cell_array ( flash8_t *ctx, uint32_t row_address, uint16_t column_address, uint8_t *feature_status_out );
415 
430 err_t flash8_read_buffer ( flash8_t *ctx, uint16_t column_address, uint8_t *read_data );
431 
447 err_t flash8_program_load ( flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint16_t len );
448 
464 err_t flash8_program_execute ( flash8_t *ctx, uint32_t row_address );
465 
482 err_t flash8_program_load_random ( flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint8_t len );
483 
500 err_t flash8_block_erase ( flash8_t *ctx, uint32_t row_address, uint8_t *feat_data );
501 
516 err_t flash8_sw_reset ( flash8_t *ctx, uint8_t *feat_data );
517 
531 
545 
560 err_t flash8_set_feature ( flash8_t *ctx, uint8_t feature_addr, uint8_t feature_data );
561 
575 err_t flash8_set_config_feature ( flash8_t *ctx, feature_cfg_t feature_data );
576 
591 err_t flash8_get_feature ( flash8_t *ctx, uint8_t feature_addr, uint8_t *feature_data );
592 
606 err_t flash8_get_config_feature ( flash8_t *ctx, feature_cfg_t *feature_data );
607 
621 
637 err_t flash8_protect_execute ( flash8_t *ctx, uint32_t row_address, uint8_t *feature_status_out );
638 
654 err_t flash8_read_id ( flash8_t *ctx, uint8_t *manufacture_id, uint8_t *device_id, uint8_t *organization_id );
655 
675 err_t flash8_write_memory ( flash8_t *ctx, uint32_t row_address, uint16_t column_address,
676  uint8_t *data_in, uint16_t len, uint8_t *feature_status_out );
677 
697 err_t flash8_read_memory ( flash8_t *ctx, uint32_t row_address, uint16_t column_address,
698  uint8_t *data_out, uint16_t len, uint8_t *feature_status_out );
699 
700 #ifdef __cplusplus
701 }
702 #endif
703 #endif // FLASH8_H
704  // flash8
706 
707 // ------------------------------------------------------------------------ END
flash8_cfg_t::miso
pin_name_t miso
Definition: flash8.h:227
flash8_protect_execute
err_t flash8_protect_execute(flash8_t *ctx, uint32_t row_address, uint8_t *feature_status_out)
Flash 8 protect execute function.
feature_cfg_t::hse
uint8_t hse
Definition: flash8.h:254
flash8_cfg_t::sck
pin_name_t sck
Definition: flash8.h:229
flash8_generic_read
err_t flash8_generic_read(flash8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Flash 8 data reading function.
flash8_cfg_t::hld
pin_name_t hld
Definition: flash8.h:234
flash8_default_cfg
void flash8_default_cfg(flash8_t *ctx)
Flash 8 default configuration function.
flash8_read_buffer
err_t flash8_read_buffer(flash8_t *ctx, uint16_t column_address, uint8_t *read_data)
Flash 8 read buffer function.
flash8_get_config_feature
err_t flash8_get_config_feature(flash8_t *ctx, feature_cfg_t *feature_data)
Flash 8 get config feature function.
flash8_write_memory
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.
flash8_cfg_t::cs
pin_name_t cs
Definition: flash8.h:230
flash8_generic_write
err_t flash8_generic_write(flash8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Flash 8 data writing function.
flash8_program_load_random
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.
flash8_get_feature
err_t flash8_get_feature(flash8_t *ctx, uint8_t feature_addr, uint8_t *feature_data)
Flash 8 get feature function.
flash8_write_protect_enable
void flash8_write_protect_enable(flash8_t *ctx)
Flash 8 enable write protection function.
flash8_write_disable
err_t flash8_write_disable(flash8_t *ctx)
Flash 8 write disable function.
flash8_t::wp
digital_out_t wp
Definition: flash8.h:210
flash8_t::chip_select
pin_name_t chip_select
Definition: flash8.h:216
feature_cfg_t::prt_e
uint8_t prt_e
Definition: flash8.h:253
flash8_cfg_t::wp
pin_name_t wp
Definition: flash8.h:233
feature_cfg_t::ecc_e
uint8_t ecc_e
Definition: flash8.h:252
FLASH8_ERROR
@ FLASH8_ERROR
Definition: flash8.h:271
flash8_t
Flash 8 Click context object.
Definition: flash8.h:208
flash8_t::spi
spi_master_t spi
Definition: flash8.h:214
feature_cfg_t::bl
uint8_t bl
Definition: flash8.h:250
flash8_init
err_t flash8_init(flash8_t *ctx, flash8_cfg_t *cfg)
Flash 8 initialization function.
flash8_t::hld
digital_out_t hld
Definition: flash8.h:211
FLASH8_OK
@ FLASH8_OK
Definition: flash8.h:270
flash8_block_erase
err_t flash8_block_erase(flash8_t *ctx, uint32_t row_address, uint8_t *feat_data)
Flash 8 block erase function.
flash8_hold_enable
void flash8_hold_enable(flash8_t *ctx)
Flash 8 hold enable function.
flash8_set_feature
err_t flash8_set_feature(flash8_t *ctx, uint8_t feature_addr, uint8_t feature_data)
Flash 8 set feature function.
flash8_read_memory
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.
feature_cfg_t::brwd
uint8_t brwd
Definition: flash8.h:249
flash8_write_enable
err_t flash8_write_enable(flash8_t *ctx)
Flash 8 write enable function.
feature_cfg_t::ers_f
uint8_t ers_f
Definition: flash8.h:258
flash8_sw_reset
err_t flash8_sw_reset(flash8_t *ctx, uint8_t *feat_data)
Flash 8 soft reset function.
flash8_program_load
err_t flash8_program_load(flash8_t *ctx, uint16_t column_address, uint8_t *data_in, uint16_t len)
Flash 8 program load function.
feature_cfg_t::idr_e
uint8_t idr_e
Definition: flash8.h:251
flash8_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash8.h:237
flash8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash8.h:238
feature_cfg_t::eccs
uint8_t eccs
Definition: flash8.h:256
flash8_read_cell_array
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.
flash8_return_value_t
flash8_return_value_t
Flash 8 Click return value data.
Definition: flash8.h:269
flash8_write_protect_disable
void flash8_write_protect_disable(flash8_t *ctx)
Flash 8 disable write protection function.
flash8_cfg_t
Flash 8 Click configuration object.
Definition: flash8.h:225
feature_cfg_t::oip
uint8_t oip
Definition: flash8.h:260
flash8_read_id
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.
feature_cfg_t
Flash 8 Feature operation object.
Definition: flash8.h:248
flash8_cfg_setup
void flash8_cfg_setup(flash8_cfg_t *cfg)
Flash 8 configuration object setup function.
flash8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash8.h:239
flash8_cfg_t::mosi
pin_name_t mosi
Definition: flash8.h:228
feature_cfg_t::hold_d
uint8_t hold_d
Definition: flash8.h:255
flash8_protected_area_all_unlocked
err_t flash8_protected_area_all_unlocked(flash8_t *ctx)
Flash 8 protected area all unlocked function.
feature_cfg_t::wel
uint8_t wel
Definition: flash8.h:259
feature_cfg_t::prg_f
uint8_t prg_f
Definition: flash8.h:257
flash8_program_execute
err_t flash8_program_execute(flash8_t *ctx, uint32_t row_address)
Flash 8 program execute function.
flash8_hold_disable
void flash8_hold_disable(flash8_t *ctx)
Flash 8 hold disable function.
flash8_set_config_feature
err_t flash8_set_config_feature(flash8_t *ctx, feature_cfg_t feature_data)
Flash 8 set config feature function.