Skip to content

Fix cardputer boot loop, and do some cleanup#10607

Merged
tannewt merged 4 commits intoadafruit:mainfrom
dhalbert:cardputer-keyboard-fix
Sep 4, 2025
Merged

Fix cardputer boot loop, and do some cleanup#10607
tannewt merged 4 commits intoadafruit:mainfrom
dhalbert:cardputer-keyboard-fix

Conversation

@dhalbert
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert commented Sep 3, 2025

Detailed changes:

  • For cardputer_keyboard.c, allocate DemuxKeyMatrix it creates and the objects it holds (all the way down) on the port heap, because it lives past VM's.
  • To do the above, add support for non-VM heap for DemuxKeyMatrix and the keypad allocations it needs by passing an arg use_gc_allocator, as is done in lvfontio.
  • Add mp_obj_port_malloc(), mp_obj_port_malloc_var(), mp_obj_new_port_tuple(), all of which allocate on the port heap, not the VM heap.
  • Add port_malloc_zero(), because port_malloc() did not zero out its allocation, unlike VM heap allocations. I got caught by this.
  • Move port_gc_collect() from main.c to supervisor/port.c for consistency. This function is not actually used by anyone, but I was considering using it.
    -Add an MP_WEAK mp_board_init(), for board-specific initializations needed when a VM starts. Also considered, but not used. Added anyway for possible future use.
  • Add an MP_WEAK board_gc_collect(), for board-specific gc. Not used.
  • Don't duplicate keyboard code between boards/m5stack_cardputer and boards/m5stack_cardputer_ros. Instead, add a ports/espressif/module directory for this code, in the style of a port-specific module directory, like the port-specific bindings directories.

My original approach to this was to make the cardputer_keyboard object be allocated when the VM started up. That required less pervasive changes, and it worked fine, except for the Press any key... when the VM finished. So I had to make it live across VM's.

I tested and @dglaude also tested (thanks!).

@dhalbert dhalbert force-pushed the cardputer-keyboard-fix branch from 49024ef to c121d73 Compare September 3, 2025 01:41
- For `cardputer_keyboard.c`, allocate `DemuxKeyMatrix` it creates and the objects it holds (all the way down) on the port heap, because it lives past VM's.
- To do the above, add support for non-VM heap for `DemuxKeyMatrix` and the `keypad` allocations it needs by passing an arg `use_gc_allocator`, as is done in `lvfontio`.
- Add `mp_obj_port_malloc()`, `mp_obj_port_malloc_var()`, `mp_obj_new_port_tuple()`, all of which allocate on the port heap, not the VM heap.
- Add `port_malloc_zero()`, because `port_malloc()` did not zero out its allocation, unlike VM heap allocations. I got caught by this.
- Move `port_gc_collect()` from `main.c` to `supervisor/port.c` for consistency. This function is not actually used by anyone, but I was considering using it.
- Add an `MP_WEAK` `mp_board_init()`, for board-specific initializations needed when a VM starts. Also considered, but not used. Added anyway for possible future use.
- Add an `MP_WEAK` `board_gc_collect()`, for board-specific gc. Not used.
- Add an `MP_WEAK` `port_gc_collect()`, for port-specific gc. Not used.
- Don't duplicate keyboard code between `boards/m5stack_cardputer` and `boards/m5stack_cardputer_ros`. Instead, add a `ports/espressif/module` directory for this code, in the style of a port-specific `module` directory, like the port-specific `bindings` directories.
@dhalbert dhalbert force-pushed the cardputer-keyboard-fix branch from c121d73 to de2efe0 Compare September 3, 2025 02:08
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.

It would be preferable to just disable this warning, but Clang
-Wunknown-warning-option kicks in even when disabling warnings so this
becomes fiddly to apply.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Avoids the new Wunterminated-string-literal when compiled with gcc 15.1.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
@dhalbert
Copy link
Copy Markdown
Collaborator Author

dhalbert commented Sep 3, 2025

I cherry-picked two commits from micropython#17269 to fix a gcc 15 build problem on Windows.

@dhalbert dhalbert requested a review from tannewt September 3, 2025 14:08
Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor thing. Thanks!

Comment thread supervisor/shared/board.c Outdated
@dhalbert dhalbert requested a review from tannewt September 3, 2025 23:54
Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 17ea151 into adafruit:main Sep 4, 2025
1249 of 1250 checks passed
@dhalbert dhalbert deleted the cardputer-keyboard-fix branch March 4, 2026 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

M5Stack Cardputer bootloop with CircuitPython 10.0.0-beta.2

3 participants