2021-09-23 02:48 PM
Hi!
I don't know really how to explain this. But I have enabled CANBUS and it works very good. I also have activated USB and it works too.
But since I have changed the preemption from 0 to 1 for CANBUS RX0, I have no ability to use USB connection.
I changed the preemption from 0 to 1 for CANBUS RX0 because else SysTick would stop. HAL_GetTick() gave the same number for ever as long I was inside the CANBUS RX interrupt function.
What happen when I have 1 for CANBUS RX0 in priority and plug in the USB. From my computers perspective, it says that it could not connect the device.
From my STM32 perspective, I get stuck inside this while loop for ever where wIstr = 41465
/**
* @brief This function handles PCD Endpoint interrupt request.
* @param hpcd PCD handle
* @retval HAL status
*/
static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
{
PCD_EPTypeDef *ep;
uint16_t count, wIstr, wEPVal, TxByteNbre;
uint8_t epindex;
/* stay in loop while pending interrupts */
while ((hpcd->Instance->ISTR & USB_ISTR_CTR) != 0U)
{
wIstr = hpcd->Instance->ISTR;
/* extract highest priority endpoint number */
epindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
if (epindex == 0U)
I activate the CANBUS interrupt with this code. I'm trying out the J1939 CANBUS library https://github.com/DanielMartensson/Open-SAE-J1939
/* Interrupt handler that read message */
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
Open_SAE_J1939_Listen_For_Messages(j1939_handler);
}
static void Create_CAN_Interrupt(CAN_HandleTypeDef *hcan) {
/* Don't forget to check NVIC in CAN -> NVIC Settings -> CAN RX0 interrupt */
if (HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
Error_Handler();
}
Question:
What I acctully want help with is that HAL_GetTick() did not work with CANBUS RX0 priority 0, so I changed the priority to 1. So now HAL_GetTick() works inside the CANBUS RX interrupt function above.
But then USB won't work because I cannot connect it if the CANBUS RX0 priority is 1. So I need to set it to 0 again, but then I'm facing the same issue as before.
So what should I do here?
What do you think?
My STM32 is STM32F373VBTx and I'm using STM32CubeIDE 1.7.0.
Solved! Go to Solution.
2021-10-06 08:09 AM
Hello @Daniel Mårtensson ,
In order to be able to use HAL_GetTick() proprely (HAL relies on it) within an interrupt, SysTick must have higher priority than the interrupt.
Therefore, setting the SysTick's priority to the highest level would in theory allow for it use anywhere.
Unfortunately, and according to the application, setting SysTick to the highest priority might lead to reactivity loss for other events.
As a rule of thumb, waiting for an event within an ISR or doing a time consuming task there isn't advised at all.
Going with option 1 is the most logical thing to do. Option 2 should work in theory. Option 3 would change nothing.
I hope this helps you.
BeST Regards,
Walid
2021-10-06 08:09 AM
Hello @Daniel Mårtensson ,
In order to be able to use HAL_GetTick() proprely (HAL relies on it) within an interrupt, SysTick must have higher priority than the interrupt.
Therefore, setting the SysTick's priority to the highest level would in theory allow for it use anywhere.
Unfortunately, and according to the application, setting SysTick to the highest priority might lead to reactivity loss for other events.
As a rule of thumb, waiting for an event within an ISR or doing a time consuming task there isn't advised at all.
Going with option 1 is the most logical thing to do. Option 2 should work in theory. Option 3 would change nothing.
I hope this helps you.
BeST Regards,
Walid
2021-10-07 12:41 AM
Thank you. I solved this issue by not using delays in an interrupt.
2021-10-07 01:10 AM
Glad to hear that :smiling_face_with_smiling_eyes: Thanks for your feedback.