From fca9804672f9e15d04c66c522604b4575fef4628 Mon Sep 17 00:00:00 2001 From: JOONH0o <105910755+JOONH0o@users.noreply.github.com> Date: Tue, 18 Feb 2025 22:55:44 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix=20-=201=20=E4=BC=98=E5=8C=96=E4=B8=AD?= =?UTF-8?q?=E6=96=AD=E4=B8=AD=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B2=20=E4=BC=98=E5=8C=96SPI=E5=86=99=E5=A4=96?= =?UTF-8?q?=E9=83=A8FLASH=E6=85=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.在spi驱动中有在中断中打印调试信息的问题,增加ISR log判断进行 2.spi+DMA 写外部flash,由于spi速度很快,不进行delay就可以;同时,仿照Linux的驱动框架进行优化,数据小不使用DMA --- bsp/hc32/libraries/hc32_drivers/drv_eth.c | 4 ++++ bsp/hc32/libraries/hc32_drivers/drv_spi.c | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_eth.c b/bsp/hc32/libraries/hc32_drivers/drv_eth.c index 573b70502a9..d5ba5a39792 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_eth.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_eth.c @@ -358,7 +358,9 @@ static void hc32_eth_irq_handle(stc_eth_handle_t *eth_handle) result = eth_device_ready(&(hc32_eth_device.parent)); if (result != RT_EOK) { +#ifdef ULOG_USING_ISR_LOG LOG_I("eth rx complete callback err = %d", result); +#endif } /* Clear the Eth DMA Rx IT pending bits */ ETH_DMA_ClearStatus(ETH_DMA_FLAG_RIS | ETH_DMA_FLAG_NIS); @@ -465,7 +467,9 @@ static void eth_phy_irq_handler(void *args) rt_uint16_t status = 0; ETH_PHY_ReadReg(&EthHandle, PHY_IISDR, &status); +#ifdef ULOG_USING_ISR_LOG LOG_D("phy interrupt status reg is 0x%X", status); +#endif #endif hc32_phy_link_change(); } diff --git a/bsp/hc32/libraries/hc32_drivers/drv_spi.c b/bsp/hc32/libraries/hc32_drivers/drv_spi.c index eccc05e544f..0265d069bed 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_spi.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_spi.c @@ -473,8 +473,8 @@ static int32_t hc32_spi_dma_trans(struct hc32_spi_config *spi_config, const uint while ((RESET == DMA_GetTransCompleteStatus(DmaInstance, DmaFlag)) && (u32TimeoutCnt < spi_config->timeout)) { - rt_thread_mdelay(1); - u32TimeoutCnt++; +// rt_thread_mdelay(1); +// u32TimeoutCnt++; } if (u32TimeoutCnt >= spi_config->timeout) { @@ -544,7 +544,7 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess if (message->send_buf && message->recv_buf) { hc32_spi_set_trans_mode(spi_instance, SPI_FULL_DUPLEX); - if ((spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_TX) && (spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_RX)) + if ((spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_TX) && (spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_RX) && (send_length > 32)) { state = hc32_spi_dma_trans(spi_drv->config, send_buf, recv_buf, send_length); } @@ -557,7 +557,7 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess else if (message->send_buf) { hc32_spi_set_trans_mode(spi_instance, SPI_SEND_ONLY); - if (spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_TX) + if ((spi_drv->spi_dma_flag & RT_DEVICE_FLAG_DMA_TX) && (send_length > 32)) { state = hc32_spi_dma_trans(spi_drv->config, send_buf, RT_NULL, send_length); } @@ -601,8 +601,8 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess while ((RESET == SPI_GetStatus(spi_instance, SPI_FLAG_IDLE)) && (u32TimeoutCnt < spi_drv->config->timeout)) { - rt_thread_mdelay(1); - u32TimeoutCnt++; +// rt_thread_mdelay(1); +// u32TimeoutCnt++; } if (u32TimeoutCnt >= spi_drv->config->timeout) { From 496a232a95ad00f3ca5f25d4e7e38518f0dc83ac Mon Sep 17 00:00:00 2001 From: JOONH0o <105910755+JOONH0o@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:57:31 +0800 Subject: [PATCH 2/5] Update drv_spi.c --- bsp/hc32/libraries/hc32_drivers/drv_spi.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_spi.c b/bsp/hc32/libraries/hc32_drivers/drv_spi.c index 0265d069bed..b67490f625b 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_spi.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_spi.c @@ -473,8 +473,6 @@ static int32_t hc32_spi_dma_trans(struct hc32_spi_config *spi_config, const uint while ((RESET == DMA_GetTransCompleteStatus(DmaInstance, DmaFlag)) && (u32TimeoutCnt < spi_config->timeout)) { -// rt_thread_mdelay(1); -// u32TimeoutCnt++; } if (u32TimeoutCnt >= spi_config->timeout) { @@ -601,8 +599,6 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess while ((RESET == SPI_GetStatus(spi_instance, SPI_FLAG_IDLE)) && (u32TimeoutCnt < spi_drv->config->timeout)) { -// rt_thread_mdelay(1); -// u32TimeoutCnt++; } if (u32TimeoutCnt >= spi_drv->config->timeout) { From bcb4e23ab6d27bfb0d328d06d8a84990da2969f6 Mon Sep 17 00:00:00 2001 From: JOONH0o <105910755+JOONH0o@users.noreply.github.com> Date: Sun, 23 Feb 2025 22:49:33 +0800 Subject: [PATCH 3/5] Update drv_eth.c --- bsp/hc32/libraries/hc32_drivers/drv_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_eth.c b/bsp/hc32/libraries/hc32_drivers/drv_eth.c index d5ba5a39792..8c8e3e90b3b 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_eth.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_eth.c @@ -358,7 +358,7 @@ static void hc32_eth_irq_handle(stc_eth_handle_t *eth_handle) result = eth_device_ready(&(hc32_eth_device.parent)); if (result != RT_EOK) { -#ifdef ULOG_USING_ISR_LOG +#if !defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) LOG_I("eth rx complete callback err = %d", result); #endif } From 5bef2ee4a9fb731ec65687497472ebbbf08fb4c3 Mon Sep 17 00:00:00 2001 From: JOONH0o <105910755+JOONH0o@users.noreply.github.com> Date: Sun, 23 Feb 2025 22:50:46 +0800 Subject: [PATCH 4/5] Update drv_eth.c --- bsp/hc32/libraries/hc32_drivers/drv_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_eth.c b/bsp/hc32/libraries/hc32_drivers/drv_eth.c index 8c8e3e90b3b..1096d954ce6 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_eth.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_eth.c @@ -467,7 +467,7 @@ static void eth_phy_irq_handler(void *args) rt_uint16_t status = 0; ETH_PHY_ReadReg(&EthHandle, PHY_IISDR, &status); -#ifdef ULOG_USING_ISR_LOG +#if !defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) LOG_D("phy interrupt status reg is 0x%X", status); #endif #endif From 287151d7fc4cf073e40761212454df1c557f14f5 Mon Sep 17 00:00:00 2001 From: JOONH0o <105910755+JOONH0o@users.noreply.github.com> Date: Sun, 23 Feb 2025 22:52:10 +0800 Subject: [PATCH 5/5] Update drv_eth.c --- bsp/hc32/libraries/hc32_drivers/drv_eth.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/hc32/libraries/hc32_drivers/drv_eth.c b/bsp/hc32/libraries/hc32_drivers/drv_eth.c index 1096d954ce6..043de32237c 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_eth.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_eth.c @@ -358,7 +358,7 @@ static void hc32_eth_irq_handle(stc_eth_handle_t *eth_handle) result = eth_device_ready(&(hc32_eth_device.parent)); if (result != RT_EOK) { -#if !defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) +#if defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) LOG_I("eth rx complete callback err = %d", result); #endif } @@ -467,7 +467,7 @@ static void eth_phy_irq_handler(void *args) rt_uint16_t status = 0; ETH_PHY_ReadReg(&EthHandle, PHY_IISDR, &status); -#if !defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) +#if defined (RT_USING_ULOG) || defined (ULOG_USING_ISR_LOG) LOG_D("phy interrupt status reg is 0x%X", status); #endif #endif