kaluma-project / kaluma

A tiny JavaScript runtime for RP2040 (Raspberry Pi Pico)
https://kalumajs.org
Apache License 2.0
648 stars 37 forks source link

Refactor user program flash #449

Closed niklauslee closed 2 years ago

niklauslee commented 3 years ago

board.h

// binary
#define KALUMA_BINARY_MAX 0x100000 // 1MB

// flash
#define KALUMA_FLASH_OFFSET KALUMA_BINARY_MAX
#define KALUMA_FLASH_SECTOR_SIZE 4096
#define KALUMA_FLASH_SECTOR_COUNT 256
#define KALUMA_FLASH_PAGE_SIZE 256
// flash sector examples:
// - sector 0~15 : storage area
// - sector 16~127 : code area
// - sector 128~255 : file system (lfs)

// user program on flash
#define KALUMA_PROG_SECTOR_BASE 0
#define KALUMA_PROG_SECTOR_COUNT 128

prog.h/c

Storing and accessing user's program.

#include "flash.h"

extern uint8_t *km_program_base = (uint8_t *)KALUMA_PROG_BASE;

int km_prog_clear();
int km_prog_begin();
int km_prog_write(int8_t *buffer, int size);
int km_prog_end();
int km_prog_get_size();
int km_prog_max_size();