42#ifdef PREINIT_SUPPORTED
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
52#include "drv_digital_out.h"
53#include "drv_spi_master.h"
65#define FLASH_MEM_ADDR_FIRST_PAGE_START 0x0
66#define FLASH_MEM_ADDR_FIRST_PAGE_END 0xFF
67#define FLASH_MEM_ADDR_SECOND_PAGE_START 0x100
68#define FLASH_MEM_ADDR_SECOND_PAGE_END 0x1FF
69#define FLASH_MEM_ADDR_LAST_PAGE_START 0xFFF00
70#define FLASH_MEM_ADDR_LAST_PAGE_END 0xFFFFF
71#define FLASH_MEM_ADDR_FIRST_SECTOR_START 0x0
72#define FLASH_MEM_ADDR_FIRST_SECTOR_END 0xFFF
73#define FLASH_MEM_ADDR_LAST_SECTOR_START 0xFF000
74#define FLASH_MEM_ADDR_LAST_SECTOR_END 0xFFFFF
75#define FLASH_MEM_ADDR_FIRST_BLOCK_START 0x0
76#define FLASH_MEM_ADDR_FIRST_BLOCK_END 0xFFFF
77#define FLASH_MEM_ADDR_LAST_BLOCK_START 0xF0000
78#define FLASH_MEM_ADDR_LAST_BLOCK_END 0xFFFFF
85#define FLASH_NDATA_TRANSFER_MIN 1
86#define FLASH_NDATA_TRANSFER_MAX 256
98#define FLASH_STATUS_MASK_WRITE_BUSY 0x1
99#define FLASH_STATUS_MASK_WRITE_EN 0x2
100#define FLASH_STATUS_MASK_BLOCK_PROTECT 0x3C
101#define FLASH_STATUS_MASK_WP_DIS 0x40
102#define FLASH_STATUS_MASK_OTP_LOCK 0x80
109#define FLASH_STATUS_SET_BLOCK_PROT_BIT0 0x4
110#define FLASH_STATUS_SET_BLOCK_PROT_BIT1 0x8
111#define FLASH_STATUS_SET_BLOCK_PROT_BIT2 0x10
112#define FLASH_STATUS_SET_BLOCK_PROT_BIT3 0x20
113#define FLASH_STATUS_SET_WP_DIS 0x40
114#define FLASH_STATUS_SET_OTP_LOCK 0x80
123#define FLASH_MAP_MIKROBUS( cfg, mikrobus ) \
124 cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
125 cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
126 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
127 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
128 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_RST ); \
129 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
void flash_default_cfg(flash_t *ctx)
Click Default Configuration function.
uint8_t flash_read_status(flash_t *ctx)
Status Read function.
void flash_write_disable(flash_t *ctx)
Write Disable function.
void flash_write_enable(flash_t *ctx)
Write Enable function.
flash_err_t flash_erase_half_block(flash_t *ctx, uint32_t mem_addr)
Half Block Erase function.
void flash_set_write_protect_pin(flash_t *ctx, flash_pin_state_t state)
WP Pin Set function.
flash_err_t flash_write_byte(flash_t *ctx, uint32_t mem_addr, uint8_t data_tx)
Byte Write function.
flash_err_t flash_read_byte(flash_t *ctx, uint32_t mem_addr, uint8_t *data_rx)
Byte Read function.
void flash_set_hold_pin(flash_t *ctx, flash_pin_state_t state)
HLD Pin Set function.
void flash_cfg_setup(flash_cfg_t *cfg)
Config Object Setup function.
void flash_erase_chip(flash_t *ctx)
Chip Erase function.
void flash_write_status(flash_t *ctx, uint8_t data_tx)
Status Write function.
flash_err_t flash_write_page(flash_t *ctx, uint32_t mem_addr, uint8_t *data_tx, uint16_t n_data)
Page Write function.
flash_err_t flash_erase_block(flash_t *ctx, uint32_t mem_addr)
Block Erase function.
void flash_read_id(flash_t *ctx, uint8_t *manufact_id, uint16_t *dev_id)
ID Read function.
void flash_reset(flash_t *ctx)
Reset function.
flash_err_t flash_erase_sector(flash_t *ctx, uint32_t mem_addr)
Sector Erase function.
flash_err_t flash_read_page(flash_t *ctx, uint32_t mem_addr, uint8_t *data_rx, uint16_t n_data)
Page Read function.
flash_err_t flash_init(flash_t *ctx, flash_cfg_t *cfg)
Click Initialization function.
flash_err_t
Click error code definition.
Definition flash.h:143
flash_pin_state_t
Click pin states.
Definition flash.h:155
@ FLASH_ERR_MEM_ADDR
Definition flash.h:146
@ FLASH_ERR_INIT_DRV
Definition flash.h:145
@ FLASH_ERR_NDATA
Definition flash.h:147
@ FLASH_OK
Definition flash.h:144
@ FLASH_PIN_STATE_LOW
Definition flash.h:156
@ FLASH_PIN_STATE_HIGH
Definition flash.h:157
Click configuration structure definition.
Definition flash.h:183
pin_name_t hld
Definition flash.h:191
pin_name_t sdi
Definition flash.h:186
spi_master_chip_select_polarity_t cs_polarity
Definition flash.h:197
pin_name_t sck
Definition flash.h:187
spi_master_mode_t spi_mode
Definition flash.h:196
uint32_t spi_speed
Definition flash.h:195
pin_name_t wp
Definition flash.h:192
pin_name_t sdo
Definition flash.h:185
pin_name_t cs
Definition flash.h:188
Click context object definition.
Definition flash.h:165
digital_out_t cs
Definition flash.h:167
digital_out_t hld
Definition flash.h:170
spi_master_t spi
Definition flash.h:174
pin_name_t chip_select
Definition flash.h:175
digital_out_t wp
Definition flash.h:171