Skip to content

Commit

Permalink
Freezieng CAN and USB on High traffic fix
Browse files Browse the repository at this point in the history
Freezieng CAN and USB on High traffic fix
  • Loading branch information
Lukasz-Juranek committed Dec 5, 2016
1 parent 7d921da commit 1ac4ff0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
10 changes: 0 additions & 10 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,6 @@ int main(void)
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1) {

if (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED)
{
/* fix for high traffic issue (CAN reception is blocked on high Tx/Rx traffic,
* caused probably by USB/CAN interrupt race, possible to resolve not checking USB busy
*/
printf("Shame on You lazy programmer!\n"); // TODO do the fix !
printf("Shame on You lazy programmer!\n");
}

slCanCheckCommand();
if (canRxFlags.flags.byte != 0) {
slcanReciveCanFrame(hcan.pRxMsg);
Expand Down
17 changes: 14 additions & 3 deletions Src/slcan/slcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ extern UART_HandleTypeDef huart2;
extern USBD_HandleTypeDef hUsbDeviceFS;
static void slcanOutputFlush(void)
{
while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK);


if (hUsbDeviceFS.dev_state != USBD_STATE_CONFIGURED) // use auxiliary uart only if usb not connected
HAL_UART_Transmit(&huart2,sl_frame,sl_frame_len,100); //ll todo figure out time
else {
while (CDC_Transmit_FS(sl_frame, sl_frame_len) != USBD_OK);
while (((USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData)->TxState)
{
volatile i;
i++;
}
}
sl_frame_len = 0;
}

Expand Down Expand Up @@ -141,7 +149,7 @@ static uint8_t parseHex(uint8_t* line, uint8_t len, uint32_t* value) {
static uint8_t transmitStd(uint8_t* line) {
uint32_t temp;
uint8_t idlen;

HAL_StatusTypeDef tr;

hcan.pTxMsg->RTR = ((line[0] == 'r') || (line[0] == 'R'));

Expand Down Expand Up @@ -173,7 +181,10 @@ static uint8_t transmitStd(uint8_t* line) {
}
}

return HAL_CAN_Transmit(&hcan, 1000);
HAL_NVIC_DisableIRQ(CEC_CAN_IRQn);
tr = HAL_CAN_Transmit(&hcan, 1000);
HAL_NVIC_EnableIRQ(CEC_CAN_IRQn);
return tr;
}


Expand Down

0 comments on commit 1ac4ff0

Please sign in to comment.