From 69ed847740e3efb5c5ff6319629c93d236150959 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Fri, 23 Sep 2022 20:08:02 +0200 Subject: i2s driver fixed; added uart programming; --- fw/fe310/phone/flash.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 fw/fe310/phone/flash.c (limited to 'fw/fe310/phone/flash.c') diff --git a/fw/fe310/phone/flash.c b/fw/fe310/phone/flash.c new file mode 100644 index 0000000..e78576a --- /dev/null +++ b/fw/fe310/phone/flash.c @@ -0,0 +1,160 @@ +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "app/app.h" +#include "app/status.h" + +#include "flash.h" + +static const uint8_t magic[] = + {0x2D, 0xC0, 0x3B, 0x5F, 0xEA, 0xE3, 0x1A, 0x3A, 0x83, 0x11, 0x6A, 0x33, 0x98, 0x46, 0x1C, 0x47}; + +#define ACK 0x05 +#define NACK 0x0A +#define BLK_SIZE 256 + +__attribute__ ((section (".itim"))) +static uint32_t crc32x(unsigned char *buf, size_t len, uint32_t crc) { + int i; + + crc = ~crc; + while (len--) { + crc ^= *buf++; + for (i=0; i<8; i++) { + uint32_t t = ~((crc & 1) - 1); + crc = (crc >> 1) ^ (0xEDB88320 & t); + } + } + + return ~crc; +} + +__attribute__ ((section (".itim"))) +void flash_write(void) { + volatile uint32_t r; + uint32_t crc32, crc32_b; + uint32_t addr; + uint8_t buf[BLK_SIZE + 2 * sizeof(uint32_t)]; + int i; + + clear_csr(mstatus, MSTATUS_MIE); + SPI0_REG(SPI_REG_FCTRL) = 0; + SPI0_REG(SPI_REG_FMT) &= ~SPI_FMT_DIR(SPI_DIR_TX); + + do { + for (i=0; i