From c81560826e92e3794458207c397980d1dcd4794d Mon Sep 17 00:00:00 2001 From: moonglow Date: Fri, 11 Jun 2021 13:12:13 +0300 Subject: [PATCH 1/3] *increase TXFIFO to 256 slots *abort all pending mailboxes for start/stop events --- Src/pcanpro_can.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Src/pcanpro_can.c b/Src/pcanpro_can.c index ee59195..2681eb4 100644 --- a/Src/pcanpro_can.c +++ b/Src/pcanpro_can.c @@ -15,7 +15,7 @@ static CAN_HandleTypeDef hcan[CAN_BUS_TOTAL] = [CAN_BUS_2].Instance = CAN2 }; -#define CAN_TX_FIFO_SIZE (64) +#define CAN_TX_FIFO_SIZE (256) static struct t_can_dev { void *dev; @@ -316,10 +316,10 @@ int pcan_can_init_ex( int bus, uint32_t bitrate ) p_can->Init.TimeTriggeredMode = DISABLE; p_can->Init.AutoBusOff = ENABLE; p_can->Init.AutoWakeUp = ENABLE; - /* do resend packets ! */ + p_can->Init.AutoRetransmission = DISABLE; p_can->Init.ReceiveFifoLocked = DISABLE; - p_can->Init.TransmitFifoPriority = DISABLE; + p_can->Init.TransmitFifoPriority = ENABLE; /* APB1 bus ref clock = 24MHz, best sp is 87.5% */ _get_precalculated_bitrate( bitrate, &brp, &tseg1, &tseg2, &sjw ); @@ -381,9 +381,11 @@ void pcan_can_set_bus_active( int bus, uint16_t mode ) if( mode ) { HAL_CAN_Start( p_can ); + HAL_CAN_AbortTxRequest( p_can, CAN_TX_MAILBOX0 | CAN_TX_MAILBOX1 | CAN_TX_MAILBOX2 ); } else { + HAL_CAN_AbortTxRequest( p_can, CAN_TX_MAILBOX0 | CAN_TX_MAILBOX1 | CAN_TX_MAILBOX2 ); HAL_CAN_Stop( p_can ); } } From d8aeedceb51f31b0823ff90b1c089794051d3602 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Wed, 30 Jun 2021 16:13:59 +0200 Subject: [PATCH 2/3] Make status led blink when device is alive. When it crashes the LED freezes. --- Src/main.c | 1 + Src/pcanpro_fd_protocol.c | 2 +- Src/pcanpro_protocol.c | 1 + Src/pcanpro_timestamp.c | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Src/main.c b/Src/main.c index 1537bcb..cf62e6d 100644 --- a/Src/main.c +++ b/Src/main.c @@ -76,6 +76,7 @@ int main(void) pcan_timestamp_init(); pcan_led_init(); + pcan_led_set_mode( LED_STAT, LED_MODE_BLINK_FAST, 0xFFFFFFFF ); pcan_protocol_init(); pcan_usb_device_init(); diff --git a/Src/pcanpro_fd_protocol.c b/Src/pcanpro_fd_protocol.c index a4c911b..fbf8d72 100644 --- a/Src/pcanpro_fd_protocol.c +++ b/Src/pcanpro_fd_protocol.c @@ -203,7 +203,7 @@ void pcan_ep0_receive( void ) pcan_flush_ep( PCAN_USB_EP_MSGIN_CH1 ); pcan_flush_ep( PCAN_USB_EP_CMDIN ); pcan_device.can_drv_loaded = drv_load_packet[1]; - pcan_led_set_mode( LED_STAT, LED_MODE_ON, 0 ); + pcan_led_set_mode( LED_STAT, LED_MODE_BLINK_SLOW, 0xFFFFFFFF ); } else pcan_device.lin_drv_loaded = drv_load_packet[1]; diff --git a/Src/pcanpro_protocol.c b/Src/pcanpro_protocol.c index ef83566..3c2cf78 100644 --- a/Src/pcanpro_protocol.c +++ b/Src/pcanpro_protocol.c @@ -243,6 +243,7 @@ void pcan_ep0_receive( void ) { pcan_flush_ep( PCAN_USB_EP_MSGIN_CH1 ); pcan_flush_ep( PCAN_USB_EP_CMDIN ); + pcan_led_set_mode( LED_STAT, LED_MODE_BLINK_SLOW, 0xFFFFFFFF ); } else { diff --git a/Src/pcanpro_timestamp.c b/Src/pcanpro_timestamp.c index 0a5baa7..9f09212 100644 --- a/Src/pcanpro_timestamp.c +++ b/Src/pcanpro_timestamp.c @@ -33,6 +33,10 @@ void pcan_timestamp_init( void ) assert( 0 ); break; } + + //HAL_GetTick must not return 0 to use LED events in early stage. + //Let's increment the value here by one. + HAL_IncTick(); } uint32_t pcan_timestamp_millis( void ) From ddae76df328bcc315a4a3f9e34f1e7b159e23738 Mon Sep 17 00:00:00 2001 From: Roman Ilichev Date: Mon, 25 Oct 2021 18:32:58 +0300 Subject: [PATCH 3/3] *use hardware only TX/RX loop flag ( fix unneeded TX echo ) --- Src/pcanpro_fd_protocol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/pcanpro_fd_protocol.c b/Src/pcanpro_fd_protocol.c index fbf8d72..db333a5 100644 --- a/Src/pcanpro_fd_protocol.c +++ b/Src/pcanpro_fd_protocol.c @@ -335,7 +335,7 @@ int pcan_protocol_tx_frame( struct ucan_tx_msg *pmsg ) msg.flags |= MSG_FLAG_RTR; if( pmsg->flags & UCAN_MSG_EXT_ID ) msg.flags |= MSG_FLAG_EXT; - if( pmsg->flags & (UCAN_MSG_API_SRR|UCAN_MSG_HW_SRR) ) + if( pmsg->flags & (/*UCAN_MSG_API_SRR|*/UCAN_MSG_HW_SRR) ) { msg.flags |= MSG_FLAG_ECHO; msg.dummy = pmsg->client;