Source code for the Trusted Boot Module.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
tbm-mcu/spi_flash.h

33 lines
943 B

#pragma once
/* Human-readable sizes */
#define KIB 1024
#define MIB (1024 * KIB)
#define GIB (1024 * GIB)
/* Read commands */
#define CMD_READ_ARRAY_SLOW 0x03
#define CMD_READ_ID 0x9f
/* Write commands */
#define CMD_PAGE_PROGRAM 0x02
#define CMD_WRITE_DISABLE 0x04
#define CMD_WRITE_ENABLE 0x06
/* Erase commands */
#define CMD_ERASE_4K 0x20
#define CMD_ERASE_32K 0x52
#define CMD_ERASE_64K 0xD8
#define CMD_ERASE_CHIP 0x60
/* Rounding */
#define IS_ROUND(x, k) (!((x) & ((k) - 1)))
#define ROUND_DOWN(x, k) ((x) & ~((k) - 1))
#define ROUND_UP(x, k) (((x) + (k) - 1) & ~((k) - 1))
void init_spi(void);
void spi_send_cmd(uint32_t dev, const char *cmd, size_t cmd_len,
char *data, size_t data_len);
void spi_flash_read(uint32_t dev, uint32_t addr, char *data, size_t len);
void spi_flash_write(uint32_t dev, uint32_t addr, char *data, size_t len);
void spi_flash_erase(FILE *fp, uint32_t dev, uint32_t addr, size_t len);