diff --git a/sw/include/spi.h b/sw/include/spi.h index 9862bc4..2bf0b1b 100644 --- a/sw/include/spi.h +++ b/sw/include/spi.h @@ -70,7 +70,8 @@ void spiWriteSecurity(struct ff_spi *spi, uint8_t sr, uint8_t security[256]); int spiSetType(struct ff_spi *spi, enum spi_type type); int spiRead(struct ff_spi *spi, uint32_t addr, uint8_t *data, unsigned int count); int spiIsBusy(struct ff_spi *spi); -int spiBeginErase(struct ff_spi *spi, uint32_t erase_addr); +int spiBeginErase32(struct ff_spi *spi, uint32_t erase_addr); +int spiBeginErase64(struct ff_spi *spi, uint32_t erase_addr); int spiBeginWrite(struct ff_spi *spi, uint32_t addr, const void *data, unsigned int count); struct spi_id spiId(struct ff_spi *spi); diff --git a/sw/src/spi.c b/sw/src/spi.c index 4c63236..ebac6b3 100644 --- a/sw/src/spi.c +++ b/sw/src/spi.c @@ -32,7 +32,7 @@ static void gpioWrite(int pin, int val) { do_mirror |= 1 << pin; else do_mirror &= ~(1 << pin); - // bbspi_do_write(do_mirror); + bbspi_do_write(do_mirror); } static int gpioRead(int pin) { @@ -40,7 +40,7 @@ static int gpioRead(int pin) { } static void gpioSync(void) { - bbspi_do_write(do_mirror); + // bbspi_do_write(do_mirror); } #define SPI_ONLY_SINGLE @@ -703,10 +703,10 @@ static int spi_wait_for_not_busy(struct ff_spi *spi) { } int spiIsBusy(struct ff_spi *spi) { - return spiReadStatus(spi, 1) & (1 << 0); + return spiReadStatus(spi, 1) & (1 << 0); } -int spiBeginErase(struct ff_spi *spi, uint32_t erase_addr) { +int spiBeginErase32(struct ff_spi *spi, uint32_t erase_addr) { // Enable Write-Enable Latch (WEL) spiBegin(spi); spiCommand(spi, 0x06); @@ -721,6 +721,21 @@ int spiBeginErase(struct ff_spi *spi, uint32_t erase_addr) { return 0; } +int spiBeginErase64(struct ff_spi *spi, uint32_t erase_addr) { + // Enable Write-Enable Latch (WEL) + spiBegin(spi); + spiCommand(spi, 0x06); + spiEnd(spi); + + spiBegin(spi); + spiCommand(spi, 0xD8); + spiCommand(spi, erase_addr >> 16); + spiCommand(spi, erase_addr >> 8); + spiCommand(spi, erase_addr >> 0); + spiEnd(spi); + return 0; +} + int spiBeginWrite(struct ff_spi *spi, uint32_t addr, const void *v_data, unsigned int count) { uint8_t write_cmd = 0x02; const uint8_t *data = v_data;