flash12  2.1.0.0
flash12.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 FLASH12_H
29 #define FLASH12_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 #include "spi_specifics.h"
49 
70 #define FLASH12_CMD_READ_ARRAY 0x03
71 #define FLASH12_CMD_FAST_READ_ARRAY 0x0B
72 
77 #define FLASH12_CMD_BYTE_PAGE_PROGRAM 0x02
78 #define FLASH12_CMD_PAGE_ERASE 0x81
79 #define FLASH12_CMD_BLOCK_ERASE_4KB 0x20
80 #define FLASH12_CMD_BLOCK_ERASE_32KB 0x52
81 #define FLASH12_CMD_BLOCK_ERASE_64KB 0xD8
82 #define FLASH12_CMD_CHIP_ERASE 0x60
83 
88 #define FLASH12_CMD_ERASE_SECURITY_REG 0x44
89 #define FLASH12_CMD_PROGRAM_SECURITY_REG 0x42
90 #define FLASH12_CMD_READ_SECURITY_REG 0x48
91 #define FLASH12_CMD_READ_SERIAL_FLASH 0x5A
92 
97 #define FLASH12_CMD_WRITE_ENABLE 0x06
98 #define FLASH12_CMD_VOLATILE_STATUS 0x50
99 #define FLASH12_CMD_WRITE_DISABLE 0x04
100 
105 #define FLASH12_CMD_READ_STATUS_1 0x05
106 #define FLASH12_CMD_WRITE_STATUS_1 0x01
107 #define FLASH12_CMD_READ_STATUS_2 0x35
108 #define FLASH12_CMD_ACT_STATUS_INT 0x25
109 
114 #define FLASH12_CMD_DEEP_POWER_DOWN 0xB9
115 #define FLASH12_CMD_RELEASE_PD_ID 0xAB
116 #define FLASH12_CMD_MANUFACTURER_ID 0x90
117 #define FLASH12_CMD_JEDEC_ID 0x9F
118 #define FLASH12_CMD_READ_UNIQUE_ID_NUM 0x4B
119 
124 #define FLASH12_CMD_ENABLE_RESET 0x66
125 #define FLASH12_CMD_RESET_DEVICE 0x99
126 
127  // flash12_cmd
129 
144 #define FLASH12_MANUFACTURER_ID 0x1F
145 #define FLASH12_DEVICE_ID 0x14
146 
151 #define FLASH12_STATUS1_SRP0 0x80
152 #define FLASH12_STATUS1_BPSIZE 0x40
153 #define FLASH12_STATUS1_TB 0x20
154 #define FLASH12_STATUS1_WEL 0x02
155 #define FLASH12_STATUS1_BSY 0x01
156 
161 #define FLASH12_MIN_ADDRESS 0x000000ul
162 #define FLASH12_MAX_ADDRESS 0x07FFFFul
163 #define FLASH12_PAGE_SIZE 256
164 #define FLASH12_CMD_MAX_LEN 8
165 
174 #define FLASH12_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
175 #define FLASH12_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
176  // flash12_set
178 
193 #define FLASH12_MAP_MIKROBUS( cfg, mikrobus ) \
194  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
195  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
196  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
197  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
198  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
199  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
200  // flash12_map // flash12
203 
208 typedef struct
209 {
210  // Output pins
211  digital_out_t wp;
212  digital_out_t hld;
214  // Modules
215  spi_master_t spi;
217  pin_name_t chip_select;
219 } flash12_t;
220 
225 typedef struct
226 {
227  // Communication gpio pins
228  pin_name_t miso;
229  pin_name_t mosi;
230  pin_name_t sck;
231  pin_name_t cs;
233  // Additional gpio pins
234  pin_name_t wp;
235  pin_name_t hld;
237  // static variable
238  uint32_t spi_speed;
239  spi_master_mode_t spi_mode;
240  spi_master_chip_select_polarity_t cs_polarity;
242 } flash12_cfg_t;
243 
248 typedef enum
249 {
251  FLASH12_ERROR = -1
252 
254 
271 
285 err_t flash12_init ( flash12_t *ctx, flash12_cfg_t *cfg );
286 
300 
314 
328 
342 
356 
368 err_t flash12_write_cmd ( flash12_t *ctx, uint8_t cmd );
369 
384 err_t flash12_write_cmd_data ( flash12_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len );
385 
400 err_t flash12_read_cmd_data ( flash12_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len );
401 
417 err_t flash12_write_cmd_address_data ( flash12_t *ctx, uint8_t cmd, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
418 
434 err_t flash12_read_cmd_address_data ( flash12_t *ctx, uint8_t cmd, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
435 
451 err_t flash12_memory_write ( flash12_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint32_t len );
452 
468 err_t flash12_memory_read ( flash12_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint32_t len );
469 
481 
494 
507 
520 err_t flash12_read_status ( flash12_t *ctx, uint8_t reg_num, uint8_t *status );
521 
534 err_t flash12_write_status ( flash12_t *ctx, uint8_t status );
535 
550 err_t flash12_erase_memory ( flash12_t *ctx, uint8_t erase_cmd, uint32_t mem_addr );
551 
565 err_t flash12_get_device_id ( flash12_t *ctx, uint8_t *mfr_id, uint8_t *dev_id );
566 
567 #ifdef __cplusplus
568 }
569 #endif
570 #endif // FLASH12_H
571  // flash12
573 
574 // ------------------------------------------------------------------------ END
flash12_return_value_t
flash12_return_value_t
Flash 12 Click return value data.
Definition: flash12.h:249
flash12_cfg_t::hld
pin_name_t hld
Definition: flash12.h:235
flash12_soft_reset
err_t flash12_soft_reset(flash12_t *ctx)
Flash 12 soft reset function.
flash12_cfg_t::mosi
pin_name_t mosi
Definition: flash12.h:229
flash12_t::spi
spi_master_t spi
Definition: flash12.h:215
flash12_get_device_id
err_t flash12_get_device_id(flash12_t *ctx, uint8_t *mfr_id, uint8_t *dev_id)
Flash 12 device ID reading function.
flash12_cfg_t::cs
pin_name_t cs
Definition: flash12.h:231
flash12_write_enable
err_t flash12_write_enable(flash12_t *ctx)
Flash 12 write enable function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
flash12_read_cmd_data
err_t flash12_read_cmd_data(flash12_t *ctx, uint8_t cmd, uint8_t *data_out, uint8_t len)
Flash 12 command data reading function.
flash12_hw_write_disable
void flash12_hw_write_disable(flash12_t *ctx)
Flash 12 hardware write disable function.
flash12_read_status
err_t flash12_read_status(flash12_t *ctx, uint8_t reg_num, uint8_t *status)
Flash 12 status reading function.
flash12_write_cmd
err_t flash12_write_cmd(flash12_t *ctx, uint8_t cmd)
Flash 12 command writing function.
flash12_default_cfg
err_t flash12_default_cfg(flash12_t *ctx)
Flash 12 default configuration function.
flash12_t
Flash 12 Click context object.
Definition: flash12.h:209
flash12_t::chip_select
pin_name_t chip_select
Definition: flash12.h:217
flash12_t::hld
digital_out_t hld
Definition: flash12.h:212
flash12_memory_write
err_t flash12_memory_write(flash12_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint32_t len)
Flash 12 memory data writing function.
flash12_erase_memory
err_t flash12_erase_memory(flash12_t *ctx, uint8_t erase_cmd, uint32_t mem_addr)
Flash 12 erase memory function.
flash12_read_cmd_address_data
err_t flash12_read_cmd_address_data(flash12_t *ctx, uint8_t cmd, uint32_t mem_addr, uint8_t *data_out, uint32_t len)
Flash 12 command address data reading function.
flash12_cfg_t::spi_speed
uint32_t spi_speed
Definition: flash12.h:238
FLASH12_ERROR
@ FLASH12_ERROR
Definition: flash12.h:251
flash12_write_cmd_address_data
err_t flash12_write_cmd_address_data(flash12_t *ctx, uint8_t cmd, uint32_t mem_addr, uint8_t *data_in, uint32_t len)
Flash 12 command address data writing function.
flash12_hold_enable
void flash12_hold_enable(flash12_t *ctx)
Flash 12 hold enable function.
flash12_cfg_t::wp
pin_name_t wp
Definition: flash12.h:234
flash12_cfg_t::miso
pin_name_t miso
Definition: flash12.h:228
flash12_write_cmd_data
err_t flash12_write_cmd_data(flash12_t *ctx, uint8_t cmd, uint8_t *data_in, uint8_t len)
Flash 12 command data writing function.
flash12_cfg_t
Flash 12 Click configuration object.
Definition: flash12.h:226
FLASH12_OK
@ FLASH12_OK
Definition: flash12.h:250
flash12_memory_read
err_t flash12_memory_read(flash12_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint32_t len)
Flash 12 memory data reading function.
flash12_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: flash12.h:239
flash12_hw_write_enable
void flash12_hw_write_enable(flash12_t *ctx)
Flash 12 hardware write enable function.
flash12_cfg_setup
void flash12_cfg_setup(flash12_cfg_t *cfg)
Flash 12 configuration object setup function.
flash12_t::wp
digital_out_t wp
Definition: flash12.h:211
flash12_hold_disable
void flash12_hold_disable(flash12_t *ctx)
Flash 12 hold disable function.
flash12_cfg_t::sck
pin_name_t sck
Definition: flash12.h:230
flash12_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: flash12.h:240
flash12_write_disable
err_t flash12_write_disable(flash12_t *ctx)
Flash 12 write disable function.
flash12_init
err_t flash12_init(flash12_t *ctx, flash12_cfg_t *cfg)
Flash 12 initialization function.
flash12_write_status
err_t flash12_write_status(flash12_t *ctx, uint8_t status)
Flash 12 status writing function.