88 * Change Logs:
99 * Date Author Notes
1010 * 2025-18-03 Dmitriy Chernov first implementation for GD32F4xx
11+ * 2025-09-24 CYFS add support for GD32F5xx
1112 */
1213
1314#include "drv_can.h"
@@ -31,7 +32,7 @@ static const struct gd32_baudrate_tbl can_baudrate_tbl[] =
3132 {CAN20kBaud , CAN_BT_SJW_1TQ , CAN_BT_BS1_11TQ , CAN_BT_BS2_2TQ , 150 },
3233 {CAN10kBaud , CAN_BT_SJW_1TQ , CAN_BT_BS1_11TQ , CAN_BT_BS2_2TQ , 300 },
3334};
34- #elif defined(GD32F425 ) || defined(GD32F427 ) || defined(GD32F450 ) /* 50MHz(max) */
35+ #elif defined(GD32F425 ) || defined(GD32F427 ) || defined(GD32F450 ) || defined( GD32F527 ) /* 50MHz(max) */
3536static const struct gd32_baudrate_tbl can_baudrate_tbl [] =
3637{
3738 {CAN1MBaud , CAN_BT_SJW_1TQ , CAN_BT_BS1_8TQ , CAN_BT_BS2_1TQ , 5 },
@@ -82,7 +83,9 @@ static const struct gd32_can gd32_can_gpio[] =
8283#ifdef BSP_USING_CAN0
8384 {
8485 .can_clk = RCU_CAN0 ,
86+ #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32F5xx
8587 .alt_func_num = GPIO_AF_9 ,
88+ #endif
8689#if defined BSP_CAN0_TX_PA12
8790 .tx_clk = RCU_GPIOA ,
8891 .tx_pin = GET_PIN (A , 12 ),
@@ -119,7 +122,10 @@ static const struct gd32_can gd32_can_gpio[] =
119122#ifdef BSP_USING_CAN1
120123 {
121124 .can_clk = RCU_CAN1 ,
125+ #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32F5xx
122126 .alt_func_num = GPIO_AF_9 ,
127+ #endif
128+
123129#if defined BSP_CAN1_TX_PB6
124130 .tx_clk = RCU_GPIOB ,
125131 .tx_pin = GET_PIN (B , 6 ),
@@ -150,7 +156,7 @@ static void gd32_can_gpio_init(void)
150156 rcu_periph_clock_enable (gd32_can_gpio [i ].tx_clk );
151157 rcu_periph_clock_enable (gd32_can_gpio [i ].rx_clk );
152158
153- #if defined SOC_SERIES_GD32F4xx
159+ #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32F5xx
154160 gpio_af_set (PIN_GDPORT (gd32_can_gpio [i ].tx_pin ), gd32_can_gpio [i ].alt_func_num , PIN_GDPIN (gd32_can_gpio [i ].tx_pin ));
155161 gpio_af_set (PIN_GDPORT (gd32_can_gpio [i ].rx_pin ), gd32_can_gpio [i ].alt_func_num , PIN_GDPIN (gd32_can_gpio [i ].rx_pin ));
156162
@@ -515,7 +521,8 @@ static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
515521 return RT_EOK ;
516522}
517523
518- static int _can_sendmsg (struct rt_can_device * can , const void * buf , rt_uint32_t box_num )
524+
525+ static rt_ssize_t _can_sendmsg (struct rt_can_device * can , const void * buf , rt_uint32_t box_num )
519526{
520527 RT_ASSERT (can );
521528
@@ -605,7 +612,7 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
605612 return RT_EOK ;
606613}
607614
608- static int _can_recvmsg (struct rt_can_device * can , void * buf , rt_uint32_t fifo )
615+ static rt_ssize_t _can_recvmsg (struct rt_can_device * can , void * buf , rt_uint32_t fifo )
609616{
610617 RT_ASSERT (can );
611618
@@ -735,23 +742,23 @@ static void _can_ewmc_isr(struct rt_can_device *can)
735742 can -> status .ackerrcnt ++ ;
736743 if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF0 ))
737744 {
738- if (!can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR0 ))
745+ if (!can_flag_get (can_x , CAN_FLAG_MTFNERR0 ))
739746 {
740747 rt_hw_can_isr (can , RT_CAN_EVENT_TX_FAIL | 0 << 8 );
741748 }
742749 can_interrupt_flag_clear (can_x , CAN_INT_FLAG_MTF0 );
743750 }
744751 else if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF1 ))
745752 {
746- if (!can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR1 ))
753+ if (!can_flag_get (can_x , CAN_FLAG_MTFNERR1 ))
747754 {
748755 rt_hw_can_isr (can , RT_CAN_EVENT_TX_FAIL | 1 << 8 );
749756 }
750757 can_interrupt_flag_clear (can_x , CAN_INT_FLAG_MTF1 );
751758 }
752759 else if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF2 ))
753760 {
754- if (!can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR2 ))
761+ if (!can_flag_get (can_x , CAN_FLAG_MTFNERR2 ))
755762 {
756763 rt_hw_can_isr (can , RT_CAN_EVENT_TX_FAIL | 2 << 8 );
757764 }
@@ -796,7 +803,7 @@ static void _can_tx_isr(struct rt_can_device *can)
796803
797804 if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF0 ))
798805 {
799- if (can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR0 ))
806+ if (can_flag_get (can_x , CAN_FLAG_MTFNERR0 ))
800807 {
801808 rt_hw_can_isr (can , RT_CAN_EVENT_TX_DONE | 0 << 8 );
802809 }
@@ -809,7 +816,7 @@ static void _can_tx_isr(struct rt_can_device *can)
809816 }
810817 else if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF1 ))
811818 {
812- if (can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR1 ))
819+ if (can_flag_get (can_x , CAN_FLAG_MTFNERR1 ))
813820 {
814821 rt_hw_can_isr (can , RT_CAN_EVENT_TX_DONE | 1 << 8 );
815822 }
@@ -822,7 +829,7 @@ static void _can_tx_isr(struct rt_can_device *can)
822829 }
823830 else if (can_interrupt_flag_get (can_x , CAN_INT_FLAG_MTF2 ))
824831 {
825- if (can_interrupt_flag_get (can_x , CAN_FLAG_MTFNERR2 ))
832+ if (can_flag_get (can_x , CAN_FLAG_MTFNERR2 ))
826833 {
827834 rt_hw_can_isr (can , RT_CAN_EVENT_TX_DONE | 2 << 8 );
828835 }
0 commit comments