diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..7a12509 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,26 @@ +## Description + + + +## Related Issue + + + +## Type of Change + +- [ ] Bug fix +- [ ] New feature +- [ ] Breaking change +- [ ] Documentation update +- [ ] Refactor / code cleanup + +## Checklist + +- [ ] I have tested the changes on a hardware +- [ ] I have checked that the PR works for `CAN` and `FDCAN` devices, and explained if and why this rule deviates +- [ ] I have performed the `python3 scripts/build.py` with success and no errors +- [ ] I have checked and run `clang-format` with the repository input to format the code + +## Additional Notes + + \ No newline at end of file diff --git a/CANopenNode_STM32/CO_driver_STM32.c b/CANopenNode_STM32/CO_driver_STM32.c index 5b87d9c..ed9d972 100644 --- a/CANopenNode_STM32/CO_driver_STM32.c +++ b/CANopenNode_STM32/CO_driver_STM32.c @@ -40,9 +40,9 @@ static CO_CANmodule_t* CANModule_local = NULL; /* Local instance of global CAN m #ifdef CO_STM32_FDCAN_Driver #ifndef FDCAN_BUFFER_INDEXES -#if defined (FDCAN_TX_BUFFER31) +#if defined(FDCAN_TX_BUFFER31) #define FDCAN_BUFFER_INDEXES 0xFFFFFFFFU -#elif defined (FDCAN_TX_BUFFER2) +#elif defined(FDCAN_TX_BUFFER2) #define FDCAN_BUFFER_INDEXES FDCAN_TX_BUFFER0 | FDCAN_TX_BUFFER1 | FDCAN_TX_BUFFER2 #else #define FDCAN_BUFFER_INDEXES 0xFFFFFFFFU @@ -517,9 +517,18 @@ prv_read_can_received_msg(CAN_HandleTypeDef* hcan, uint32_t fifo, uint32_t fifo_ uint8_t messageFound = 0; #ifdef CO_STM32_FDCAN_Driver + + /* + * Write received message to the temporary 64-bytes buffer. + * This is to ensure that the CAN nodes that do not comply with the newer CAN standards + * don't send wrong message with the wrong DLC value. This is a safety measure to avoid buffer overflow. + * + * Check the FDCAN implementation for STM32 in their respective reference manual. + */ static FDCAN_RxHeaderTypeDef rx_hdr; + static uint8_t rx_data[64]; /* Read received message from FIFO */ - if (HAL_FDCAN_GetRxMessage(hfdcan, fifo, &rx_hdr, rcvMsg.data) != HAL_OK) { + if (HAL_FDCAN_GetRxMessage(hfdcan, fifo, &rx_hdr, rx_data) != HAL_OK) { return; } /* Setup identifier (with RTR) and length */ @@ -556,6 +565,9 @@ prv_read_can_received_msg(CAN_HandleTypeDef* hcan, uint32_t fifo, uint32_t fifo_ rcvMsg.dlc = 0; break; /* Invalid length when more than 8 */ } + if (rcvMsg.dlc > 0) { + memcpy(rcvMsg.data, rx_data, rcvMsg.dlc); + } rcvMsgIdent = rcvMsg.ident; #else static CAN_RxHeaderTypeDef rx_hdr; @@ -653,7 +665,7 @@ HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef* hfdcan, uint32_t BufferI CANModule_local->CANtxCount--; CANModule_local->bufferInhibitFlag = buffer->syncFlag; } else { - break; // if we could not send the message, break out of the loop (the tx buffers are full) + break; // if we could not send the message, break out of the loop (the tx buffers are full) } } } @@ -712,9 +724,9 @@ CO_CANinterrupt_TX(CO_CANmodule_t* CANmodule, uint32_t MailboxNumber) { buffer->bufferFull = false; CANmodule->CANtxCount--; CANmodule->bufferInhibitFlag = buffer->syncFlag; + } else { + break; // if we could not send the message, break out of the loop (the tx buffers are full) } - else - break; // if we could not send the message, break out of the loop (the tx buffers are full) } } CO_UNLOCK_CAN_SEND(CANmodule);