Skip to content

Commit

Permalink
Fix for Renesas RX SPI driver. All tests passing now. Added test for …
Browse files Browse the repository at this point in the history
…SPI_FLASH=1 enabled with `TEST_EXT_FLASH`. Reverted probe fix.
  • Loading branch information
dgarske committed Jul 16, 2024
1 parent 0e0b6cc commit a15f34e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hal/spi/spi_drv_renesas_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
63 changes: 60 additions & 3 deletions src/spi_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "spi_drv.h"
#include "spi_flash.h"
#include "printf.h"
#include "string.h"

#ifdef SPI_FLASH

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}


Expand Down Expand Up @@ -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<sizeof(pageData); i++) {
pageData[i] = (i & 0xff);
}
ret = ext_flash_write(TEST_EXT_ADDRESS, pageData, sizeof(pageData));
wolfBoot_printf("Page Write: Ret %d\n", ret);
#endif

/* Read page */
memset(pageData, 0, sizeof(pageData));
ret = ext_flash_read(TEST_EXT_ADDRESS, pageData, sizeof(pageData));
wolfBoot_printf("Page Read: Ret %d\n", ret);

wolfBoot_printf("Checking...\n");
/* Check data */
for (i=0; i<sizeof(pageData); i++) {
#if defined(DEBUG_QSPI) && DEBUG_QSPI > 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 */

0 comments on commit a15f34e

Please sign in to comment.