#include "string.h" #include "norflash.h" extern "C" { extern void delay_init (); extern void Delay_Ms (const unsigned dly); }; union FlashCommandHeader { struct { FLASH_COMMANDS cmd : 8; uint32_t adr : 24; // adresa je BIG ENDIEN - vyšší byte vystupuje po SPI dříve (MSB FIRST). }__attribute__((packed)); uint8_t bytes [4]; }__attribute__((packed)); static inline uint32_t be_set_24 (const uint32_t p) { return ((p & 0x000000ff) << 16) | ((p & 0x0000ff00) << 0) | ((p & 0x00ff0000) >> 16); } static constexpr unsigned FlashBlockLen = 0x1000u; // 4KiB = 4096 B NorFlash::NorFlash() noexcept : spi() { delay_init(); } unsigned int NorFlash::ReadBlock(const unsigned int addr, uint8_t * data, const unsigned int len) { FlashCommandHeader header; header.cmd = FLASH_4READ; header.adr = be_set_24(addr); spi.ChipSelect(true); for (unsigned n=0u; n