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 
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 #include "spi_specifics.h"
49 
70 #define FLASH11_CMD_ENABLE_RESET 0x66
71 #define FLASH11_CMD_RESET_DEVICE 0x99
72 #define FLASH11_CMD_DEEP_POWER_DOWN 0xB9
73 #define FLASH11_CMD_RESUME_FROM_DPD 0xAB
74 
79 #define FLASH11_CMD_READ_ARRAY 0x03
80 #define FLASH11_CMD_FAST_READ_ARRAY 0x0B
81 
86 #define FLASH11_CMD_WRITE_ENABLE 0x06
87 #define FLASH11_CMD_VOLATILE_SR_WR_EN 0x50
88 #define FLASH11_CMD_WRITE_DISABLE 0x04
89 
94 #define FLASH11_CMD_BYTE_PAGE_PROGRAM 0x02
95 
100 #define FLASH11_CMD_BLOCK_ERASE_4KB 0x20
101 #define FLASH11_CMD_BLOCK_ERASE_32KB 0x52
102 #define FLASH11_CMD_BLOCK_ERASE_64KB 0xD8
103 #define FLASH11_CMD_CHIP_ERASE 0x60
104 
109 #define FLASH11_CMD_ERASE_PROGRAM_SUSPEND 0x75
110 #define FLASH11_CMD_ERASE_PROGRAM_RESUME 0x7A
111 
116 #define FLASH11_CMD_READ_STATUS_1 0x05
117 #define FLASH11_CMD_READ_STATUS_2 0x35
118 #define FLASH11_CMD_READ_STATUS_3 0x15
119 #define FLASH11_CMD_WRITE_STATUS_1 0x01
120 #define FLASH11_CMD_WRITE_STATUS_2 0x31
121 #define FLASH11_CMD_WRITE_STATUS_3 0x11
122 
127 #define FLASH11_CMD_MANUFACTURER_ID 0x90
128 #define FLASH11_CMD_READ_JEDEC_ID 0x9F
129 #define FLASH11_CMD_READ_SERIAL_FLASH_DP 0x5A
130 
135 #define FLASH11_CMD_ERASE_SECURITY_REG 0x44
136 #define FLASH11_CMD_PROGRAM_SECURITY_REG 0x42
137 #define FLASH11_CMD_READ_SECURITY_REG 0x48
138 #define FLASH11_CMD_READ_UNIQUE_ID_NUM 0x4B
139  // flash11_opcode
141 
156 #define FLASH11_STATUS1_SRP0_BIT_MASK 0x80
157 #define FLASH11_STATUS1_BP4_BIT_MASK 0x40
158 #define FLASH11_STATUS1_BP3_BIT_MASK 0x20
159 #define FLASH11_STATUS1_BP2_BIT_MASK 0x10
160 #define FLASH11_STATUS1_BP1_BIT_MASK 0x08
161 #define FLASH11_STATUS1_BP0_BIT_MASK 0x04
162 #define FLASH11_STATUS1_WEL_EN 0x02
163 #define FLASH11_STATUS1_WEL_DIS 0x00
164 #define FLASH11_STATUS1_BSY 0x01
165 #define FLASH11_STATUS1_RDY 0x00
166 
171 #define FLASH11_MANUFACTURER_ID 0x1F
172 #define FLASH11_DEVICE_ID_0 0x87
173 #define FLASH11_DEVICE_ID_1 0x01
174 
179 #define FLASH11_MIN_ADDRESS 0x000000
180 #define FLASH11_MAX_ADDRESS 0x3FFFFFul
181 #define FLASH11_PAGE_SIZE 256
182 
187 #define FLASH11_WRITE_PROTECT_ENABLE 0
188 #define FLASH11_WRITE_PROTECT_DISABLE 1
189 
194 #define FLASH11_HOLD_ENABLE 0
195 #define FLASH11_HOLD_DISABLE 1
196 
205 #define FLASH11_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
206 #define FLASH11_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
207  // flash11_set
209 
224 #define FLASH11_MAP_MIKROBUS( cfg, mikrobus ) \
225  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
226  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
227  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
228  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
229  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
230  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
231  // flash11_map // flash11
234 
239 typedef struct
240 {
241  // Output pins
242  digital_out_t wp;
243  digital_out_t hld;
245  // Modules
246  spi_master_t spi;
248  pin_name_t chip_select;
250 } flash11_t;
251 
256 typedef struct
257 {
258  // Communication gpio pins
259  pin_name_t miso;
260  pin_name_t mosi;
261  pin_name_t sck;
262  pin_name_t cs;
264  // Additional gpio pins
265  pin_name_t wp;
266  pin_name_t hld;
268  // static variable
269  uint32_t spi_speed;
270  spi_master_mode_t spi_mode;
271  spi_master_chip_select_polarity_t cs_polarity;
273 } flash11_cfg_t;
274 
279 typedef enum
280 {
282  FLASH11_ERROR = -1
283 
285 
302 
316 err_t flash11_init ( flash11_t *ctx, flash11_cfg_t *cfg );
317 
331 
346 err_t flash11_generic_write ( flash11_t *ctx, uint8_t opcode, uint8_t *data_in, uint8_t len );
347 
362 err_t flash11_generic_read ( flash11_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len );
363 
377 err_t flash11_set_cmd ( flash11_t *ctx, uint8_t opcode );
378 
396 err_t flash11_write_cmd_addr_data ( flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
397 
415 err_t flash11_read_cmd_addr_data ( flash11_t *ctx, uint8_t opcode, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
416 
430 
447 err_t flash11_memory_write ( flash11_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
448 
465 err_t flash11_memory_read ( flash11_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
466 
480 
494 
513 err_t flash11_block_erase ( flash11_t *ctx, uint8_t cmd_block_erase, uint32_t mem_addr );
514 
528 
543 err_t flash11_set_status ( flash11_t *ctx, uint8_t status_reg, uint8_t status );
544 
559 err_t flash11_get_status ( flash11_t *ctx, uint8_t status_reg, uint8_t *status );
560 
575 err_t flash11_get_device_id ( flash11_t *ctx, uint8_t *device_id );
576 
590 void flash11_hw_write_protect ( flash11_t *ctx, uint8_t en_wp );
591 
605 void flash11_en_hold ( flash11_t *ctx, uint8_t en_hold );
606 
607 #ifdef __cplusplus
608 }
609 #endif
610 #endif // FLASH11_H
611  // flash11
613 
614 // ------------------------------------------------------------------------ END
flash11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash11.h:270
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:243
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:282
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:281
flash11_cfg_t::mosi
pin_name_t mosi
Definition: flash11.h:260
flash11_t
Flash 11 Click context object.
Definition: flash11.h:240
flash11_cfg_t::wp
pin_name_t wp
Definition: flash11.h:265
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:259
flash11_cfg_t::cs
pin_name_t cs
Definition: flash11.h:262
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:242
flash11_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash11.h:271
flash11_return_value_t
flash11_return_value_t
Flash 11 Click return value data.
Definition: flash11.h:280
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:261
flash11_t::chip_select
pin_name_t chip_select
Definition: flash11.h:248
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:257
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:246
flash11_cfg_t::hld
pin_name_t hld
Definition: flash11.h:266
flash11_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash11.h:269
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.