Skip to content

Commit

Permalink
QSPI fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarske committed May 24, 2024
1 parent 5962d55 commit 74036a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 9 additions & 0 deletions hal/rx65n.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
#define RSPI_SPDCR2_BYSW (1 << 0) /* Byte Swap: 0=Byte swapping of SPDR data disabled, 1=Byte swapping of SPDR data enabled */


#if defined(EXT_FLASH) && defined(TEST_FLASH)
static int test_flash(void);
#endif

static void hal_delay_us(uint32_t us)
{
uint32_t delay;
Expand Down Expand Up @@ -586,6 +590,11 @@ void hal_init(void)
#ifdef DEBUG_UART
uart_init();
uart_write("wolfBoot HAL Init\n", 18);
#endif
#if defined(EXT_FLASH) && defined(TEST_FLASH)
if (test_flash() != 0) {
wolfBoot_printf("Flash Test Failed!\n");
}
#endif
return;
}
Expand Down
29 changes: 20 additions & 9 deletions hal/rx72n.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*/

/* HAL for Renesas RX72N */
/* Default configuration:
/* Tested with:
* RX72N Envision Kit (HMI IoT)
* R5F572NNHDFB 144-pin LFQFP (PLQP0144KA-B)
* 4MB Flash, 1MB RAM, 32KB Data Flash, 240MHz, TSIP
* QSPI: Macronix MX25L3233FM2I-08G: 4MB QSPI Serial Flash
*/

#include <stdio.h>
Expand Down Expand Up @@ -302,6 +303,11 @@

#define QSPI_FIFO_SIZE 32 /* bytes */


#if defined(EXT_FLASH) && defined(TEST_FLASH)
static int test_flash(void);
#endif

static void hal_delay_us(uint32_t us)
{
uint32_t delay;
Expand All @@ -312,15 +318,11 @@ static void hal_delay_us(uint32_t us)

#if defined(SPI_FLASH) || defined(QSPI_FLASH)

/* Macronix MX25L3233FM2I-08G: 4MB QSPI Serial Flash */
/* RSPI1: P27/RSPCKB-A, P26/MOSIB-A, P30/MISOB-A, P31/SSLB0-A */
/* QSPI: PD2/QIO2-B, PD3/QIO3-B, PD4/QSSL-B, PD5/QSPCLK-B, PD6/QIO0-B, PD7/QIO1-B */
#ifndef FLASH_RSPI_PORT
#define FLASH_RSPI_PORT 1 /* RSPI1 */
#endif
#ifndef FLASH_CLK_HZ
#define FLASH_CLK_HZ 15000000
#endif
#define FLASH_SPI_USE_HW_CS
void spi_init(int polarity, int phase)
{
Expand Down Expand Up @@ -577,9 +579,6 @@ static int qspi_data(const uint32_t* txData, uint32_t* rxData, uint32_t dataSz)
tmp = QSPI_SPDR8;
}

/* Clear flags */
QSPI_SPSR |= (QSPI_SPSR_SPTEF | QSPI_SPSR_SPRFF | QSPI_SPSR_SPSSLF);

return 0;
}

Expand Down Expand Up @@ -653,11 +652,17 @@ int qspi_transfer(uint8_t fmode, const uint8_t cmd,
if (dummySz > 0) {
qspi_data(NULL, NULL, dummySz);
}
qspi_data(&alt, NULL, altSz);
if (fmode == QSPI_MODE_READ)
qspi_data(NULL, (uint32_t*)data, dataSz);
else
qspi_data((const uint32_t*)data, NULL, dataSz);

/* Wait for QSSL negation */
while ((QSPI_SPSR & QSPI_SPSR_SPSSLF) == 0);

/* Clear flags */
QSPI_SPSR |= (QSPI_SPSR_SPTEF | QSPI_SPSR_SPRFF | QSPI_SPSR_SPSSLF);

/* Disable QSPI */
QSPI_SPCR &= ~QSPI_SPCR_SPE;

Expand Down Expand Up @@ -892,6 +897,12 @@ void hal_init(void)
uart_init();
uart_write("wolfBoot HAL Init\n", 18);
#endif
#if defined(EXT_FLASH) && defined(TEST_FLASH)
if (test_flash() != 0) {
wolfBoot_printf("Flash Test Failed!\n");
}
#endif

return;
}
int hal_flash_write(uint32_t address, const uint8_t *data, int len)
Expand Down

0 comments on commit 74036a3

Please sign in to comment.