-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Drivers] CAN #14
Labels
Milestone
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CubeMX tasks
Update: (1 x extended filter x 10 words) + (16 x Rx Fifo elements x 18 words) + (16 x Tx Fifo elements x 18 words) = 586 words
Update: We probably don't need it. Just leave it disabled.
Main Tasks
HAL_FDCAN_ErrorCallback()
,HAL_FDCAN_ActivateNotification((&hcan, CAN_IT_RX_FIFO0_MSG_PENDING | CAN_IT_ERROR)
...The last currently enables only the FDCAN_IE_RF0NE , FDCAN_IE_RF1NE flags...we should have more here.Update:
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
inside the callback.Update: Added
Inside the callback, we increment the lastItemPointer to point to a different location on the local buffer to accommodate each Frame payload of 8 bytes.
CAN::Frame newFrame;
holds exactly what you need to find the CAN messages (Main or redundant CAN, pointer to data HAL Header)xQueueSendToBackFromISR(canGatekeeperTask->incomingFrameQueue, &newFrame, NULL);
Then you send the data other canGatekeeperTask.Update:
Changed tx logic. Send functions are changed to blocking to ensure no array is overflowing (check TPProtocol at the createCANTPMessage). As for the RX, there is no issue with the queues because no one can send if he has not received ACK, so this delay will prevent RX queue from overflowing. In case something goes wrong, the message will just be ignored.
Update:
No. The next multi-frame message can only start after the ACK is received (protected by a mutex).
Update: Every CAN packet is stored in the eMMC and a handler is put in a queue and pushed to the Application layer. Handling is then done by the application layer. In the application layer you have the following :
void getStoredMessage(CAN::StoredPacket* packet, uint8_t* dataBuffer, uint32_t dataSize, uint32_t bufferSize)
Update:
HAL_StatusTypeDef HAL_FDCAN_GetProtocolStatus(const FDCAN_HandleTypeDef *hfdcan, FDCAN_ProtocolStatusTypeDef *ProtocolStatus);
Update:
The OBC CAN bud enters an unrecoverable state after the COMMS is powered off. The only way we found to make it work again is to reinitialize the CAN peripheraal. COMMS recovers just fine so reinitializing was not necessary.
Update: Yes but we don't care for the order of the consecutive frames but we do care about receiving the first and and the final frame.
Update: The NACK would be useful only for efficiency reasons - the OBC for example will not need to wait for the timeout to end in blocking mode. It is not ideal, but we will use the timeout of 1s as a baseline and the capability of having this as a variable in the database.
Note
The first frame has only metadata and all the other frames (both consecutive and final) have 6 bytes of actual info and 2 bytes of metadata (as for the consecutive: the first one is the frame type and the second one is frame number while the final has as the second one the number of data in bytes).
Packet: 1024 bytes of usable info
Frame: CAN header + 8 bytes of usable info
Frame Payload: 8 bytes of usable info
Message: whatever we send
Update:
The frame ID now does not hold any metadata about the message. The message ID is the first byte of the packet.
Update:
Tested with simultaneous rx/tx. It can handle it just fine.
Test Tasks
Findings: The FIFO 1 does not work in the old repo.
Update:
Update The function is working.
Update: Correct use of MCAN_Initialize() on the OBC side.
Update:
Found a way to ignore these frames from the COMMS.
{01 10 11}: First two bits of the first byte of the payload on a multi-frame packet, so after running some tests we found that if these bits are equal to 00 we have an error so we drop them.
The single frames will not have 00 in the second byte, so that's why we have the following code in the ISR
CAN BUS Errors
The module (CAN controller) handles the error autonomously, typically by retransmitting the message (even if it is on Error Active State or Error Passive State, not when it is one Bus-off state)
Error Handling
After detecting one of the above-described errors an error frame will be transmitted immediately. The error frame consists of 2 different fields. The first field is given by the superposition of error flags contributed from different nodes. The second field is the error delimiter. A node detecting an error condition signals this by transmission of an active error flag. The error flag's form violates the rule of bit stuffing or destroys the bit field requiring a fixed form. As a consequence, all other nodes also detect an error condition and likewise start transmission of an error flag. So the sequence of dominant bits, which actually can be monitored on the bus, results from a superposition of different error flags transmitted by individual nodes. The total length of this sequence varies between a minimum of 6 and a maximum of 12 bits. Passive error flags initiated by a transmitter cause errors at the receivers when they start in a frame field which is encoded by the method of bit stuffing, because they then lead to stuff errors detected by the receivers. This requires, however, that such an error flag does not start during arbitration and another node continues transmitting, or that it starts very few bits before the end of the CRC sequence and the last bits of the CRC sequence happen to be all recessive. Passive error flags initiated by receivers are not able to prevail in any activity on the bus line. Therefore, "error passive" receivers always have to wait 6 subsequent equal bits after detecting an error condition, until they have completed their error flag. The error delimiter consists of 8 recessive bits. After transmission of an error flag, each node sends recessive bits and monitors the bus until it detects a recessive bit. It then starts transmitting 7 more recessive bits.
The error handling happens in the following order:
Error Counters
Increases for transmission errors.
Increases for reception errors.
Error States - Error Limitation
In this case, the CAN module must be reset via software somehow, as switching to the redundant bus will not suffice; the issue could recur on the redundant bus, leading to a deadlock.
BUS Switch Over
AcubeSat Logic
Το OBC αποστέλλει μηνύματα Ping σε κάϑε κόμβο με την ίδια περίοδο THB = 5 δευτερολέπτων, τα οποία απαιτούν πάντηση Pong από τον εκάστοτε κόμβο. Η πρακτική αυτή βοηϑά στη διευκρίνιση της αστοχία στις γραμμές TX ή RX.
• Σε περίπτωση που δεν ληφθεί μήνυμα καρδιακού παλμού ή απάντηση σε ένα μήνυμα Ping, από όλους τους κόμβους σε παράϑυρο TT = 30 δευτερολέπτων, το OBC ϑεωρεί ότι ο δίαυλος απέτυχε και αποστέλλει μήνυμα Bus Switchover το οποίο ανακοινώνει τον πλέον εν λειτουργία δίαυλο. Το μήνυμα αυτό
μεταδίδεται και στους δύο κόμβους.
• Για να αποφευχϑούν περιπτώσεις που κάποιος από τους κόμβους βρίσκεται εκτός συγχρονισμού όσον αφορά τον ενεργό δίαυλο, το OBC περιοδικά ανακοινώνει την παράμετρο που περιλαμβάνει την πληροφορία. Η περίοδος αυτής της ανακοίνωσης δεν έχει αποφασιστεί ακόμα.
PeakSat Logic
I think it is better for the COMMS to listen to both channels.
References
Note: On a CAN bus, a frame is the basic unit of messaging. For a classic CAN bus, a frame consists of an 11-bit identifier along with an 8-byte message payload. For CAN FD, a frame is labelled with a 29-bit identifier and carries a 64-byte message payload.
CAN-TP Protocol
https://controllerstech.com/stm32-fdcan-in-loopback-mode/
STM32 CAN Application Note
bit timing parameters
sos
thesis
CAN Wiki - Acubesat
CAN Bus Errors Exmplained
An Introduction to CAN
Questions
The text was updated successfully, but these errors were encountered: