flash5 2.0.0.0
flash5.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 FLASH5_H
36#define FLASH5_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define FLASH5_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM );
80#define FLASH5_RETVAL uint8_t
81
82#define FLASH5_OK 0x00
83#define FLASH5_INIT_ERROR 0xFF
90#define FLASH5_MAX_addr 0xFFFF
91#define FLASH5_PAGESIZE 2048
98#define FLASH5_CMD_RESET 0xFF
99#define FLASH5_CMD_DEVICE_ID 0x9F
100#define FLASH5_CMD_READ_REG_STATUS1 0x05
101#define FLASH5_CMD_READ_REG_STATUS2 0x0F
102#define FLASH5_CMD_WRITE_REG_STATUS1 0x01
103#define FLASH5_CMD_WRITE_REG_STATUS2 0x1F
104#define FLASH5_CMD_WRITE_ENABLE 0x06
105#define FLASH5_CMD_WRITE_DISABLE 0x04
106#define FLASH5_CMD_BAD_BLOCK_MANAGE 0xA1
107#define FLASH5_CMD_READ_BBM_TABLE 0xA5
108#define FLASH5_CMD_LAST_ECC_FAIL_PAGE 0xA9
109#define FLASH5_CMD_BLOCK_ERASE 0xD8
110#define FLASH5_CMD_LOAD_DATA 0x02
111#define FLASH5_CMD__RND_LOAD_DATA 0x84
112#define FLASH5_CMD_QUAD_LOAD_DATA 0x32
113#define FLASH5_CMD_QUAD_RND_LOAD_DATA 0x34
114#define FLASH5_CMD_EXECUTE 0x10
115#define FLASH5_CMD_PAGE_READ_DATA 0x13
116#define FLASH5_CMD_READ_DATA 0x03
117#define FLASH5_CMD_FAST_READ 0x0B
118#define FLASH5_CMD_FAST_READ_4BYTE_addr 0x0C
119#define FLASH5_CMD_FAST_READ_DUAL_OUT 0x3B
120#define FLASH5_CMD_FAST_READ_DUAL_OUT_4BYTE_addr 0x3C
121#define FLASH5_CMD_FAST_READ_QUAD_OUT 0x6B
122#define FLASH5_CMD_FAST_READ_QUAD_OUT_4BYTE_addr 0x6C
123#define FLASH5_CMD_FAST_READ_DUAL_IO 0xBB
124#define FLASH5_CMD_FAST_READ_IO_4BYTE_addr 0xBC
125#define FLASH5_CMD_FAST_READ_QUAD_IO 0xEB
126#define FLASH5_CMD_FAST_READ_QUAD_IO_4BYTE_addr 0xEC
133#define FLASH5_REG_STATUS_1 0xA0
134#define FLASH5_REG_STATUS_2 0xB0
135#define FLASH5_REG_STATUS_3 0xC0
142#define FLASH5_RS1_WRITE_PROTECTION_ENABLE 0x02
143#define FLASH5_RS1_WRITE_PROTECTION_DISABLE 0x00
144#define FLASH5_RS1_SRP1_ENABLE 0x01
145#define FLASH5_RS1_SRP2_ENABLE 0x80
152#define FLASH5_RS2_PAGE_READ_MODE 0x08
153#define FLASH5_RS2_PAGE_CONTINOUS_READ_MODE 0x00
154#define FLASH5_RS2_ECC_ENABLED 0x10
155#define FLASH5_RS2_ECC_DISABLED 0x10
156#define FLASH5_RS2_OTP_LOCK 0x80
157#define FLASH5_RS2_OTP_ACCESS 0x40
158#define FLASH5_RS2_REG_STATUS_1_LOCK 0x20
165#define FLASH5_DEVICE_OK 0xFF
166#define FLASH5_DEVICE_ERROR 0xAA
173#define FLASH5_PIN_STATUS_HIGH 1
174#define FLASH5_PIN_STATUS_LOW 0
177 // End group macro
178// --------------------------------------------------------------- PUBLIC TYPES
187typedef struct
188{
189 // Output pins
190
191 digital_out_t cs;
192 digital_out_t wp;
193 digital_out_t hld;
194
195 // Modules
196
197 spi_master_t spi;
198 pin_name_t chip_select;
199
200} flash5_t;
201
205typedef struct
206{
207 // Communication gpio pins
208
209 pin_name_t miso;
210 pin_name_t mosi;
211 pin_name_t sck;
212 pin_name_t cs;
213
214 // Additional gpio pins
215
216 pin_name_t wp;
217 pin_name_t hld;
218
219 // static variable
220
221 uint32_t spi_speed;
222 spi_master_mode_t spi_mode;
223 spi_master_chip_select_polarity_t cs_polarity;
224
226
227 // End types group
228// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
229
234#ifdef __cplusplus
235extern "C"{
236#endif
237
247
257
269void flash5_generic_transfer ( flash5_t *ctx, uint8_t *wr_buf,
270 uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
271
280void flash5_read_data ( flash5_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t n_buf_size );
281
290void flash5_write_data ( flash5_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t n_buf_size );
291
298void flash5_send_cmd ( flash5_t *ctx, uint8_t cmd_data );
299
308uint8_t flash5_set_wp_pin ( flash5_t *ctx, uint8_t status );
309
318uint8_t flash5_set_hold_pin ( flash5_t *ctx, uint8_t status );
319
328
335void flash5_page_read ( flash5_t *ctx, uint16_t page_num );
336
343void flash5_execute_load ( flash5_t *ctx, uint16_t page_num );
344
353void flash5_page_read_memory ( flash5_t *ctx, uint16_t column_addr, uint8_t *data_buf, uint16_t buf_size );
354
364void flash5_continous_read_memory ( flash5_t *ctx, uint8_t *data_buf, uint16_t buf_size );
365
374void flash5_page_load_memory ( flash5_t *ctx, uint16_t column_addr, uint8_t *data_buf, uint16_t buf_size );
375
385uint8_t flash5_read_status_data ( flash5_t *ctx, uint8_t status_cmd, uint8_t status_addr );
386
395void flash5_write_status_data ( flash5_t *ctx, uint8_t status_cmd, uint8_t status_addr, uint8_t status_data );
396
403
410void flash5_erase_page_data ( flash5_t *ctx, uint16_t page_addr );
411
412#ifdef __cplusplus
413}
414#endif
415#endif // _FLASH5_H_
416
417 // End public_function group
419
420// ------------------------------------------------------------------------- END
#define FLASH5_RETVAL
Definition flash5.h:80
void flash5_page_read(flash5_t *ctx, uint16_t page_num)
Function for setting page read.
void flash5_execute_load(flash5_t *ctx, uint16_t page_num)
Function for executing page load.
void flash5_erase_page_data(flash5_t *ctx, uint16_t page_addr)
Function for eraseing one page.
void flash5_write_data(flash5_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t n_buf_size)
Generic funcion for writing.
void flash5_page_load_memory(flash5_t *ctx, uint16_t column_addr, uint8_t *data_buf, uint16_t buf_size)
Function for loading one page.
void flash5_read_data(flash5_t *ctx, uint8_t reg_addr, uint8_t *data_buf, uint16_t n_buf_size)
Generic funcion for reading.
void flash5_send_cmd(flash5_t *ctx, uint8_t cmd_data)
Function for sending one Byte od data.
uint8_t flash5_set_hold_pin(flash5_t *ctx, uint8_t status)
Sets hold pin to one state.
void flash5_generic_transfer(flash5_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t flash5_set_wp_pin(flash5_t *ctx, uint8_t status)
Sets wp pin to one state.
void flash5_cfg_setup(flash5_cfg_t *cfg)
Config Object Initialization function.
void flash5_continous_read_memory(flash5_t *ctx, uint8_t *data_buf, uint16_t buf_size)
Function for continous reading.
uint8_t flash5_read_status_data(flash5_t *ctx, uint8_t status_cmd, uint8_t status_addr)
Function for reading status data.
void flash5_software_reset(flash5_t *ctx)
Function for reseting device.
uint8_t flash5_device_id_check(flash5_t *ctx)
Funcion for checking device id.
void flash5_page_read_memory(flash5_t *ctx, uint16_t column_addr, uint8_t *data_buf, uint16_t buf_size)
Function for reading one page.
void flash5_write_status_data(flash5_t *ctx, uint8_t status_cmd, uint8_t status_addr, uint8_t status_data)
Function for writing status data.
FLASH5_RETVAL flash5_init(flash5_t *ctx, flash5_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition flash5.h:206
pin_name_t hld
Definition flash5.h:217
spi_master_chip_select_polarity_t cs_polarity
Definition flash5.h:223
pin_name_t sck
Definition flash5.h:211
spi_master_mode_t spi_mode
Definition flash5.h:222
pin_name_t mosi
Definition flash5.h:210
uint32_t spi_speed
Definition flash5.h:221
pin_name_t wp
Definition flash5.h:216
pin_name_t miso
Definition flash5.h:209
pin_name_t cs
Definition flash5.h:212
Click ctx object definition.
Definition flash5.h:188
digital_out_t cs
Definition flash5.h:191
digital_out_t hld
Definition flash5.h:193
spi_master_t spi
Definition flash5.h:197
pin_name_t chip_select
Definition flash5.h:198
digital_out_t wp
Definition flash5.h:192