libnile
Loading...
Searching...
No Matches
flash.h File Reference
#include <wonderful.h>
#include "hardware.h"
#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Macros

#define NILE_FLASH_ID_W25Q16JV_IQ   0xEF4015
#define NILE_FLASH_ID_W25Q16JV_IM   0xEF7015
#define NILE_FLASH_SR1_BUSY   (1 << 0)
 Erase/Write in Progress.
#define NILE_FLASH_SR1_WEL   (1 << 1)
 Write Enable Latch.
#define NILE_FLASH_SR1_BP0   (1 << 2)
 Block Protect 0.
#define NILE_FLASH_SR1_BP1   (1 << 3)
 Block Protect 1.
#define NILE_FLASH_SR1_BP2   (1 << 4)
 Block Protect 2.
#define NILE_FLASH_SR1_TB   (1 << 5)
 Top/Bottom Block Protect.
#define NILE_FLASH_SR1_SEC   (1 << 6)
 Sector/Block Protect.
#define NILE_FLASH_SR1_CMP   (1 << 7)
 Complement Protect.
#define NILE_FLASH_SR2_SRL   (1 << 0)
 Status Register Lock.
#define NILE_FLASH_SR2_LB1   (1 << 3)
 Security Register 1 Lock.
#define NILE_FLASH_SR2_LB2   (1 << 4)
 Security Register 2 Lock.
#define NILE_FLASH_SR2_LB3   (1 << 5)
 Security Register 3 Lock.
#define NILE_FLASH_SR2_CMP   (1 << 6)
 Complement Protect.
#define NILE_FLASH_SR2_SUS   (1 << 7)
 Suspend Status.
#define NILE_FLASH_SR3_WPS   (1 << 2)
 Write Protect Selection.
#define NILE_FLASH_SR3_DRV_100   (0)
 Output Driver Strength 100%.
#define NILE_FLASH_SR3_DRV_75   (1 << 5)
 Output Driver Strength 75%.
#define NILE_FLASH_SR3_DRV_50   (2 << 5)
 Output Driver Strength 50%.
#define NILE_FLASH_SR3_DRV_25   (3 << 5)
 Output Driver Strength 25%.
#define NILE_FLASH_SR3_DRV_MASK   (3 << 5)
 Output Driver Strength Mask.
#define NILE_FLASH_CMD_WRSR1   0x01
 Write Status Register 1.
#define NILE_FLASH_CMD_WRITE   0x02
 Write Data.
#define NILE_FLASH_CMD_READ   0x03
 Read Data.
#define NILE_FLASH_CMD_WRDI   0x04
 Write Disable.
#define NILE_FLASH_CMD_RDSR1   0x05
 Read Status Register 1.
#define NILE_FLASH_CMD_WREN   0x06
 Write Enable.
#define NILE_FLASH_CMD_WRSR3   0x11
 Write Status Register 3.
#define NILE_FLASH_CMD_RDSR3   0x15
 Read Status Register 3.
#define NILE_FLASH_CMD_ERASE_4K   0x20
 Sector Erase (4K)
#define NILE_FLASH_CMD_WRSR2   0x31
 Write Status Register 2.
#define NILE_FLASH_CMD_RDSR2   0x35
 Read Status Register 2.
#define NILE_FLASH_CMD_BLOCK_LOCK   0x36
 Individual block lock.
#define NILE_FLASH_CMD_BLOCK_UNLOCK   0x39
 Individual block unlock.
#define NILE_FLASH_CMD_BLOCK_RDLOCK   0x3D
 Read block lock.
#define NILE_FLASH_CMD_SEC_WRITE   0x42
 Write security registers.
#define NILE_FLASH_CMD_SEC_ERASE   0x44
 Erase security registers.
#define NILE_FLASH_CMD_SEC_READ   0x48
 Read security registers.
#define NILE_FLASH_CMD_RDUUID   0x4B
 Read 64-bit Unique ID.
#define NILE_FLASH_CMD_ERASE_32K   0x52
 Block Erase (32K)
#define NILE_FLASH_CMD_RDSFPD   0x5A
 Read SFDP.
#define NILE_FLASH_CMD_RESET_EN   0x66
 Enable reset.
#define NILE_FLASH_CMD_SUSPEND   0x75
 Erase/Program Suspend.
#define NILE_FLASH_CMD_RESUME   0x7A
 Erase/Program Resume.
#define NILE_FLASH_CMD_LOCK   0x7E
 Global lock.
#define NILE_FLASH_CMD_MFR_ID   0x90
 Read Manufacturer / Device ID.
#define NILE_FLASH_CMD_UNLOCK   0x98
 Global unlock.
#define NILE_FLASH_CMD_RESET   0x99
 Reset device.
#define NILE_FLASH_CMD_RDID   0x9F
 Read JEDEC ID.
#define NILE_FLASH_CMD_WAKE_ID   0xAB
 Release Power-down / Device ID.
#define NILE_FLASH_CMD_SLEEP   0xB9
 Power-down.
#define NILE_FLASH_CMD_ERASE_ALL   0xC7
 Chip Erase. Not advisable.
#define NILE_FLASH_CMD_ERASE_64K   0xD8
 Block Erase (64K)

Functions

static bool nile_flash_write_unlock_global (void)
 Unlock global SPI flash writing.
static bool nile_flash_write_enable (void)
 Enable SPI flash writing.
static bool nile_flash_write_disable (void)
 Disable SPI flash writing.
static bool nile_flash_wake (void)
 Wake up SPI flash.
static bool nile_flash_sleep (void)
 Put SPI flash to sleep.
bool nile_flash_read_uuid (uint8_t *buffer)
 Read device UUID (8 bytes) from SPI flash.
uint32_t nile_flash_read_id (void)
 Read JEDEC ID from SPI flash.
bool nile_flash_read (void __far *buffer, uint32_t address, uint16_t size)
 Read data from SPI flash.
bool nile_flash_write_page (const void __far *buffer, uint32_t address, uint16_t size)
 Write page to SPI flash.
static bool nile_flash_erase_part (uint8_t type, uint32_t address)
 Erase area from SPI flash.
static uint8_t nile_flash_read_sr1 (void)
static uint8_t nile_flash_read_sr2 (void)
static uint8_t nile_flash_read_sr3 (void)
static bool nile_flash_write_sr1 (uint8_t value)
static bool nile_flash_write_sr2 (uint8_t value)
static bool nile_flash_write_sr3 (uint8_t value)
bool nile_flash_wait_ready (void)
 Wait until SPI flash is ready.

Macro Definition Documentation

◆ NILE_FLASH_CMD_BLOCK_LOCK

#define NILE_FLASH_CMD_BLOCK_LOCK   0x36

Individual block lock.

Definition at line 66 of file flash.h.

◆ NILE_FLASH_CMD_BLOCK_RDLOCK

#define NILE_FLASH_CMD_BLOCK_RDLOCK   0x3D

Read block lock.

Definition at line 68 of file flash.h.

◆ NILE_FLASH_CMD_BLOCK_UNLOCK

#define NILE_FLASH_CMD_BLOCK_UNLOCK   0x39

Individual block unlock.

Definition at line 67 of file flash.h.

◆ NILE_FLASH_CMD_ERASE_32K

#define NILE_FLASH_CMD_ERASE_32K   0x52

Block Erase (32K)

Definition at line 73 of file flash.h.

◆ NILE_FLASH_CMD_ERASE_4K

#define NILE_FLASH_CMD_ERASE_4K   0x20

Sector Erase (4K)

Definition at line 63 of file flash.h.

◆ NILE_FLASH_CMD_ERASE_64K

#define NILE_FLASH_CMD_ERASE_64K   0xD8

Block Erase (64K)

Definition at line 86 of file flash.h.

◆ NILE_FLASH_CMD_ERASE_ALL

#define NILE_FLASH_CMD_ERASE_ALL   0xC7

Chip Erase. Not advisable.

Definition at line 85 of file flash.h.

◆ NILE_FLASH_CMD_LOCK

#define NILE_FLASH_CMD_LOCK   0x7E

Global lock.

Definition at line 78 of file flash.h.

◆ NILE_FLASH_CMD_MFR_ID

#define NILE_FLASH_CMD_MFR_ID   0x90

Read Manufacturer / Device ID.

Definition at line 79 of file flash.h.

◆ NILE_FLASH_CMD_RDID

#define NILE_FLASH_CMD_RDID   0x9F

Read JEDEC ID.

Definition at line 82 of file flash.h.

◆ NILE_FLASH_CMD_RDSFPD

#define NILE_FLASH_CMD_RDSFPD   0x5A

Read SFDP.

Definition at line 74 of file flash.h.

◆ NILE_FLASH_CMD_RDSR1

#define NILE_FLASH_CMD_RDSR1   0x05

Read Status Register 1.

Definition at line 59 of file flash.h.

◆ NILE_FLASH_CMD_RDSR2

#define NILE_FLASH_CMD_RDSR2   0x35

Read Status Register 2.

Definition at line 65 of file flash.h.

◆ NILE_FLASH_CMD_RDSR3

#define NILE_FLASH_CMD_RDSR3   0x15

Read Status Register 3.

Definition at line 62 of file flash.h.

◆ NILE_FLASH_CMD_RDUUID

#define NILE_FLASH_CMD_RDUUID   0x4B

Read 64-bit Unique ID.

Definition at line 72 of file flash.h.

◆ NILE_FLASH_CMD_READ

#define NILE_FLASH_CMD_READ   0x03

Read Data.

Definition at line 57 of file flash.h.

◆ NILE_FLASH_CMD_RESET

#define NILE_FLASH_CMD_RESET   0x99

Reset device.

Definition at line 81 of file flash.h.

◆ NILE_FLASH_CMD_RESET_EN

#define NILE_FLASH_CMD_RESET_EN   0x66

Enable reset.

Definition at line 75 of file flash.h.

◆ NILE_FLASH_CMD_RESUME

#define NILE_FLASH_CMD_RESUME   0x7A

Erase/Program Resume.

Definition at line 77 of file flash.h.

◆ NILE_FLASH_CMD_SEC_ERASE

#define NILE_FLASH_CMD_SEC_ERASE   0x44

Erase security registers.

Definition at line 70 of file flash.h.

◆ NILE_FLASH_CMD_SEC_READ

#define NILE_FLASH_CMD_SEC_READ   0x48

Read security registers.

Definition at line 71 of file flash.h.

◆ NILE_FLASH_CMD_SEC_WRITE

#define NILE_FLASH_CMD_SEC_WRITE   0x42

Write security registers.

Definition at line 69 of file flash.h.

◆ NILE_FLASH_CMD_SLEEP

#define NILE_FLASH_CMD_SLEEP   0xB9

Power-down.

Definition at line 84 of file flash.h.

◆ NILE_FLASH_CMD_SUSPEND

#define NILE_FLASH_CMD_SUSPEND   0x75

Erase/Program Suspend.

Definition at line 76 of file flash.h.

◆ NILE_FLASH_CMD_UNLOCK

#define NILE_FLASH_CMD_UNLOCK   0x98

Global unlock.

Definition at line 80 of file flash.h.

◆ NILE_FLASH_CMD_WAKE_ID

#define NILE_FLASH_CMD_WAKE_ID   0xAB

Release Power-down / Device ID.

Definition at line 83 of file flash.h.

◆ NILE_FLASH_CMD_WRDI

#define NILE_FLASH_CMD_WRDI   0x04

Write Disable.

Definition at line 58 of file flash.h.

◆ NILE_FLASH_CMD_WREN

#define NILE_FLASH_CMD_WREN   0x06

Write Enable.

Definition at line 60 of file flash.h.

◆ NILE_FLASH_CMD_WRITE

#define NILE_FLASH_CMD_WRITE   0x02

Write Data.

Definition at line 56 of file flash.h.

◆ NILE_FLASH_CMD_WRSR1

#define NILE_FLASH_CMD_WRSR1   0x01

Write Status Register 1.

Definition at line 55 of file flash.h.

◆ NILE_FLASH_CMD_WRSR2

#define NILE_FLASH_CMD_WRSR2   0x31

Write Status Register 2.

Definition at line 64 of file flash.h.

◆ NILE_FLASH_CMD_WRSR3

#define NILE_FLASH_CMD_WRSR3   0x11

Write Status Register 3.

Definition at line 61 of file flash.h.

◆ NILE_FLASH_ID_W25Q16JV_IM

#define NILE_FLASH_ID_W25Q16JV_IM   0xEF7015

Definition at line 30 of file flash.h.

◆ NILE_FLASH_ID_W25Q16JV_IQ

#define NILE_FLASH_ID_W25Q16JV_IQ   0xEF4015

Definition at line 29 of file flash.h.

◆ NILE_FLASH_SR1_BP0

#define NILE_FLASH_SR1_BP0   (1 << 2)

Block Protect 0.

Definition at line 34 of file flash.h.

◆ NILE_FLASH_SR1_BP1

#define NILE_FLASH_SR1_BP1   (1 << 3)

Block Protect 1.

Definition at line 35 of file flash.h.

◆ NILE_FLASH_SR1_BP2

#define NILE_FLASH_SR1_BP2   (1 << 4)

Block Protect 2.

Definition at line 36 of file flash.h.

◆ NILE_FLASH_SR1_BUSY

#define NILE_FLASH_SR1_BUSY   (1 << 0)

Erase/Write in Progress.

Definition at line 32 of file flash.h.

◆ NILE_FLASH_SR1_CMP

#define NILE_FLASH_SR1_CMP   (1 << 7)

Complement Protect.

Definition at line 39 of file flash.h.

◆ NILE_FLASH_SR1_SEC

#define NILE_FLASH_SR1_SEC   (1 << 6)

Sector/Block Protect.

Definition at line 38 of file flash.h.

◆ NILE_FLASH_SR1_TB

#define NILE_FLASH_SR1_TB   (1 << 5)

Top/Bottom Block Protect.

Definition at line 37 of file flash.h.

◆ NILE_FLASH_SR1_WEL

#define NILE_FLASH_SR1_WEL   (1 << 1)

Write Enable Latch.

Definition at line 33 of file flash.h.

◆ NILE_FLASH_SR2_CMP

#define NILE_FLASH_SR2_CMP   (1 << 6)

Complement Protect.

Definition at line 45 of file flash.h.

◆ NILE_FLASH_SR2_LB1

#define NILE_FLASH_SR2_LB1   (1 << 3)

Security Register 1 Lock.

Definition at line 42 of file flash.h.

◆ NILE_FLASH_SR2_LB2

#define NILE_FLASH_SR2_LB2   (1 << 4)

Security Register 2 Lock.

Definition at line 43 of file flash.h.

◆ NILE_FLASH_SR2_LB3

#define NILE_FLASH_SR2_LB3   (1 << 5)

Security Register 3 Lock.

Definition at line 44 of file flash.h.

◆ NILE_FLASH_SR2_SRL

#define NILE_FLASH_SR2_SRL   (1 << 0)

Status Register Lock.

Definition at line 41 of file flash.h.

◆ NILE_FLASH_SR2_SUS

#define NILE_FLASH_SR2_SUS   (1 << 7)

Suspend Status.

Definition at line 46 of file flash.h.

◆ NILE_FLASH_SR3_DRV_100

#define NILE_FLASH_SR3_DRV_100   (0)

Output Driver Strength 100%.

Definition at line 49 of file flash.h.

◆ NILE_FLASH_SR3_DRV_25

#define NILE_FLASH_SR3_DRV_25   (3 << 5)

Output Driver Strength 25%.

Definition at line 52 of file flash.h.

◆ NILE_FLASH_SR3_DRV_50

#define NILE_FLASH_SR3_DRV_50   (2 << 5)

Output Driver Strength 50%.

Definition at line 51 of file flash.h.

◆ NILE_FLASH_SR3_DRV_75

#define NILE_FLASH_SR3_DRV_75   (1 << 5)

Output Driver Strength 75%.

Definition at line 50 of file flash.h.

◆ NILE_FLASH_SR3_DRV_MASK

#define NILE_FLASH_SR3_DRV_MASK   (3 << 5)

Output Driver Strength Mask.

Definition at line 53 of file flash.h.

◆ NILE_FLASH_SR3_WPS

#define NILE_FLASH_SR3_WPS   (1 << 2)

Write Protect Selection.

Definition at line 48 of file flash.h.

Function Documentation

◆ nile_flash_erase_part()

bool nile_flash_erase_part ( uint8_t type,
uint32_t address )
inlinestatic

Erase area from SPI flash.

Parameters
typeType (NILE_FLASH_CMD_ERASE_4K, NILE_FLASH_CMD_ERASE_32K, NILE_FLASH_CMD_ERASE_64K)
addressStarting adddress
Returns
true Write succeeded.
false Write timed out.

Definition at line 168 of file flash.h.

◆ nile_flash_read()

bool nile_flash_read ( void __far * buffer,
uint32_t address,
uint16_t size )

Read data from SPI flash.

Parameters
bufferBuffer to read to
addressAddress to read from
sizeLength of data to be read

◆ nile_flash_read_id()

uint32_t nile_flash_read_id ( void )

Read JEDEC ID from SPI flash.

◆ nile_flash_read_sr1()

uint8_t nile_flash_read_sr1 ( void )
inlinestatic

Definition at line 173 of file flash.h.

◆ nile_flash_read_sr2()

uint8_t nile_flash_read_sr2 ( void )
inlinestatic

Definition at line 178 of file flash.h.

◆ nile_flash_read_sr3()

uint8_t nile_flash_read_sr3 ( void )
inlinestatic

Definition at line 183 of file flash.h.

◆ nile_flash_read_uuid()

bool nile_flash_read_uuid ( uint8_t * buffer)

Read device UUID (8 bytes) from SPI flash.

◆ nile_flash_sleep()

bool nile_flash_sleep ( void )
inlinestatic

Put SPI flash to sleep.

Definition at line 127 of file flash.h.

◆ nile_flash_wait_ready()

bool nile_flash_wait_ready ( void )

Wait until SPI flash is ready.

◆ nile_flash_wake()

bool nile_flash_wake ( void )
inlinestatic

Wake up SPI flash.

Definition at line 119 of file flash.h.

◆ nile_flash_write_disable()

bool nile_flash_write_disable ( void )
inlinestatic

Disable SPI flash writing.

Definition at line 111 of file flash.h.

◆ nile_flash_write_enable()

bool nile_flash_write_enable ( void )
inlinestatic

Enable SPI flash writing.

Definition at line 103 of file flash.h.

◆ nile_flash_write_page()

bool nile_flash_write_page ( const void __far * buffer,
uint32_t address,
uint16_t size )

Write page to SPI flash.

Parameters
bufferBuffer to write from
addressAddress to write to
sizeLength of data to be written

◆ nile_flash_write_sr1()

bool nile_flash_write_sr1 ( uint8_t value)
inlinestatic

Definition at line 188 of file flash.h.

◆ nile_flash_write_sr2()

bool nile_flash_write_sr2 ( uint8_t value)
inlinestatic

Definition at line 193 of file flash.h.

◆ nile_flash_write_sr3()

bool nile_flash_write_sr3 ( uint8_t value)
inlinestatic

Definition at line 198 of file flash.h.

◆ nile_flash_write_unlock_global()

bool nile_flash_write_unlock_global ( void )
inlinestatic

Unlock global SPI flash writing.

Definition at line 95 of file flash.h.