flash10  2.1.0.0
flash10.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 FLASH10_H
29 #define FLASH10_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define FLASH10_CMD_READ_ARRAY 0x03
61 #define FLASH10_CMD_FAST_READ_ARRAY 0x0B
62 
67 #define FLASH10_CMD_BLOCK_ERASE_4KB 0x20
68 #define FLASH10_CMD_BLOCK_ERASE_32KB 0x52
69 #define FLASH10_CMD_BLOCK_ERASE_64KB 0xD8
70 #define FLASH10_CMD_CHIP_ERASE 0x60
71 #define FLASH10_CMD_BYTE_PAGE_PROGRAM 0x02
72 #define FLASH10_CMD_SEQUENTIAL_PROGRAM 0xAD
73 #define FLASH10_CMD_ERASE_PROGRAM_SUSPEND 0x75
74 #define FLASH10_CMD_ERASE_PROGRAM_RESUME 0x7A
75 
80 #define FLASH10_CMD_WRITE_ENABLE 0x06
81 #define FLASH10_CMD_WRITE_DISABLE 0x04
82 #define FLASH10_CMD_VOLATILE_STATUS 0x50
83 #define FLASH10_CMD_INDIVIDUAL_BLOCK_LOCK 0x36
84 #define FLASH10_CMD_INDIVIDUAL_BLOCK_UNLOCK 0x39
85 #define FLASH10_CMD_READ_BLOCK_LOCK 0x3C
86 #define FLASH10_CMD_GLOBAL_BLOCK_LOCK 0x7E
87 #define FLASH10_CMD_GLOBAL_BLOCK_UNLOCK 0x98
88 
93 #define FLASH10_CMD_PROGRAM_OTP_SECURITY 0x9B
94 #define FLASH10_CMD_READ_OTP_SECURITY 0x4B
95 
100 #define FLASH10_CMD_READ_STATUS_1 0x05
101 #define FLASH10_CMD_READ_STATUS_2 0x35
102 #define FLASH10_CMD_READ_STATUS_3 0x15
103 #define FLASH10_CMD_READ_STATUS_4 0x65
104 #define FLASH10_CMD_READ_STATUS_5 0x65
105 #define FLASH10_CMD_WRITE_STATUS_1 0x01
106 #define FLASH10_CMD_WRITE_STATUS_2 0x31
107 #define FLASH10_CMD_WRITE_STATUS_3 0x11
108 #define FLASH10_CMD_WRITE_STATUS_4 0x71
109 #define FLASH10_CMD_WRITE_STATUS_5 0x71
110 #define FLASH10_CMD_READ_STATUS 0x65
111 #define FLASH10_CMD_WRITE_STATUS 0x71
112 #define FLASH10_CMD_STATUS_LOCK 0x6F
113 
118 #define FLASH10_CMD_DEEP_POWER_DOWN 0xB9
119 #define FLASH10_CMD_ULTRA_DEEP_POWER_DOWN 0x79
120 #define FLASH10_CMD_RESUME_FROM_DPD 0xAB
121 
126 #define FLASH10_CMD_ENABLE_RESET 0x66
127 #define FLASH10_CMD_RESET_DEVICE 0x99
128 #define FLASH10_CMD_TERMINATE 0xF0
129 
134 #define FLASH10_CMD_MANUFACTURER_ID 0x90
135 #define FLASH10_CMD_JEDEC_ID 0x9F
136 
141 #define FLASH10_CMD_READ_SFDP 0x5A
142  // flash10_reg
144 
159 #define FLASH10_STATUS_REG_1 1
160 #define FLASH10_STATUS_REG_2 2
161 #define FLASH10_STATUS_REG_3 3
162 #define FLASH10_STATUS_REG_4 4
163 #define FLASH10_STATUS_REG_5 5
164 
169 #define FLASH10_STATUS1_SRP0 0x80
170 #define FLASH10_STATUS1_BPSIZE 0x40
171 #define FLASH10_STATUS1_TB 0x20
172 #define FLASH10_STATUS1_WEL 0x02
173 #define FLASH10_STATUS1_BSY 0x01
174 
179 #define FLASH10_MIN_ADDRESS 0x000000
180 #define FLASH10_MAX_ADDRESS 0x3FFFFFul
181 #define FLASH10_PAGE_SIZE 256
182 
187 #define FLASH10_MANUFACTURER_ID 0x1F
188 #define FLASH10_DEVICE_ID 0x47
189 
198 #define FLASH10_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
199 #define FLASH10_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
200  // flash10_set
202 
217 #define FLASH10_MAP_MIKROBUS( cfg, mikrobus ) \
218  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
219  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
220  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
221  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
222  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
223  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM );
224  // flash10_map // flash10
227 
232 typedef struct
233 {
234  // Output pins
235  digital_out_t rst;
236  digital_out_t wp;
238  // Modules
239  spi_master_t spi;
241  pin_name_t chip_select;
243 } flash10_t;
244 
249 typedef struct
250 {
251  // Communication gpio pins
252  pin_name_t miso;
253  pin_name_t mosi;
254  pin_name_t sck;
255  pin_name_t cs;
257  // Additional gpio pins
258  pin_name_t rst;
259  pin_name_t wp;
261  // static variable
262  uint32_t spi_speed;
263  spi_master_mode_t spi_mode;
264  spi_master_chip_select_polarity_t cs_polarity;
266 } flash10_cfg_t;
267 
272 typedef enum
273 {
275  FLASH10_ERROR = -1
276 
278 
295 
309 err_t flash10_init ( flash10_t *ctx, flash10_cfg_t *cfg );
310 
322 err_t flash10_write_cmd ( flash10_t *ctx, uint8_t cmd );
323 
338 err_t flash10_write_cmd_data ( flash10_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
339 
354 err_t flash10_read_cmd_data ( flash10_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len );
355 
371 err_t flash10_write_cmd_address_data ( flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_in, uint32_t len );
372 
388 err_t flash10_read_cmd_address_data ( flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_out, uint32_t len );
389 
404 err_t flash10_memory_write ( flash10_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len );
405 
420 err_t flash10_memory_read ( flash10_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
421 
435 err_t flash10_erase_memory ( flash10_t *ctx, uint8_t erase_cmd, uint32_t address );
436 
448 
458 
468 
480 
493 err_t flash10_write_status ( flash10_t *ctx, uint8_t status_reg_num, uint8_t status );
494 
507 err_t flash10_read_status ( flash10_t *ctx, uint8_t status_reg_num, uint8_t *status );
508 
518 void flash10_set_wp_pin ( flash10_t *ctx, uint8_t state );
519 
529 void flash10_set_rst_pin ( flash10_t *ctx, uint8_t state );
530 
531 #ifdef __cplusplus
532 }
533 #endif
534 #endif // FLASH10_H
535  // flash10
537 
538 // ------------------------------------------------------------------------ END
flash10_write_cmd_data
err_t flash10_write_cmd_data(flash10_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
Flash 10 write cmd data function.
flash10_read_cmd_address_data
err_t flash10_read_cmd_address_data(flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_out, uint32_t len)
Flash 10 read cmd address data function.
flash10_write_enable
err_t flash10_write_enable(flash10_t *ctx)
Flash 10 write enable function.
flash10_t::chip_select
pin_name_t chip_select
Definition: flash10.h:241
flash10_read_status
err_t flash10_read_status(flash10_t *ctx, uint8_t status_reg_num, uint8_t *status)
Flash 10 read status function.
flash10_cfg_t::sck
pin_name_t sck
Definition: flash10.h:254
spi_specifics.h
This file contains SPI specific macros, functions, etc.
flash10_memory_write
err_t flash10_memory_write(flash10_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len)
Flash 10 memory write function.
flash10_erase_memory
err_t flash10_erase_memory(flash10_t *ctx, uint8_t erase_cmd, uint32_t address)
Flash 10 erase memory function.
flash10_t::rst
digital_out_t rst
Definition: flash10.h:235
flash10_t
Flash 10 Click context object.
Definition: flash10.h:233
flash10_check_communication
err_t flash10_check_communication(flash10_t *ctx)
Flash 10 check communication function.
flash10_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash10.h:262
flash10_read_cmd_data
err_t flash10_read_cmd_data(flash10_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len)
Flash 10 read cmd data function.
flash10_t::spi
spi_master_t spi
Definition: flash10.h:239
flash10_cfg_t::cs
pin_name_t cs
Definition: flash10.h:255
flash10_write_cmd
err_t flash10_write_cmd(flash10_t *ctx, uint8_t cmd)
Flash 10 write cmd function.
flash10_write_protect
err_t flash10_write_protect(flash10_t *ctx)
Flash 10 write protect function.
flash10_write_cmd_address_data
err_t flash10_write_cmd_address_data(flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_in, uint32_t len)
Flash 10 write cmd address data function.
flash10_cfg_t::miso
pin_name_t miso
Definition: flash10.h:252
FLASH10_OK
@ FLASH10_OK
Definition: flash10.h:274
flash10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash10.h:264
flash10_set_wp_pin
void flash10_set_wp_pin(flash10_t *ctx, uint8_t state)
Flash 10 set wp pin function.
flash10_soft_reset
err_t flash10_soft_reset(flash10_t *ctx)
Flash 10 soft reset function.
flash10_cfg_t
Flash 10 Click configuration object.
Definition: flash10.h:250
flash10_cfg_t::mosi
pin_name_t mosi
Definition: flash10.h:253
flash10_cfg_t::wp
pin_name_t wp
Definition: flash10.h:259
flash10_write_status
err_t flash10_write_status(flash10_t *ctx, uint8_t status_reg_num, uint8_t status)
Flash 10 write status function.
flash10_cfg_t::rst
pin_name_t rst
Definition: flash10.h:258
flash10_init
err_t flash10_init(flash10_t *ctx, flash10_cfg_t *cfg)
Flash 10 initialization function.
flash10_return_value_t
flash10_return_value_t
Flash 10 Click return value data.
Definition: flash10.h:273
flash10_memory_read
err_t flash10_memory_read(flash10_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
Flash 10 memory read function.
flash10_cfg_setup
void flash10_cfg_setup(flash10_cfg_t *cfg)
Flash 10 configuration object setup function.
flash10_set_rst_pin
void flash10_set_rst_pin(flash10_t *ctx, uint8_t state)
Flash 10 set rst pin function.
flash10_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash10.h:263
flash10_t::wp
digital_out_t wp
Definition: flash10.h:236
FLASH10_ERROR
@ FLASH10_ERROR
Definition: flash10.h:275