flash9 2.0.0.0
flash9.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 FLASH9_H
29#define FLASH9_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
74#define FLASH9_CMD_READ_STATUS_REGISTER_1 0x05
75#define FLASH9_CMD_READ_STATUS_REGISTER_2 0x35
76#define FLASH9_CMD_READ_STATUS_REGISTER_3 0x15
77#define FLASH9_CMD_READ_SFDP_REGISTER 0x5A
78#define FLASH9_CMD_ERASE_PROGRAM_SUSPEND 0x75
79#define FLASH9_CMD_ERASE_PROGRAM_RESUME 0x7A
80
85#define FLASH9_CMD_WRITE_ENABLE 0x06
86#define FLASH9_CMD_VOLATILE_SR_WRITE_ENABLE 0x50
87#define FLASH9_CMD_WRITE_DISABLE 0x04
88#define FLASH9_CMD_READ_UNIQUE_ID 0x4B
89#define FLASH9_CMD_RELEASE_POWER_DOWN_ID 0xAB
90#define FLASH9_CMD_MANUFACTURER_DEVICE_ID 0x90
91#define FLASH9_CMD_JEDEC_ID 0x9F
92#define FLASH9_CMD_CHIP_ERASE 0xC7
93#define FLASH9_CMD_WRITE_STATUS_REGISTER_1 0x01
94#define FLASH9_CMD_WRITE_STATUS_REGISTER_2 0x31
95#define FLASH9_CMD_WRITE_STATUS_REGISTER_3 0x11
96#define FLASH9_CMD_GLOBAL_BLOCK_LOCK 0x7E
97#define FLASH9_CMD_GLOBAL_BLOCK_UNLOCK 0x98
98#define FLASH9_CMD_POWER_DOWN 0xB9
99#define FLASH9_CMD_ENTER_4BYTE_ADDRESS_MODE 0xB7
100#define FLASH9_CMD_EXIT_4BYTE_ADDRESS_MODE 0xE9
101#define FLASH9_CMD_ENABLE_RESET 0x66
102#define FLASH9_CMD_RESET_DEVICE 0x99
103#define FLASH9_CMD_SOFTWARE_DIE_SELECT 0xC2
104
109#define FLASH9_CMD_READ_DATA 0x03
110#define FLASH9_CMD_READ_DATA_WITH_4BYTE_ADDRESS 0x13
111#define FLASH9_CMD_FAST_READ 0x0B
112#define FLASH9_CMD_FAST_READ_WITH_4BYTE_ADDRESS 0x0C
113#define FLASH9_CMD_PAGE_PROGRAM 0x02
114#define FLASH9_CMD_PAGE_PROGRAM_WITH_4BYTE_ADDRESS 0x12
115#define FLASH9_CMD_SECTOR_ERASE 0x20
116#define FLASH9_CMD_SECTOR_ERASE_WITH_4BYTE_ADDRESS 0x21
117#define FLASH9_CMD_BLOCK_ERASE_32KB 0x52
118#define FLASH9_CMD_BLOCK_ERASE_64KB 0xD8
119#define FLASH9_CMD_BLOCK_ERASE_64KB_WITH_4BYTE_ADDRESS 0xDC
120#define FLASH9_CMD_ERASE_SECURITY_REGISTER 0x44
121#define FLASH9_CMD_PROGRAM_SECURITY_REGISTER 0x42
122#define FLASH9_CMD_READ_SECURITY_REGISTER 0x48
123#define FLASH9_CMD_READ_BLOCK_LOCK 0x3D
124#define FLASH9_CMD_INDIVIDUAL_BLOCK_LOCK 0x36
125#define FLASH9_CMD_INDIVIDUAL_BLOCK_UNLOCK 0x39
126
127 // flash9_reg
128
143#define FLASH9_JEDEC_MANUFACTURER_ID 0xEF
144#define FLASH9_JEDEC_MEMORY_TYPE 0x70
145#define FLASH9_JEDEC_CAPACITY 0x22
146
151#define FLASH9_MIN_ADDRESS 0x00000000
152#define FLASH9_MAX_ADDRESS 0x0FFFFFFFul
153
162#define FLASH9_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
163#define FLASH9_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
164
165 // flash9_set
166
181#define FLASH9_MAP_MIKROBUS( cfg, mikrobus ) \
182 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
183 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
184 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
185 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
186 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
187 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
188 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
189
190 // flash9_map
191 // flash9
192
197typedef struct
198{
199 // Output pins
200 digital_out_t wp;
201 digital_out_t rst;
202 digital_out_t hld;
204 // Modules
205 spi_master_t spi;
207 pin_name_t chip_select;
209} flash9_t;
210
215typedef 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 pin_name_t wp;
225 pin_name_t rst;
226 pin_name_t hld;
228 // static variable
229 uint32_t spi_speed;
230 spi_master_mode_t spi_mode;
231 spi_master_chip_select_polarity_t cs_polarity;
234
239typedef enum
240{
242 FLASH9_ERROR = -1
243
245
262
277err_t flash9_init ( flash9_t *ctx, flash9_cfg_t *cfg );
278
293
306err_t flash9_generic_write ( flash9_t *ctx, uint8_t *data_in, uint16_t in_len );
307
323err_t flash9_generic_read ( flash9_t *ctx, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint16_t out_len ) ;
324
339err_t flash9_write_register ( flash9_t *ctx, uint8_t reg, uint8_t *data_in, uint16_t in_len );
340
355err_t flash9_read_register ( flash9_t *ctx, uint8_t reg, uint8_t *data_out, uint16_t out_len );
356
369err_t flash9_write_command ( flash9_t *ctx, uint8_t cmd );
370
380void flash9_set_wp_pin ( flash9_t *ctx, uint8_t state );
381
391void flash9_set_hld_pin ( flash9_t *ctx, uint8_t state );
392
402void flash9_set_rst_pin ( flash9_t *ctx, uint8_t state );
403
416
430err_t flash9_erase_memory ( flash9_t *ctx, uint8_t erase_cmd, uint32_t address );
431
445err_t flash9_read_status ( flash9_t *ctx, uint8_t status_cmd, uint8_t *status );
446
460err_t flash9_write_status ( flash9_t *ctx, uint8_t status_cmd, uint8_t status );
461
477err_t flash9_memory_write ( flash9_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len );
478
494err_t flash9_memory_read ( flash9_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
495
511err_t flash9_memory_read_fast ( flash9_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
512
513#ifdef __cplusplus
514}
515#endif
516#endif // FLASH9_H
517
518 // flash9
519
520// ------------------------------------------------------------------------ END
flash9_return_value_t
Flash 9 Click return value data.
Definition flash9.h:240
@ FLASH9_OK
Definition flash9.h:241
@ FLASH9_ERROR
Definition flash9.h:242
err_t flash9_read_status(flash9_t *ctx, uint8_t status_cmd, uint8_t *status)
Flash 9 read status function.
err_t flash9_erase_memory(flash9_t *ctx, uint8_t erase_cmd, uint32_t address)
Flash 9 erase memory function.
err_t flash9_read_register(flash9_t *ctx, uint8_t reg, uint8_t *data_out, uint16_t out_len)
Flash 9 read register function.
err_t flash9_init(flash9_t *ctx, flash9_cfg_t *cfg)
Flash 9 initialization function.
void flash9_set_hld_pin(flash9_t *ctx, uint8_t state)
Flash 9 set hld pin function.
err_t flash9_generic_write(flash9_t *ctx, uint8_t *data_in, uint16_t in_len)
Flash 9 generic write function.
err_t flash9_write_command(flash9_t *ctx, uint8_t cmd)
Flash 9 write command function.
err_t flash9_generic_read(flash9_t *ctx, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint16_t out_len)
Flash 9 generic read function.
err_t flash9_memory_write(flash9_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len)
Flash 9 memory write function.
err_t flash9_memory_read_fast(flash9_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len)
Flash 9 memory read fast function.
err_t flash9_memory_read(flash9_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len)
Flash 9 memory read function.
err_t flash9_write_register(flash9_t *ctx, uint8_t reg, uint8_t *data_in, uint16_t in_len)
Flash 9 write register function.
void flash9_set_wp_pin(flash9_t *ctx, uint8_t state)
Flash 9 set wp pin function.
err_t flash9_check_communication(flash9_t *ctx)
Flash 9 check communication function.
void flash9_set_rst_pin(flash9_t *ctx, uint8_t state)
Flash 9 set rst pin function.
void flash9_cfg_setup(flash9_cfg_t *cfg)
Flash 9 configuration object setup function.
err_t flash9_default_cfg(flash9_t *ctx)
Flash 9 default configuration function.
err_t flash9_write_status(flash9_t *ctx, uint8_t status_cmd, uint8_t status)
Flash 9 write status function.
This file contains SPI specific macros, functions, etc.
Flash 9 Click configuration object.
Definition flash9.h:216
pin_name_t hld
Definition flash9.h:226
spi_master_chip_select_polarity_t cs_polarity
Definition flash9.h:231
pin_name_t sck
Definition flash9.h:220
spi_master_mode_t spi_mode
Definition flash9.h:230
pin_name_t mosi
Definition flash9.h:219
uint32_t spi_speed
Definition flash9.h:229
pin_name_t wp
Definition flash9.h:224
pin_name_t miso
Definition flash9.h:218
pin_name_t rst
Definition flash9.h:225
pin_name_t cs
Definition flash9.h:221
Flash 9 Click context object.
Definition flash9.h:198
digital_out_t hld
Definition flash9.h:202
spi_master_t spi
Definition flash9.h:205
digital_out_t rst
Definition flash9.h:201
pin_name_t chip_select
Definition flash9.h:207
digital_out_t wp
Definition flash9.h:200