2014-07-09 04:53 AM
Hi,
Has anyone
run
a
CAN
application
that works
also
in
error
cases
?In my
application
the connection hangs
, for example,after
pulling the
CAN bus
pin plug
and re-
connect.One reason for this
is the
HAL_CAN_Transmit
()
function,
the
function
does not call
__
HAL_UNLOCK
(
HCAN)in the
event of a fault
(HAL_ERROR return).
It seems
that
the same problem
also exists in
HAL_CAN_Sleep
() and
HAL_CAN_WakeUp
().
Another problem
is that
the MSR
>
ERRI
flag is
never
reset
,after
bus errors
the system hangs
in the error
interrupt
Prodedure
(
endless)
.
How do I get
the system
working after CAN-Bus Errors? Thanks #bxcan #bug #stm32cube #can #can-sce-silent-mode2014-07-11 12:54 PM
The way I handle CAN errors is to first detect it with excessive TX or RX errors in the SCE interrupt. If it's obvious the node has to disconnect then I switch to SILENT mode in the BTR register. I also disable the SCE interrupts, otherwise they will flood with constant errors.
I set a soft timer in the RTOS (FreeRTOS) to periodically retry the bus by bringing it out of SILENT mode and enabling error interrupts. If the errors reappear then it's back to SILENT again, otherwise I start processing messages. Leaving the bus in SILENT mode ensures it will detect when the bus fault is cleared (assuming it's remote). The periodic enable is in case there are only two nodes and the other one needs a node to complete the network. This is all custom drivers, I don't use the HAL since ST tends to skip any in depth fault handling. Jack Peacock2014-08-06 04:36 AM
Hi Helmut,
Thanks for the feedback. We understand that this is an issue, and that a ''__HAL_UNLOCK()'' is missed in case of error, and as a temporary workaround you can use ''HAL_CAN_DeInit()''. Concerning the 2nd point, yes the MSR>ERRI flag is never reset but other ESR flags are cleared and the generation of interrupt depends on ESR flags and not MSR ones. Please find below ERRIE bit description on RM:Bit 15 ERRIE: Error interrupt enable
0: No interrupt will be generated when an error condition is pending in the CAN_ESR.
1: An interrupt will be generation when an error condition is pending in the CAN_ESR.
Nevertheless this improvement can be done.Thank you for your interest in our STM32Cube solution.Please continue providing valuable feedback.
With regards.
2014-08-07 12:54 AM
Hi Heisenberg,
thanks for your comment. There is also a timing problem in ''HAL_CAN_Transmit_IT(CAN_HandleTypeDef* hcan)''. The macro ''__HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME);'' is called one line to early, so sometimes the ''HAL_CAN_TxCpltCallback()'' ist called when data is not send at this time. Wrong Code: .. .. /* Enable Error Interrupt */ __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); /* Enable Transmit mailbox empty Interrupt */ __HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME); /* Request transmission */ hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; } } else { return HAL_BUSY; } return HAL_OK; } Working Code: .. .. /* Enable Error Interrupt */ __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); /* Enable Transmit mailbox empty Interrupt */ /* Request transmission */ hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; __HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME); } } else { return HAL_BUSY; } return HAL_OK; } Regards Helmut2016-09-14 05:21 AM
Hello All,
I have been using CAN Tx Rx with polling and timeout for a long time but now I want to do it with interrupts. I am usnig an STM32f334c8t7 processor which is interfraced to Microchip's 2562 CAN transciever. I can enable interrrupt in the IER and some CAN messages are sent (6 to be precise) before it all freezes. I can actually not make up the sequence for transmitting via interrupts. When should i enable the TME interrupt when and what should be in the TX Complete callback function. Is it necessary to implement it or not? can somebody please draw a basic outline of the sequence. PS: I am using MX Cube for code generation and i think somehow this HAL locking unlocking is messing it all up. I want to quickly fill all the 3 mail boxes one by one and then they get transmitted and i get the interrupt upon which i would transmit even more messages and so on.Thanks