|
@@ -42,7 +42,7 @@ enum
|
|
|
|
|
|
/* Private functions ------------------------------------------------------------*/
|
|
|
static rt_err_t nu_qspi_bus_configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration);
|
|
|
-static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_message *message);
|
|
|
+static rt_ssize_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_message *message);
|
|
|
static int nu_qspi_register_bus(struct nu_spi *qspi_bus, const char *name);
|
|
|
|
|
|
/* Public functions -------------------------------------------------------------*/
|
|
@@ -60,7 +60,7 @@ static struct nu_spi nu_qspi_arr [] =
|
|
|
{
|
|
|
.name = "qspi0",
|
|
|
.spi_base = (SPI_T *)QSPI0,
|
|
|
-
|
|
|
+ .rstidx = QSPI0_RST,
|
|
|
#if defined(BSP_USING_SPI_PDMA)
|
|
|
#if defined(BSP_USING_QSPI0_PDMA)
|
|
|
.pdma_perp_tx = PDMA_QSPI0_TX,
|
|
@@ -76,7 +76,7 @@ static struct nu_spi nu_qspi_arr [] =
|
|
|
{
|
|
|
.name = "qspi1",
|
|
|
.spi_base = (SPI_T *)QSPI1,
|
|
|
-
|
|
|
+ .rstidx = QSPI1_RST,
|
|
|
#if defined(BSP_USING_SPI_PDMA)
|
|
|
#if defined(BSP_USING_QSPI1_PDMA)
|
|
|
.pdma_perp_tx = PDMA_QSPI1_TX,
|
|
@@ -88,7 +88,6 @@ static struct nu_spi nu_qspi_arr [] =
|
|
|
#endif
|
|
|
},
|
|
|
#endif
|
|
|
- {0}
|
|
|
}; /* qspi nu_qspi */
|
|
|
|
|
|
static rt_err_t nu_qspi_bus_configure(struct rt_spi_device *device,
|
|
@@ -226,17 +225,15 @@ static int nu_qspi_mode_config(struct nu_spi *qspi_bus, rt_uint8_t *tx, rt_uint8
|
|
|
return qspi_lines;
|
|
|
}
|
|
|
|
|
|
-static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
|
|
|
+static rt_ssize_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
|
|
|
{
|
|
|
struct nu_spi *qspi_bus;
|
|
|
struct rt_qspi_configuration *qspi_configuration;
|
|
|
-#if defined(RT_SFUD_USING_QSPI)
|
|
|
struct rt_qspi_message *qspi_message;
|
|
|
rt_uint8_t u8last = 1;
|
|
|
-#endif
|
|
|
rt_uint8_t bytes_per_word;
|
|
|
QSPI_T *qspi_base;
|
|
|
- rt_uint32_t u32len = 0;
|
|
|
+ rt_ssize_t u32len = 0;
|
|
|
|
|
|
RT_ASSERT(device != RT_NULL);
|
|
|
RT_ASSERT(message != RT_NULL);
|
|
@@ -259,7 +256,6 @@ static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#if defined(RT_SFUD_USING_QSPI)
|
|
|
qspi_message = (struct rt_qspi_message *)message;
|
|
|
|
|
|
/* Command + Address + Dummy + Data */
|
|
@@ -275,7 +271,7 @@ static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_
|
|
|
}
|
|
|
|
|
|
/* Address stage */
|
|
|
- if (qspi_message->address.size != 0)
|
|
|
+ if (qspi_message->address.size > 0)
|
|
|
{
|
|
|
rt_uint32_t u32ReversedAddr = 0;
|
|
|
rt_uint32_t u32AddrNumOfByte = qspi_message->address.size / 8;
|
|
@@ -305,8 +301,39 @@ static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_
|
|
|
1);
|
|
|
}
|
|
|
|
|
|
+ /* alternate_bytes stage */
|
|
|
+ if ((qspi_message->alternate_bytes.size > 0) && (qspi_message->alternate_bytes.size <= 4))
|
|
|
+ {
|
|
|
+ rt_uint32_t u32AlternateByte = 0;
|
|
|
+ rt_uint32_t u32NumOfByte = qspi_message->alternate_bytes.size / 8;
|
|
|
+ switch (u32NumOfByte)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ u32AlternateByte = (qspi_message->alternate_bytes.content & 0xff);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ nu_set16_be((rt_uint8_t *)&u32AlternateByte, qspi_message->alternate_bytes.content);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ nu_set24_be((rt_uint8_t *)&u32AlternateByte, qspi_message->alternate_bytes.content);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ nu_set32_be((rt_uint8_t *)&u32AlternateByte, qspi_message->alternate_bytes.content);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ RT_ASSERT(0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ u8last = nu_qspi_mode_config(qspi_bus, (rt_uint8_t *)&u32AlternateByte, RT_NULL, qspi_message->alternate_bytes.qspi_lines);
|
|
|
+ nu_spi_transfer((struct nu_spi *)qspi_bus,
|
|
|
+ (rt_uint8_t *) &u32AlternateByte,
|
|
|
+ RT_NULL,
|
|
|
+ u32NumOfByte,
|
|
|
+ 1);
|
|
|
+ }
|
|
|
+
|
|
|
/* Dummy_cycles stage */
|
|
|
- if (qspi_message->dummy_cycles != 0)
|
|
|
+ if (qspi_message->dummy_cycles > 0)
|
|
|
{
|
|
|
qspi_bus->dummy = 0x00;
|
|
|
|
|
@@ -317,15 +344,11 @@ static rt_uint32_t nu_qspi_bus_xfer(struct rt_spi_device *device, struct rt_spi_
|
|
|
qspi_message->dummy_cycles / (8 / u8last),
|
|
|
1);
|
|
|
}
|
|
|
- /* Data stage */
|
|
|
- nu_qspi_mode_config(qspi_bus, (rt_uint8_t *) message->send_buf, (rt_uint8_t *) message->recv_buf, qspi_message->qspi_data_lines);
|
|
|
-#else
|
|
|
- /* Data stage */
|
|
|
- nu_qspi_mode_config(qspi_bus, RT_NULL, RT_NULL, 1);
|
|
|
-#endif //#if defined(RT_SFUD_USING_QSPI)
|
|
|
|
|
|
- if (message->length != 0)
|
|
|
+ if (message->length > 0)
|
|
|
{
|
|
|
+ /* Data stage */
|
|
|
+ nu_qspi_mode_config(qspi_bus, (rt_uint8_t *) message->send_buf, (rt_uint8_t *) message->recv_buf, qspi_message->qspi_data_lines);
|
|
|
nu_spi_transfer((struct nu_spi *)qspi_bus,
|
|
|
(rt_uint8_t *) message->send_buf,
|
|
|
(rt_uint8_t *) message->recv_buf,
|
|
@@ -367,11 +390,14 @@ static int rt_hw_qspi_init(void)
|
|
|
|
|
|
for (i = (QSPI_START + 1); i < QSPI_CNT; i++)
|
|
|
{
|
|
|
+ SYS_ResetModule(nu_qspi_arr[i].rstidx);
|
|
|
+
|
|
|
nu_qspi_register_bus(&nu_qspi_arr[i], nu_qspi_arr[i].name);
|
|
|
#if defined(BSP_USING_SPI_PDMA)
|
|
|
nu_qspi_arr[i].pdma_chanid_tx = -1;
|
|
|
nu_qspi_arr[i].pdma_chanid_rx = -1;
|
|
|
-
|
|
|
+#endif
|
|
|
+#if defined(BSP_USING_QSPI_PDMA)
|
|
|
if ((nu_qspi_arr[i].pdma_perp_tx != NU_PDMA_UNUSED) && (nu_qspi_arr[i].pdma_perp_rx != NU_PDMA_UNUSED))
|
|
|
{
|
|
|
if (nu_hw_spi_pdma_allocate(&nu_qspi_arr[i]) != RT_EOK)
|