Esp32c6 dual can support with canio#10670
Open
ericbaril72 wants to merge 7 commits intoadafruit:mainfrom
Open
Conversation
Implement display initialization for Waveshare ESP32-C6 Touch LCD.
Add comment for Micropython setup specific to Waveshare ESP32-C6 Touch LCD 1.47.
Added twai_driver_handle and instance fields to canio_can_obj_t structure.
tannewt
requested changes
Oct 16, 2025
Member
tannewt
left a comment
There was a problem hiding this comment.
Thanks for these tweaks! I didn't realize the C6 had two TWAI!
Comment on lines
+296
to
+300
| if (self->instance==0){ | ||
| reserved_can_instance&=0x02; /* free first instance - clear 1st bit */ | ||
| }else if (self->instance==1){ | ||
| reserved_can_instance&=0x01; /* free second instance - clear 2nd bit */ | ||
| } |
Member
There was a problem hiding this comment.
Suggested change
| if (self->instance==0){ | |
| reserved_can_instance&=0x02; /* free first instance - clear 1st bit */ | |
| }else if (self->instance==1){ | |
| reserved_can_instance&=0x01; /* free second instance - clear 2nd bit */ | |
| } | |
| reserved_can_instance &= ~(1 << self->instance); |
This sets the bit and then ~ inverts them.
Comment on lines
+119
to
+133
| byte this_can_instance=0; | ||
| if (reserved_can_instance==0x00){ /* None assigned */ | ||
| reserved_can_instance=0x01; /* First instance is assigned*/ | ||
| this_can_instance=0; /* Idx of selected instance */ | ||
| } | ||
| else if (reserved_can_instance==0x01) /* First instance allready assigned */ | ||
| { | ||
| reserved_can_instance=0x03; /* Second instance also assigned */ | ||
| this_can_instance=1; /* Idx of selected instance */ | ||
|
|
||
| }else if (reserved_can_instance==0x02) /* Second instance is assigned */ | ||
| { | ||
| reserved_can_instance=0x03; /* first instance also assigned*/ | ||
| this_can_instance=0; /* Idx of selected instance */ | ||
| } |
Member
There was a problem hiding this comment.
Use a loop for this. That way it'll work if a chip with more than 2 comes along. The compiler can unroll if desired.
Comment on lines
+21
to
+27
| #define TWAI0 REG_TWAI_BASE(0) /**< \brief (CAN0) APB Base Address */ | ||
| #define TWAI1 REG_TWAI_BASE(1) /**< \brief (CAN1) APB Base Address */ | ||
| #define TWAI_INST_NUM 2 /**< \brief (CAN) Number of instances */ | ||
|
|
||
| static twai_handle_t twai_bus_0; | ||
| static twai_handle_t twai_bus_1; | ||
| static twai_handle_t *const twai_insts[TWAI_INST_NUM] = { &twai_bus_0, &twai_bus_1 }; |
Member
There was a problem hiding this comment.
Guard this based on some defines the IDF provides for the number of TWAI. Otherwise, chips with only 1 instance won't work.
Comment on lines
+9
to
+11
|
|
||
| # Board was originally defined with a 2MB firmware, almost 2MB user filesystem. Leave it that way. | ||
| CIRCUITPY_4MB_FLASH_LARGE_USER_FS_LAYOUT = 1 |
Member
There was a problem hiding this comment.
Remove this since it is a new board.
| @@ -0,0 +1,11 @@ | |||
| CIRCUITPY_CREATOR_ID = 0x1BBB0000 | |||
| CIRCUITPY_CREATION_ID = 0x00C60002 | |||
Member
There was a problem hiding this comment.
Please grab a new id here for the touch version: https://github.com/creationid/creators/blob/main/creations/waveshare.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I refactored the common-hal/canio/can.c to alloy for use of both CAN controllers in the ESP32C6.
Having purchased the "TOUCH" version of waveshare_esp32_c6 with LCD, I also had to create this new board that uses way different pinouts.
Only tested without filters as I am using it as a CAN-to-CAN bridge.
Listener.c DOES need to be modified to select the proper &TWAI if filters are to be used ( MATCH )