flash11  2.1.0.0
flash11.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 FLASH11_H
29 #define FLASH11_H
30 
31 #ifdef __cplusplus
32 extern "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 #include "spi_specifics.h"
53 
74 #define FLASH11_CMD_ENABLE_RESET 0x66
75 #define FLASH11_CMD_RESET_DEVICE 0x99
76 #define FLASH11_CMD_DEEP_POWER_DOWN 0xB9
77 #define FLASH11_CMD_RESUME_FROM_DPD 0xAB
78 
83 #define FLASH11_CMD_READ_ARRAY 0x03
84 #define FLASH11_CMD_FAST_READ_ARRAY 0x0B
85 
90 #define FLASH11_CMD_WRITE_ENABLE 0x06
91 #define FLASH11_CMD_VOLATILE_SR_WR_EN 0x50
92 #define FLASH11_CMD_WRITE_DISABLE 0x04
93 
98 #define FLASH11_CMD_BYTE_PAGE_PROGRAM 0x02
99 
104 #define FLASH11_CMD_BLOCK_ERASE_4KB 0x20
105 #define FLASH11_CMD_BLOCK_ERASE_32KB 0x52
106 #define FLASH11_CMD_BLOCK_ERASE_64KB 0xD8
107 #define FLASH11_CMD_CHIP_ERASE 0x60
108 
113 #define FLASH11_CMD_ERASE_PROGRAM_SUSPEND 0x75
114 #define FLASH11_CMD_ERASE_PROGRAM_RESUME 0x7A
115 
120 #define FLASH11_CMD_READ_STATUS_1 0x05
121 #define FLASH11_CMD_READ_STATUS_2 0x35
122 #define FLASH11_CMD_READ_STATUS_3 0x15
123 #define FLASH11_CMD_WRITE_STATUS_1 0x01
124 #define FLASH11_CMD_WRITE_STATUS_2 0x31
125 #define FLASH11_CMD_WRITE_STATUS_3 0x11
126 
131 #define FLASH11_CMD_MANUFACTURER_ID 0x90
132 #define FLASH11_CMD_READ_JEDEC_ID 0x9F
133 #define FLASH11_CMD_READ_SERIAL_FLASH_DP 0x5A
134 
139 #define FLASH11_CMD_ERASE_SECURITY_REG 0x44
140 #define FLASH11_CMD_PROGRAM_SECURITY_REG 0x42
141 #define FLASH11_CMD_READ_SECURITY_REG 0x48
142 #define FLASH11_CMD_READ_UNIQUE_ID_NUM 0x4B
143  // flash11_opcode
145 
160 #define FLASH11_STATUS1_SRP0_BIT_MASK 0x80
161 #define FLASH11_STATUS1_BP4_BIT_MASK 0x40
162 #define FLASH11_STATUS1_BP3_BIT_MASK 0x20
163 #define FLASH11_STATUS1_BP2_BIT_MASK 0x10
164 #define FLASH11_STATUS1_BP1_BIT_MASK 0x08
165 #define FLASH11_STATUS1_BP0_BIT_MASK 0x04
166 #define FLASH11_STATUS1_WEL_EN 0x02
167 #define FLASH11_STATUS1_WEL_DIS 0x00
168 #define FLASH11_STATUS1_BSY 0x01
169 #define FLASH11_STATUS1_RDY 0x00
170 
175 #define FLASH11_MANUFACTURER_ID 0x1F
176 #define FLASH11_DEVICE_ID_0 0x87
177 #define FLASH11_DEVICE_ID_1 0x01
178 
183 #define FLASH11_MIN_ADDRESS 0x000000
184 #define FLASH11_MAX_ADDRESS 0x3FFFFFul
185 #define FLASH11_PAGE_SIZE 256
186 
191 #define FLASH11_WRITE_PROTECT_ENABLE 0
192 #define FLASH11_WRITE_PROTECT_DISABLE 1
193 
198 #define FLASH11_HOLD_ENABLE 0
199 #define FLASH11_HOLD_DISABLE 1
200 
209 #define FLASH11_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
210 #define FLASH11_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
211  // flash11_set
213 
228 #define FLASH11_MAP_MIKROBUS( cfg, mikrobus ) \
229  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
230  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
231  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
232  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
233  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
234  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
235  // flash11_map // flash11
238 
243 typedef struct
244 {
245  // Output pins
246  digital_out_t wp;
247  digital_out_t hld;
249  // Modules
250  spi_master_t spi;
252  pin_name_t chip_select;
254 } flash11_t;
255 
260 typedef struct
261 {
262  // Communication gpio pins
263  pin_name_t miso;
264  pin_name_t mosi;
265  pin_name_t sck;
266  pin_name_t cs;
268  // Additional gpio pins
269  pin_name_t wp;
270  pin_name_t hld;
272  // static variable
273  uint32_t spi_speed;
274  spi_master_mode_t spi_mode;
275  spi_master_chip_select_polarity_t cs_polarity;
277 } flash11_cfg_t;
278 
283 typedef enum
284 {
286  FLASH11_ERROR = -1
287 
289 
306 
320 err_t flash11_init ( flash11_t *ctx, flash11_cfg_t *cfg );
321 
335 
350 err_t flash11_generic_write ( flash11_t *ctx, uint8_t opcode, uint8_t *data_in, uint8_t len );
351 
366 err_t flash11_generic_read ( flash11_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len );
367 
381 err_t flash11_set_cmd ( flash11_t *ctx, uint8_t opcode );
382 
400 err_t flash11_write_cmd_addr_data ( flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
401 
419 err_t flash11_read_cmd_addr_data ( flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
420 
434 
451 err_t flash11_memory_write ( flash11_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
452 
469 err_t flash11_memory_read ( flash11_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
470 
484 
498 
517 err_t flash11_block_erase ( flash11_t *ctx, uint8_t cmd_block_erase, uint32_t mem_addr );
518 
532 
547 err_t flash11_set_status ( flash11_t *ctx, uint8_t status_reg, uint8_t status );
548 
563 err_t flash11_get_status ( flash11_t *ctx, uint8_t status_reg, uint8_t *status );
564 
579 err_t flash11_get_device_id ( flash11_t *ctx, uint8_t *device_id );
580 
594 void flash11_hw_write_protect ( flash11_t *ctx, uint8_t en_wp );
595 
609 void flash11_en_hold ( flash11_t *ctx, uint8_t en_hold );
610 
611 #ifdef __cplusplus
612 }
613 #endif
614 #endif // FLASH11_H
615  // flash11
617 
618 // ------------------------------------------------------------------------ END
flash11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash11.h:274
flash11_block_erase
err_t flash11_block_erase(flash11_t *ctx, uint8_t cmd_block_erase, uint32_t mem_addr)
Flash 11 block erase function.
flash11_hw_write_protect
void flash11_hw_write_protect(flash11_t *ctx, uint8_t en_wp)
Flash 11 hardware write protect function.
flash11_t::hld
digital_out_t hld
Definition: flash11.h:247
flash11_chip_erase
err_t flash11_chip_erase(flash11_t *ctx)
Flash 11 chip erase function.
flash11_get_status
err_t flash11_get_status(flash11_t *ctx, uint8_t status_reg, uint8_t *status)
Flash 11 gets the status function.
flash11_default_cfg
err_t flash11_default_cfg(flash11_t *ctx)
Flash 11 default configuration function.
FLASH11_ERROR
@ FLASH11_ERROR
Definition: flash11.h:286
flash11_memory_write
err_t flash11_memory_write(flash11_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint32_t len)
Flash 11 memory write function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
FLASH11_OK
@ FLASH11_OK
Definition: flash11.h:285
flash11_cfg_t::mosi
pin_name_t mosi
Definition: flash11.h:264
flash11_t
Flash 11 Click context object.
Definition: flash11.h:244
flash11_cfg_t::wp
pin_name_t wp
Definition: flash11.h:269
flash11_set_status
err_t flash11_set_status(flash11_t *ctx, uint8_t status_reg, uint8_t status)
Flash 11 set status function.
flash11_cfg_t::miso
pin_name_t miso
Definition: flash11.h:263
flash11_cfg_t::cs
pin_name_t cs
Definition: flash11.h:266
flash11_write_disable
err_t flash11_write_disable(flash11_t *ctx)
Flash 11 write disable function.
flash11_t::wp
digital_out_t wp
Definition: flash11.h:246
flash11_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash11.h:275
flash11_return_value_t
flash11_return_value_t
Flash 11 Click return value data.
Definition: flash11.h:284
flash11_init
err_t flash11_init(flash11_t *ctx, flash11_cfg_t *cfg)
Flash 11 initialization function.
flash11_cfg_t::sck
pin_name_t sck
Definition: flash11.h:265
flash11_t::chip_select
pin_name_t chip_select
Definition: flash11.h:252
flash11_sw_reset
err_t flash11_sw_reset(flash11_t *ctx)
Flash 11 sw reset function.
flash11_cfg_t
Flash 11 Click configuration object.
Definition: flash11.h:261
flash11_get_device_id
err_t flash11_get_device_id(flash11_t *ctx, uint8_t *device_id)
Flash 11 gets the device ID function.
flash11_generic_write
err_t flash11_generic_write(flash11_t *ctx, uint8_t opcode, uint8_t *data_in, uint8_t len)
Flash 11 data writing function.
flash11_t::spi
spi_master_t spi
Definition: flash11.h:250
flash11_cfg_t::hld
pin_name_t hld
Definition: flash11.h:270
flash11_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash11.h:273
flash11_en_hold
void flash11_en_hold(flash11_t *ctx, uint8_t en_hold)
Flash 11 enable hold function.
flash11_write_enable
err_t flash11_write_enable(flash11_t *ctx)
Flash 11 write enable function.
flash11_memory_read
err_t flash11_memory_read(flash11_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint32_t len)
Flash 11 memory read function.
flash11_read_cmd_addr_data
err_t flash11_read_cmd_addr_data(flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_out, uint32_t len)
Flash 11 read command adress data function.
flash11_cfg_setup
void flash11_cfg_setup(flash11_cfg_t *cfg)
Flash 11 configuration object setup function.
flash11_set_cmd
err_t flash11_set_cmd(flash11_t *ctx, uint8_t opcode)
Flash 11 set the command function.
flash11_write_cmd_addr_data
err_t flash11_write_cmd_addr_data(flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_in, uint32_t len)
Flash 11 write command adress data function.
flash11_generic_read
err_t flash11_generic_read(flash11_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len)
Flash 11 data reading function.