flash13 2.2.0
Loading...
Searching...
No Matches
flash13.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
27
28#ifndef FLASH13_H
29#define FLASH13_H
30
31#ifdef __cplusplus
32extern "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
59
64
69
74#define FLASH13_CMD_WRITE_ENABLE 0x06
75#define FLASH13_CMD_VOLATILE_SR_WRITE_ENABLE 0x50
76#define FLASH13_CMD_WRITE_DISABLE 0x04
77#define FLASH13_CMD_READ_STATUS_REG_1 0x05
78#define FLASH13_CMD_WRITE_STATUS_REG_1 0x01
79#define FLASH13_CMD_READ_STATUS_REG_2 0x35
80#define FLASH13_CMD_WRITE_STATUS_REG_2 0x31
81#define FLASH13_CMD_READ_STATUS_REG_3 0x15
82#define FLASH13_CMD_WRITE_STATUS_REG_3 0x11
83#define FLASH13_CMD_CHIP_ERASE 0x60
84#define FLASH13_CMD_ERASE_PROGRAM_SUSPEND 0x75
85#define FLASH13_CMD_ERASE_PROGRAM_RESUME 0x7A
86#define FLASH13_CMD_POWER_DOWN 0xB9
87#define FLASH13_CMD_RELEASE_POWER_DOWN 0xAB
88#define FLASH13_CMD_MANUFACTURER_DEVICE_ID 0x90
89#define FLASH13_CMD_JEDEC_ID 0x9F
90#define FLASH13_CMD_ENABLE_RESET 0x66
91#define FLASH13_CMD_RESET_DEVICE 0x99
92#define FLASH13_CMD_READ_SERIAL_FLASH_DISC_PAR 0x5A
93#define FLASH13_CMD_READ_UNIQUE_ID 0x4B
94
99#define FLASH13_CMD_PAGE_PROGRAM 0x02
100#define FLASH13_CMD_SECTOR_ERASE_4KB 0x20
101#define FLASH13_CMD_BLOCK_ERASE_32KB 0x52
102#define FLASH13_CMD_BLOCK_ERASE_64KB 0xD8
103#define FLASH13_CMD_READ_DATA 0x03
104#define FLASH13_CMD_FAST_READ 0x0B
105#define FLASH13_CMD_ERASE_SECURITY_REG 0x44
106#define FLASH13_CMD_PROGRAM_SECURITY_REG 0x42
107#define FLASH13_CMD_READ_SECURITY_REG 0x48
108#define FLASH13_CMD_SET_BURST_WITH_WRAP 0x77
109 // flash13_reg
111
116
121
126#define FLASH13_STATUS3_HOLD_RST 0x80
127#define FLASH13_STATUS3_DRV1 0x40
128#define FLASH13_STATUS3_DRV0 0x20
129#define FLASH13_STATUS3_DC 0x10
130#define FLASH13_STATUS2_SUS1 0x80
131#define FLASH13_STATUS2_CMP 0x40
132#define FLASH13_STATUS2_LB3 0x20
133#define FLASH13_STATUS2_LB2 0x10
134#define FLASH13_STATUS2_LB1 0x08
135#define FLASH13_STATUS2_SUS2 0x04
136#define FLASH13_STATUS2_QE 0x02
137#define FLASH13_STATUS2_SRP1 0x01
138#define FLASH13_STATUS1_SRP0 0x80
139#define FLASH13_STATUS1_BP4 0x40
140#define FLASH13_STATUS1_BP3 0x20
141#define FLASH13_STATUS1_BP2 0x10
142#define FLASH13_STATUS1_BP1 0x08
143#define FLASH13_STATUS1_BP0 0x04
144#define FLASH13_STATUS1_WEL 0x02
145#define FLASH13_STATUS1_WIP 0x01
146
151#define FLASH13_MIN_ADDRESS 0x000000ul
152#define FLASH13_MAX_ADDRESS 0x1FFFFFul
153#define FLASH13_PAGE_SIZE 256
154
159#define FLASH13_MANUFACTURER_ID 0x68
160#define FLASH13_DEVICE_ID 0x14
161
170#define FLASH13_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
171#define FLASH13_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
172 // flash13_set
174
179
184
189#define FLASH13_MAP_MIKROBUS( cfg, mikrobus ) \
190 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
191 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
192 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
193 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
194 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
195 cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM );
196 // flash13_map // flash13
199
204typedef struct
205{
206 // Output pins
207 digital_out_t hold;
208 digital_out_t wp;
209
210 // Modules
211 spi_master_t spi;
212
213 pin_name_t chip_select;
214
215} flash13_t;
216
221typedef struct
222{
223 // Communication gpio pins
224 pin_name_t miso;
225 pin_name_t mosi;
226 pin_name_t sck;
227 pin_name_t cs;
228
229 // Additional gpio pins
230 pin_name_t hold;
231 pin_name_t wp;
232
233 // static variable
234 uint32_t spi_speed;
235 spi_master_mode_t spi_mode;
236 spi_master_chip_select_polarity_t cs_polarity;
237
239
244typedef enum
245{
248
250
256
267
282
294err_t flash13_write_cmd ( flash13_t *ctx, uint8_t cmd );
295
310err_t flash13_write_cmd_data ( flash13_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
311
326err_t flash13_read_cmd_data ( flash13_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len );
327
343err_t flash13_write_cmd_address_data ( flash13_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_in, uint32_t len );
344
360err_t flash13_read_cmd_address_data ( flash13_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_out, uint32_t len );
361
376err_t flash13_memory_write ( flash13_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len );
377
392err_t flash13_memory_read ( flash13_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
393
407err_t flash13_erase_memory ( flash13_t *ctx, uint8_t erase_cmd, uint32_t address );
408
420
430
440
452
462void flash13_set_wp_pin ( flash13_t *ctx, uint8_t state );
463
473void flash13_set_hold_pin ( flash13_t *ctx, uint8_t state );
474
475#ifdef __cplusplus
476}
477#endif
478#endif // FLASH13_H
479 // flash13
481
482// ------------------------------------------------------------------------ END
flash13_return_value_t
Flash 13 Click return value data.
Definition flash13.h:245
@ FLASH13_OK
Definition flash13.h:246
@ FLASH13_ERROR
Definition flash13.h:247
void flash13_cfg_setup(flash13_cfg_t *cfg)
Flash 13 configuration object setup function.
err_t flash13_init(flash13_t *ctx, flash13_cfg_t *cfg)
Flash 13 initialization function.
err_t flash13_memory_write(flash13_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len)
Flash 13 memory write function.
err_t flash13_write_cmd_address_data(flash13_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_in, uint32_t len)
Flash 13 write cmd address data function.
err_t flash13_soft_reset(flash13_t *ctx)
Flash 13 soft reset function.
err_t flash13_memory_read(flash13_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
Flash 13 memory read function.
err_t flash13_read_cmd_address_data(flash13_t *ctx, uint8_t cmd, uint32_t address, uint8_t *data_out, uint32_t len)
Flash 13 read cmd address data function.
err_t flash13_check_communication(flash13_t *ctx)
Flash 13 check communication function.
err_t flash13_erase_memory(flash13_t *ctx, uint8_t erase_cmd, uint32_t address)
Flash 13 erase memory function.
void flash13_set_hold_pin(flash13_t *ctx, uint8_t state)
Flash 13 set hold pin function.
err_t flash13_write_cmd_data(flash13_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
Flash 13 write cmd data function.
err_t flash13_write_enable(flash13_t *ctx)
Flash 13 write enable function.
err_t flash13_read_cmd_data(flash13_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len)
Flash 13 read cmd data function.
err_t flash13_write_protect(flash13_t *ctx)
Flash 13 write protect function.
void flash13_set_wp_pin(flash13_t *ctx, uint8_t state)
Flash 13 set wp pin function.
err_t flash13_write_cmd(flash13_t *ctx, uint8_t cmd)
Flash 13 write cmd function.
This file contains SPI specific macros, functions, etc.
Flash 13 Click configuration object.
Definition flash13.h:222
spi_master_chip_select_polarity_t cs_polarity
Definition flash13.h:236
pin_name_t sck
Definition flash13.h:226
spi_master_mode_t spi_mode
Definition flash13.h:235
pin_name_t mosi
Definition flash13.h:225
uint32_t spi_speed
Definition flash13.h:234
pin_name_t wp
Definition flash13.h:231
pin_name_t miso
Definition flash13.h:224
pin_name_t hold
Definition flash13.h:230
pin_name_t cs
Definition flash13.h:227
Flash 13 Click context object.
Definition flash13.h:205
spi_master_t spi
Definition flash13.h:211
digital_out_t hold
Definition flash13.h:207
pin_name_t chip_select
Definition flash13.h:213
digital_out_t wp
Definition flash13.h:208