mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
SPI flash support, with xiao nrf52 and portenta-h7
This commit is contained in:
1 parent
57e30ab2e9
commit
f02ea9859e
17 files changed
+442
-17
No files matched your search
+28
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "arch.h"
|
||||
#include "periph.h"
|
||||
|
||||
struct mg_flash {
|
||||
void *start; // Address at which flash starts
|
||||
@@ -17,3 +18,30 @@ extern struct mg_flash *mg_flash;
|
||||
|
||||
// Reads memory-mapped (XIP) flash. Use as read_fn for such flash
|
||||
bool mg_flash_read_xip(void *addr, void *buf, size_t len);
|
||||
|
||||
// JEDEC SPI NOR flash: W25Q, P25Q, MX25 and similar, up to 16 MB, 3-byte
|
||||
// addresses, single-line SPI. MG_SPI_FLASH() wraps these into a struct mg_flash
|
||||
bool mg_spi_flash_init(struct mg_spi *spi, size_t *size);
|
||||
bool mg_spi_flash_read(struct mg_spi *spi, size_t ofs, void *buf, size_t len);
|
||||
bool mg_spi_flash_write(struct mg_spi *spi, size_t ofs, const void *buf,
|
||||
size_t len);
|
||||
|
||||
// Defines struct mg_flash name for a JEDEC SPI NOR chip on the struct mg_spi
|
||||
// pointer spi. Start is 0, so addresses are flash offsets. The size comes
|
||||
// from the chip on first use, and stays 0 if there is no chip. For example:
|
||||
// static struct mg_spi s_spi = {NULL, my_begin, my_end, my_txn};
|
||||
// MG_SPI_FLASH(my_flash, &s_spi);
|
||||
// #define MG_LFS_FLASH (&my_flash) // In mongoose_config.h
|
||||
#define MG_SPI_FLASH(name, spi) \
|
||||
static bool name##_init(struct mg_flash *f) { \
|
||||
if (f->size == 0) mg_spi_flash_init(spi, &f->size); \
|
||||
return f->size > 0; \
|
||||
} \
|
||||
static bool name##_read(void *a, void *b, size_t n) { \
|
||||
return mg_spi_flash_read(spi, (size_t) a, b, n); \
|
||||
} \
|
||||
static bool name##_write(void *a, const void *b, size_t n) { \
|
||||
return mg_spi_flash_write(spi, (size_t) a, b, n); \
|
||||
} \
|
||||
struct mg_flash name = {NULL, 0, 4096, 1, name##_read, \
|
||||
name##_write, NULL, name##_init}
|
||||
Reference in new issue
Block a user