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 
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 FLASH10_CMD_READ_ARRAY 0x03
75 #define FLASH10_CMD_FAST_READ_ARRAY 0x0B
76 
81 #define FLASH10_CMD_BLOCK_ERASE_4KB 0x20
82 #define FLASH10_CMD_BLOCK_ERASE_32KB 0x52
83 #define FLASH10_CMD_BLOCK_ERASE_64KB 0xD8
84 #define FLASH10_CMD_CHIP_ERASE 0x60
85 #define FLASH10_CMD_BYTE_PAGE_PROGRAM 0x02
86 #define FLASH10_CMD_SEQUENTIAL_PROGRAM 0xAD
87 #define FLASH10_CMD_ERASE_PROGRAM_SUSPEND 0x75
88 #define FLASH10_CMD_ERASE_PROGRAM_RESUME 0x7A
89 
94 #define FLASH10_CMD_WRITE_ENABLE 0x06
95 #define FLASH10_CMD_WRITE_DISABLE 0x04
96 #define FLASH10_CMD_VOLATILE_STATUS 0x50
97 #define FLASH10_CMD_INDIVIDUAL_BLOCK_LOCK 0x36
98 #define FLASH10_CMD_INDIVIDUAL_BLOCK_UNLOCK 0x39
99 #define FLASH10_CMD_READ_BLOCK_LOCK 0x3C
100 #define FLASH10_CMD_GLOBAL_BLOCK_LOCK 0x7E
101 #define FLASH10_CMD_GLOBAL_BLOCK_UNLOCK 0x98
102 
107 #define FLASH10_CMD_PROGRAM_OTP_SECURITY 0x9B
108 #define FLASH10_CMD_READ_OTP_SECURITY 0x4B
109 
114 #define FLASH10_CMD_READ_STATUS_1 0x05
115 #define FLASH10_CMD_READ_STATUS_2 0x35
116 #define FLASH10_CMD_READ_STATUS_3 0x15
117 #define FLASH10_CMD_READ_STATUS_4 0x65
118 #define FLASH10_CMD_READ_STATUS_5 0x65
119 #define FLASH10_CMD_WRITE_STATUS_1 0x01
120 #define FLASH10_CMD_WRITE_STATUS_2 0x31
121 #define FLASH10_CMD_WRITE_STATUS_3 0x11
122 #define FLASH10_CMD_WRITE_STATUS_4 0x71
123 #define FLASH10_CMD_WRITE_STATUS_5 0x71
124 #define FLASH10_CMD_READ_STATUS 0x65
125 #define FLASH10_CMD_WRITE_STATUS 0x71
126 #define FLASH10_CMD_STATUS_LOCK 0x6F
127 
132 #define FLASH10_CMD_DEEP_POWER_DOWN 0xB9
133 #define FLASH10_CMD_ULTRA_DEEP_POWER_DOWN 0x79
134 #define FLASH10_CMD_RESUME_FROM_DPD 0xAB
135 
140 #define FLASH10_CMD_ENABLE_RESET 0x66
141 #define FLASH10_CMD_RESET_DEVICE 0x99
142 #define FLASH10_CMD_TERMINATE 0xF0
143 
148 #define FLASH10_CMD_MANUFACTURER_ID 0x90
149 #define FLASH10_CMD_JEDEC_ID 0x9F
150 
155 #define FLASH10_CMD_READ_SFDP 0x5A
156  // flash10_reg
158 
173 #define FLASH10_STATUS_REG_1 1
174 #define FLASH10_STATUS_REG_2 2
175 #define FLASH10_STATUS_REG_3 3
176 #define FLASH10_STATUS_REG_4 4
177 #define FLASH10_STATUS_REG_5 5
178 
183 #define FLASH10_STATUS1_SRP0 0x80
184 #define FLASH10_STATUS1_BPSIZE 0x40
185 #define FLASH10_STATUS1_TB 0x20
186 #define FLASH10_STATUS1_WEL 0x02
187 #define FLASH10_STATUS1_BSY 0x01
188 
193 #define FLASH10_MIN_ADDRESS 0x000000
194 #define FLASH10_MAX_ADDRESS 0x3FFFFFul
195 #define FLASH10_PAGE_SIZE 256
196 
201 #define FLASH10_MANUFACTURER_ID 0x1F
202 #define FLASH10_DEVICE_ID 0x47
203 
212 #define FLASH10_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
213 #define FLASH10_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
214  // flash10_set
216 
231 #define FLASH10_MAP_MIKROBUS( cfg, mikrobus ) \
232  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
233  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
234  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
235  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
236  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
237  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM );
238  // flash10_map // flash10
241 
246 typedef struct
247 {
248  // Output pins
249  digital_out_t rst;
250  digital_out_t wp;
252  // Modules
253  spi_master_t spi;
255  pin_name_t chip_select;
257 } flash10_t;
258 
263 typedef struct
264 {
265  // Communication gpio pins
266  pin_name_t miso;
267  pin_name_t mosi;
268  pin_name_t sck;
269  pin_name_t cs;
271  // Additional gpio pins
272  pin_name_t rst;
273  pin_name_t wp;
275  // static variable
276  uint32_t spi_speed;
277  spi_master_mode_t spi_mode;
278  spi_master_chip_select_polarity_t cs_polarity;
280 } flash10_cfg_t;
281 
286 typedef enum
287 {
289  FLASH10_ERROR = -1
290 
292 
309 
323 err_t flash10_init ( flash10_t *ctx, flash10_cfg_t *cfg );
324 
336 err_t flash10_write_cmd ( flash10_t *ctx, uint8_t cmd );
337 
352 err_t flash10_write_cmd_data ( flash10_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
353 
368 err_t flash10_read_cmd_data ( flash10_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len );
369 
385 err_t flash10_write_cmd_address_data ( flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_in, uint32_t len );
386 
402 err_t flash10_read_cmd_address_data ( flash10_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_out, uint32_t len );
403 
418 err_t flash10_memory_write ( flash10_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len );
419 
434 err_t flash10_memory_read ( flash10_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
435 
449 err_t flash10_erase_memory ( flash10_t *ctx, uint8_t erase_cmd, uint32_t address );
450 
462 
472 
482 
494 
507 err_t flash10_write_status ( flash10_t *ctx, uint8_t status_reg_num, uint8_t status );
508 
521 err_t flash10_read_status ( flash10_t *ctx, uint8_t status_reg_num, uint8_t *status );
522 
532 void flash10_set_wp_pin ( flash10_t *ctx, uint8_t state );
533 
543 void flash10_set_rst_pin ( flash10_t *ctx, uint8_t state );
544 
545 #ifdef __cplusplus
546 }
547 #endif
548 #endif // FLASH10_H
549  // flash10
551 
552 // ------------------------------------------------------------------------ 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:255
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:268
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:249
flash10_t
Flash 10 Click context object.
Definition: flash10.h:247
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:276
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:253
flash10_cfg_t::cs
pin_name_t cs
Definition: flash10.h:269
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:266
FLASH10_OK
@ FLASH10_OK
Definition: flash10.h:288
flash10_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash10.h:278
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:264
flash10_cfg_t::mosi
pin_name_t mosi
Definition: flash10.h:267
flash10_cfg_t::wp
pin_name_t wp
Definition: flash10.h:273
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:272
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:287
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:277
flash10_t::wp
digital_out_t wp
Definition: flash10.h:250
FLASH10_ERROR
@ FLASH10_ERROR
Definition: flash10.h:289