flash7  2.0.0.0
flash7.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 FLASH7_H
29 #define FLASH7_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 
74 #define FLASH7_STAT_REG_LSB_SRP0 0x80
75 #define FLASH7_STAT_REG_LSB_BP4 0x40
76 #define FLASH7_STAT_REG_LSB_BP3 0x20
77 #define FLASH7_STAT_REG_LSB_BP2 0x10
78 #define FLASH7_STAT_REG_LSB_BP1 0x08
79 #define FLASH7_STAT_REG_LSB_BP0 0x04
80 #define FLASH7_STAT_REG_LSB_WEL 0x02
81 #define FLASH7_STAT_REG_LSB_WIP 0x01
82 
87 #define FLASH7_STAT_REG_MSB_SUS1 0x80
88 #define FLASH7_STAT_REG_MSB_CMP 0x40
89 #define FLASH7_STAT_REG_MSB_LB3 0x20
90 #define FLASH7_STAT_REG_MSB_LB2 0x10
91 #define FLASH7_STAT_REG_MSB_LB1 0x08
92 #define FLASH7_STAT_REG_MSB_SUS2 0x04
93 #define FLASH7_STAT_REG_MSB_QE 0x02
94 #define FLASH7_STAT_REG_MSB_SRP1 0x01
95 
100 #define FLASH7_MEMORY_ADDR_START 0x00000000
101 #define FLASH7_MEMORY_ADDR_END 0x00FFFFFF
102 #define FLASH7_MEM_SECTOR_LEN 0x00001000
103 #define FLASH7_MEMORY_BLOCK_SIZE 0x00008000
104  // flash7_reg
106 
126 #define FLASH7_CMD_WRSR 0x01
127 #define FLASH7_CMD_WRITE 0x02
128 #define FLASH7_CMD_READ 0x03
129 #define FLASH7_CMD_WRDI 0x04
130 #define FLASH7_CMD_RDSR_LSB 0x05
131 #define FLASH7_CMD_RDSR_MSB 0x35
132 #define FLASH7_CMD_WREN 0x06
133 #define FLASH7_CMD_FREAD 0x0B
134 #define FLASH7_CMD_WEVSR 0x50
135 #define FLASH7_CMD_SE 0x20
136 #define FLASH7_CMD_BE_32KB 0x52
137 #define FLASH7_CMD_BE_64KB 0xD8
138 #define FLASH7_CMD_CE 0x60
139 #define FLASH7_CMD_SLEEP 0xB9
140 #define FLASH7_CMD_WAKE 0xAB
141 #define FLASH7_CMD_REMS 0x90
142 #define FLASH7_CMD_RDID 0x9F
143 #define FLASH7_CMD_ID 0x4B
144 #define FLASH7_CMD_ENRES 0x66
145 #define FLASH7_CMD_RES 0x99
146 
151 #define FLASH7_WRITE_PROTECT_DISABLE 0x00
152 #define FLASH7_WRITE_PROTECT_ENABLE 0x01
153 
158 #define FLASH7_HOLD_DISABLE 0x00
159 #define FLASH7_HOLD_ENABLE 0x01
160 
165 #define FLASH7_DUMMY 0x00
166  // flash7_set
168 
183 #define FLASH7_MAP_MIKROBUS( cfg, mikrobus ) \
184  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
185  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
186  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
187  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
188  cfg.io2 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
189  cfg.io3 = MIKROBUS( mikrobus, MIKROBUS_INT )
190  // flash7_map // flash7
193 
198 typedef struct
199 {
200  // Output pins
201  digital_out_t io2;
202  digital_out_t io3;
204  // Modules
205  spi_master_t spi;
207  pin_name_t chip_select;
209 } flash7_t;
210 
215 typedef struct
216 {
217  // Communication gpio pins
218  pin_name_t miso;
219  pin_name_t mosi;
220  pin_name_t sck;
221  pin_name_t cs;
223  // Additional gpio pins
224 
225  pin_name_t io2;
226  pin_name_t io3;
228  // static variable
229  uint32_t spi_speed;
230  spi_master_mode_t spi_mode;
231  spi_master_chip_select_polarity_t cs_polarity;
233 } flash7_cfg_t;
234 
239 typedef enum
240 {
242  FLASH7_ERROR = -1
243 
245 
262 
277 err_t flash7_init ( flash7_t *ctx, flash7_cfg_t *cfg );
278 
293 
309 err_t flash7_generic_write ( flash7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
310 
325 err_t flash7_generic_read ( flash7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
326 
338 void flash7_write_protect ( flash7_t *ctx, uint8_t en_write_protect );
339 
350 void flash7_hold ( flash7_t *ctx, uint8_t en_hold );
351 
362 void flash7_send_command ( flash7_t *ctx, uint8_t cmd );
363 
374 
385 
396 
407 uint8_t flash7_read_status_register ( flash7_t *ctx, uint8_t status_byte );
408 
419 void flash7_write_status_register ( flash7_t *ctx, uint16_t status_data );
420 
434 uint8_t flash7_page_program ( flash7_t *ctx, uint32_t mem_addr, uint8_t *p_tx_data, uint16_t n_bytes );
435 
449 void flash7_read_memory ( flash7_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint16_t n_bytes );
450 
464 void flash7_fast_read_memory ( flash7_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint16_t n_bytes );
465 
481 uint8_t flash7_sector_erase ( flash7_t *ctx, uint16_t mem_sector );
482 
499 uint8_t flash7_block_erase ( flash7_t *ctx, uint8_t mem_block, uint8_t mem_block_len );
500 
513 
524 uint8_t flash7_wake_up ( flash7_t *ctx );
525 
537 void flash7_read_id ( flash7_t *ctx, uint8_t *manufacturer_id, uint8_t *device_id );
538 
551 void flash7_get_identification ( flash7_t *ctx, uint8_t *manufacturer_id, uint8_t *memory_type_id, uint8_t *capacity_id );
552 
562 void flash7_sw_reset ( flash7_t *ctx );
563 
564 #ifdef __cplusplus
565 }
566 #endif
567 #endif // FLASH7_H
568  // flash7
570 
571 // ------------------------------------------------------------------------ END
flash7_write_status_register
void flash7_write_status_register(flash7_t *ctx, uint16_t status_data)
Write status register function.
flash7_chip_erase
void flash7_chip_erase(flash7_t *ctx)
Chip erase function.
flash7_cfg_setup
void flash7_cfg_setup(flash7_cfg_t *cfg)
Flash 7 configuration object setup function.
flash7_cfg_t::cs
pin_name_t cs
Definition: flash7.h:221
flash7_hold
void flash7_hold(flash7_t *ctx, uint8_t en_hold)
Enable hold operation function.
flash7_t::io3
digital_out_t io3
Definition: flash7.h:202
flash7_fast_read_memory
void flash7_fast_read_memory(flash7_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint16_t n_bytes)
Fast read memory function.
flash7_write_enable
void flash7_write_enable(flash7_t *ctx)
Write enable function.
flash7_read_status_register
uint8_t flash7_read_status_register(flash7_t *ctx, uint8_t status_byte)
Read status register function.
flash7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash7.h:231
flash7_get_identification
void flash7_get_identification(flash7_t *ctx, uint8_t *manufacturer_id, uint8_t *memory_type_id, uint8_t *capacity_id)
Get identification function.
flash7_sw_reset
void flash7_sw_reset(flash7_t *ctx)
Soft reset function.
flash7_cfg_t::io2
pin_name_t io2
Definition: flash7.h:225
flash7_cfg_t
Flash 7 Click configuration object.
Definition: flash7.h:216
flash7_cfg_t::io3
pin_name_t io3
Definition: flash7.h:226
flash7_read_memory
void flash7_read_memory(flash7_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint16_t n_bytes)
Read memory function.
flash7_init
err_t flash7_init(flash7_t *ctx, flash7_cfg_t *cfg)
Flash 7 initialization function.
flash7_t
Flash 7 Click context object.
Definition: flash7.h:199
flash7_write_protect
void flash7_write_protect(flash7_t *ctx, uint8_t en_write_protect)
Enable write protect function.
flash7_default_cfg
err_t flash7_default_cfg(flash7_t *ctx)
Flash 7 default configuration function.
flash7_t::chip_select
pin_name_t chip_select
Definition: flash7.h:207
FLASH7_OK
@ FLASH7_OK
Definition: flash7.h:241
flash7_block_erase
uint8_t flash7_block_erase(flash7_t *ctx, uint8_t mem_block, uint8_t mem_block_len)
Block erase function.
flash7_go_to_sleep
void flash7_go_to_sleep(flash7_t *ctx)
Go to sleep mode function.
flash7_page_program
uint8_t flash7_page_program(flash7_t *ctx, uint32_t mem_addr, uint8_t *p_tx_data, uint16_t n_bytes)
Page program function.
flash7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash7.h:230
flash7_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash7.h:229
flash7_generic_read
err_t flash7_generic_read(flash7_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Flash 7 data reading function.
FLASH7_ERROR
@ FLASH7_ERROR
Definition: flash7.h:242
flash7_send_command
void flash7_send_command(flash7_t *ctx, uint8_t cmd)
Send command function.
flash7_cfg_t::sck
pin_name_t sck
Definition: flash7.h:220
flash7_cfg_t::miso
pin_name_t miso
Definition: flash7.h:218
flash7_sector_erase
uint8_t flash7_sector_erase(flash7_t *ctx, uint16_t mem_sector)
Sector erase function.
flash7_wake_up
uint8_t flash7_wake_up(flash7_t *ctx)
Wake up function.
flash7_return_value_t
flash7_return_value_t
Flash 7 Click return value data.
Definition: flash7.h:240
flash7_generic_write
err_t flash7_generic_write(flash7_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Flash 7 data writing function.
flash7_t::spi
spi_master_t spi
Definition: flash7.h:205
flash7_t::io2
digital_out_t io2
Definition: flash7.h:201
flash7_cfg_t::mosi
pin_name_t mosi
Definition: flash7.h:219
flash7_write_disable
void flash7_write_disable(flash7_t *ctx)
Write disable function.
flash7_read_id
void flash7_read_id(flash7_t *ctx, uint8_t *manufacturer_id, uint8_t *device_id)
Read ID function.