flatsat & canbus: Create flatsat app with CANBus implementation#147
flatsat & canbus: Create flatsat app with CANBus implementation#147TheArchons wants to merge 3 commits intomainfrom
Conversation
98229de to
d13a7a4
Compare
mshinjo
left a comment
There was a problem hiding this comment.
Just a general comment and I haven’t fully reviewed the changes yet, but:
- Can we create separate patches for different areas? For example, hardware definitions (devicetree) should be in their own patch.
- Can we update the CI workflow to build the new app as well if we are adding a new app
- Is apps/can-bus/prj.conf intentional? What is its purpose? Is it meant to be used with -DCONF?
8d54a19 to
6f5c569
Compare
You're right, I'll split this into two PRs
Sure
Unintentional, fixed |
6fc4665 to
9e69dad
Compare
It doesn't have to be a separate PR, but a separate patch (commit) |
Do you know if it booted at all? |
What do you mean by it? |
|
So @TheArchons are you using HSE or HSI? The last commit suggests you are still using HSI. Also the copilot wants to change it to HSE? Can you update the commit message that HSE works? Feel free to add more info why did you think it didn't work (maybe it was a different configuration). This would help a lot to someone who will work on it later |
|
Otherwise I'm glad it works 🔥 |
|
lgtm also imagine force pushing, skill issue |
Oh yea I forgot to change the commit messages, thanks. |
This provides the configuration needed for CANBus to work on obc. Signed-off-by: Alexander Li <github@thearchons.xyz>
This is mostly the same as the OBC dts in #147, but for PAY. Signed-off-by: Alexander Li <github@thearchons.xyz>
mshinjo
left a comment
There was a problem hiding this comment.
Have we decided between using a separate flatsat image versus developing in the flight software app?
This is mostly the same as the OBC dts in #147, but for PAY. Signed-off-by: Alexander Li <github@thearchons.xyz>
40c2a2a to
2bc1fe7
Compare
I am not sure why this build didn't fail before, but we need to define the CAN configuration for the g431rb. Signed-off-by: Alexander Li <github@thearchons.xyz>
apps/obc/src/main.c
Outdated
| LOG_MODULE_REGISTER(flatsat); | ||
|
|
||
| const struct device *const can = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus)); | ||
|
|
||
| void pi_rx_callback(const struct device *dev, struct can_frame *frame, void *user_data) | ||
| { | ||
| LOG_INF("RECEIVED CAN MESSAGE WITH ID [%x]", frame->id); | ||
|
|
||
| const int dlc = frame->dlc; | ||
|
|
||
| for (int i = 0; i < dlc; i++) { | ||
| LOG_INF("%x", frame->data[i]); | ||
| } | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| while (1) { | ||
| LOG_INF("obc"); | ||
| k_msleep(1000); | ||
| int ret; | ||
|
|
||
| LOG_INF("Starting CAN send"); | ||
|
|
||
| LOG_INF("DEVICE IS READY: %d", device_is_ready(can)); | ||
|
|
||
| if (IS_ENABLED(CONFIG_CAN_MODE_LOOPBACK)) { | ||
| // use loopback mode (send to itself) for debugging | ||
| ret = can_set_mode(can, CAN_MODE_LOOPBACK); | ||
| if (ret != 0) { | ||
| LOG_ERR("Error setting loopback mode [%d]", ret); | ||
| return 0; | ||
| } | ||
| LOG_INF("Loopback mode enabled"); | ||
| } | ||
|
|
||
| ret = can_start(can); | ||
|
|
||
| LOG_INF("CAN STARTED: %d", ret); | ||
|
|
||
| // what to filter for regarding receiving messages | ||
| const struct can_filter pi_filter = { | ||
| .flags = 0U, | ||
| .id = 0x100, // when receiving messages from the pi this must match (e.g. to send 100#ABCD .id needs to be 0x100) | ||
| .mask = CAN_STD_ID_MASK | ||
| }; | ||
|
|
||
| can_add_rx_filter(can, &pi_rx_callback, NULL, &pi_filter); | ||
|
|
||
| while (true) { | ||
| struct can_frame frame = { | ||
| .flags = 0, | ||
| .id = 0x100, | ||
| .dlc = 4, // data length. Must match the number of elements in .data | ||
| .data = { 0xde, 0xad, 0xbe, 0xef } | ||
| }; | ||
| LOG_INF("Waiting 5 seconds"); | ||
| k_msleep(5000); | ||
| ret = can_send(can, &frame, K_MSEC(3000), NULL, NULL); | ||
| if (ret) { | ||
| LOG_ERR("Sending failed [%d]", ret); | ||
| continue; | ||
| } | ||
|
|
||
| LOG_INF("CAN sent successfully"); | ||
| } | ||
|
|
There was a problem hiding this comment.
This isn't OBC specific, so I would say that we clean this up and put it under lib/, and create a thread in apps.
In apps, only thread creations and app specific init code should live.
So in apps, in terms of number of lines, it should be short. My guess is that it would be max 200 lines.
Also, we really should start using libcsp. The CAN transportation shouldn't be happening at the Zephyr API layer. Otherwise, we will starting to create technical debt... and it would be hard to fix and clean up... (which happened before the Zephyr introduction)
@alexapostolu FYI I have some libcsp stuff, which should be PR ready this weekend.
There was a problem hiding this comment.
@mshinjo Are you going to be in the lab on Saturday? We can talk about this more and get the libcsp stuff merged too
There was a problem hiding this comment.
@alexapostolu 50/50 not sure yet. I can probably visit around 5PM. Talking in-person would be way easier and faster.
main.c contains a working CANBus implementation that sends and receives messages to/from the Raspberry Pi on the flatsat. Signed-off-by: Alexander Li <github@thearchons.xyz>
main.c contains code of a working CANBus implmenentation that sends/recieves messages to/from the RaspberryPi on the flatsat.
The main issue was the device tree, which I needed to update to support CAN.
The external clock (hse) didn't work so I needed to use the internal one (hsi). I also changed pll to use hsi instead of hse.hse works, the issue was that you needed to manually specify which clocks to use.