From a15f34e0350654142953cf8a51221aa255dfe7ca Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 16 Jul 2024 07:44:14 -0700 Subject: [PATCH] Fix for Renesas RX SPI driver. All tests passing now. Added test for SPI_FLASH=1 enabled with `TEST_EXT_FLASH`. Reverted probe fix. --- hal/spi/spi_drv_renesas_rx.c | 2 +- src/spi_flash.c | 63 ++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/hal/spi/spi_drv_renesas_rx.c b/hal/spi/spi_drv_renesas_rx.c index 113ce1106..c7fbdb1a6 100644 --- a/hal/spi/spi_drv_renesas_rx.c +++ b/hal/spi/spi_drv_renesas_rx.c @@ -219,7 +219,7 @@ void spi_write(const char byte) } uint8_t spi_read(void) { - while ((RSPI_SPSR(FLASH_RSPI_PORT) & RSPI_SPSR_SPTEF) == 0); + while ((RSPI_SPSR(FLASH_RSPI_PORT) & RSPI_SPSR_SPRF) == 0); return RSPI_SPSR8(FLASH_RSPI_PORT); } diff --git a/src/spi_flash.c b/src/spi_flash.c index 810154c07..fc9adaa08 100644 --- a/src/spi_flash.c +++ b/src/spi_flash.c @@ -26,6 +26,7 @@ #include "spi_drv.h" #include "spi_flash.h" #include "printf.h" +#include "string.h" #ifdef SPI_FLASH @@ -50,6 +51,9 @@ #define EBSY 0x70 #define DBSY 0x80 +#ifdef TEST_EXT_FLASH +static int test_ext_flash(void); +#endif static enum write_mode { WB_WRITEPAGE = 0x00, @@ -172,14 +176,13 @@ static int RAMFUNCTION spi_flash_write_sb(uint32_t address, const void *data, in uint16_t spi_flash_probe(void) { uint8_t manuf, product, notused; + uint16_t manuf_prod; int i; spi_init(0,0); wait_busy(); spi_cs_on(SPI_CS_PIO_BASE, SPI_CS_FLASH); spi_write(MDID); notused = spi_read(); - spi_write(0); /* ADDR=0 */ - notused = spi_read(); spi_write(0xFF); manuf = spi_read(); spi_write(0xFF); @@ -200,8 +203,13 @@ uint16_t spi_flash_probe(void) #endif wolfBoot_printf("SPI Probe: Manuf 0x%x, Product 0x%x\n", manuf, product); + manuf_prod = (uint16_t)(manuf << 8) | (uint16_t)product; - return (uint16_t)(manuf << 8) | (uint16_t)product; +#ifdef TEST_EXT_FLASH + test_ext_flash(); +#endif + + return manuf_prod; } @@ -252,4 +260,53 @@ void spi_flash_release(void) spi_release(); } +#ifdef TEST_EXT_FLASH + +#ifndef TEST_EXT_ADDRESS + /* Start Address for test - 2MB */ + #define TEST_EXT_ADDRESS (2 * 1024 * 1024) +#endif + +static int test_ext_flash(void) +{ + int ret; + uint32_t i; + uint8_t pageData[SPI_FLASH_SECTOR_SIZE]; + uint32_t wait = 0; + +#ifndef READONLY + /* Erase sector */ + ret = ext_flash_erase(TEST_EXT_ADDRESS, SPI_FLASH_SECTOR_SIZE); + wolfBoot_printf("Sector Erase: Ret %d\n", ret); + + /* Write Page */ + for (i=0; i 1 + wolfBoot_printf("check[%3d] %02x\n", i, pageData[i]); + #endif + if (pageData[i] != (i & 0xff)) { + wolfBoot_printf("Check Data @ %d failed\n", i); + return -1; + } + } + + wolfBoot_printf("Flash Test Passed\n"); + return ret; +} +#endif /* TEST_EXT_FLASH */ + #endif /* SPI_FLASH */