flash6  2.0.0.0
flash6.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef FLASH6_H
36 #define FLASH6_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define FLASH6_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69 
75 #define FLASH6_RETVAL uint8_t
76 
77 #define FLASH6_OK 0x00
78 #define FLASH6_INIT_ERROR 0xFF
79 
85 #define FLASH6_CMD_WRITE_ENABLE 0x06
86 #define FLASH6_CMD_VOL_SR_WRITE_ENABLE 0x50
87 #define FLASH6_CMD_WRITE_DISABLE 0x04
88 #define FLASH6_CMD_RELEASE_POWER_DOWN_ID 0xAB
89 #define FLASH6_CMD_MANUFACTURER_DEVICE_ID 0x90
90 #define FLASH6_CMD_JEDEC_ID 0x9F
91 #define FLASH6_CMD_UINQUE_ID 0x4B
92 #define FLASH6_CMD_READ_DATA 0x03
93 #define FLASH6_CMD_FAST_READ_DATA 0x0B
94 #define FLASH6_CMD_PAGE_PROGRAM 0x02
95 #define FLASH6_CMD_SECTOR_ERASE_4KB 0x20
96 #define FLASH6_CMD_BLOCK_ERASE_32KB 0x52
97 #define FLASH6_CMD_BLOCK_ERASE_64KB 0xD8
98 #define FLASH6_CMD_CHIP_ERASE 0xC7 //0x60
99 #define FLASH6_CMD_READ_STATUS_1 0x05
100 #define FLASH6_CMD_WRITE_STATUS_1 0x01
101 #define FLASH6_CMD_READ_STATUS_2 0x35
102 #define FLASH6_CMD_WRITE_STATUS_2 0x31
103 #define FLASH6_CMD_READ_STATUS_3 0x15
104 #define FLASH6_CMD_WRITE_STATUS_3 0x11
105 #define FLASH6_CMD_READ_SFDP_REG 0x5A
106 #define FLASH6_CMD_ERASE_SECURITY_REG 0x44
107 #define FLASH6_CMD_PROGRAM_SECURITY_REG 0x42
108 #define FLASH6_CMD_READ_SECURITY_REG 0x48
109 #define FLASH6_CMD_GLOBAL_BLOCK_LOCK 0x7E
110 #define FLASH6_CMD_GLOBAL_BLOCK_UNLOCK 0x98
111 #define FLASH6_CMD_READ_BLOCK_LOCK 0x3D
112 #define FLASH6_CMD_INDIVIDUAL_BLOCK_LOCK 0x36
113 #define FLASH6_CMD_INDIVIDUAL_BLOCK_UNLOCK 0x39
114 #define FLASH6_CMD_ERASE_PROGRAM_SUSPEND 0x75
115 #define FLASH6_CMD_ERASE_PROGRAM_RESUME 0x7A
116 #define FLASH6_CMD_POWER_DOWN 0xB9
117 #define FLASH6_CMD_ENABLE_RESET 0x66
118 #define FLASH6_CMD_RESET_DEVICE 0x99
119 
125 #define FLASH6_DEVICE_ID 0x17
126 #define FLASH6_MANIFACTURE_ID 0xEF
127 
133 #define FLASH6_DEVICE_OK 0xFF
134 #define FLASH6_DEVICE_ERROR 0xAA
135  // End group macro
138 // --------------------------------------------------------------- PUBLIC TYPES
147 typedef struct
148 {
149  digital_out_t cs;
150  // Modules
151 
152  spi_master_t spi;
153  pin_name_t chip_select;
154 
155 } flash6_t;
156 
160 typedef struct
161 {
162  // Communication gpio pins
163 
164  pin_name_t miso;
165  pin_name_t mosi;
166  pin_name_t sck;
167  pin_name_t cs;
168 
169  // static variable
170 
171  uint32_t spi_speed;
172  spi_master_mode_t spi_mode;
173  spi_master_chip_select_polarity_t cs_polarity;
174 
175 } flash6_cfg_t;
176  // End types group
178 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179 
184 #ifdef __cplusplus
185 extern "C"{
186 #endif
187 
197 
206 
216 (
217  flash6_t *ctx,
218  uint8_t *wr_buf,
219  uint16_t wr_len,
220  uint8_t *rd_buf,
221  uint16_t rd_len
222 );
223 
232 void flash6_read_data ( flash6_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t len );
233 
242 void flash6_write_data ( flash6_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t len );
243 
249 void flash6_send_cmd ( flash6_t *ctx, uint8_t cmd_data );
250 
260 uint8_t flash6_get_manufacture_device_id ( flash6_t *ctx, uint8_t *manufacture_id, uint8_t *device_id );
261 
273 void flash6_erase_memory_segment( flash6_t *ctx, uint8_t segment, uint32_t start_addr );
274 
282 uint8_t flash6_read_status_reg ( flash6_t *ctx, uint8_t status_cmd );
283 
291 void flash6_write_status_reg ( flash6_t *ctx, uint8_t status_cmd, uint8_t status_data );
292 
301 void flash6_write_memory_data ( flash6_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_size );
302 
311 void flash6_read_memory_data ( flash6_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_size );
312 
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 #endif // _FLASH6_H_
324  // End public_function group
327 
328 // ------------------------------------------------------------------------- END
flash6_cfg_t::sck
pin_name_t sck
Definition: flash6.h:166
flash6_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash6.h:171
flash6_cfg_t::miso
pin_name_t miso
Definition: flash6.h:164
flash6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash6.h:172
flash6_init
FLASH6_RETVAL flash6_init(flash6_t *ctx, flash6_cfg_t *cfg)
Initialization function.
flash6_erase_memory_segment
void flash6_erase_memory_segment(flash6_t *ctx, uint8_t segment, uint32_t start_addr)
Function for eraseing segment.
flash6_send_cmd
void flash6_send_cmd(flash6_t *ctx, uint8_t cmd_data)
Function for sending one Byte od data.
flash6_read_memory_data
void flash6_read_memory_data(flash6_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_size)
Function used for reading from memory.
flash6_cfg_t::cs
pin_name_t cs
Definition: flash6.h:167
flash6_t
Click ctx object definition.
Definition: flash6.h:148
flash6_generic_transfer
void flash6_generic_transfer(flash6_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
flash6_read_status_reg
uint8_t flash6_read_status_reg(flash6_t *ctx, uint8_t status_cmd)
Function for reading status register.
flash6_t::cs
digital_out_t cs
Definition: flash6.h:149
flash6_read_data
void flash6_read_data(flash6_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t len)
Generic funcion for reading.
flash6_cfg_t
Click configuration structure definition.
Definition: flash6.h:161
flash6_get_manufacture_device_id
uint8_t flash6_get_manufacture_device_id(flash6_t *ctx, uint8_t *manufacture_id, uint8_t *device_id)
Funcion for checking manufacture and device id.
flash6_t::spi
spi_master_t spi
Definition: flash6.h:152
flash6_write_status_reg
void flash6_write_status_reg(flash6_t *ctx, uint8_t status_cmd, uint8_t status_data)
Function for writing status register.
flash6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash6.h:173
flash6_cfg_t::mosi
pin_name_t mosi
Definition: flash6.h:165
flash6_cfg_setup
void flash6_cfg_setup(flash6_cfg_t *cfg)
Config Object Initialization function.
flash6_write_data
void flash6_write_data(flash6_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint8_t len)
Generic funcion for writing.
flash6_write_memory_data
void flash6_write_memory_data(flash6_t *ctx, uint32_t addr, uint8_t *data_buf, uint16_t buf_size)
Function used for writing in memory.
flash6_t::chip_select
pin_name_t chip_select
Definition: flash6.h:153
flash6_software_reset
void flash6_software_reset(flash6_t *ctx)
Function for reseting device.
FLASH6_RETVAL
#define FLASH6_RETVAL
Definition: flash6.h:75