Skip to content
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

Initial working m5stack cardputer setup #8816

Merged
merged 20 commits into from
Mar 7, 2024

Conversation

jamesjnadeau
Copy link

No description provided.

@dhalbert dhalbert marked this pull request as draft January 22, 2024 01:52
@dhalbert
Copy link
Collaborator

I'm going to put this into draft mode so we don't merge it too soon. Take it out of draft mode when you're ready -- thanks.

@jamesjnadeau
Copy link
Author

I have updated the pins file per your request.

I'm still trying some things out, so I think leaving this in draft for another week is probably a good idea, thanks!

@panguin6010
Copy link

// Microphone pins
{ MP_ROM_QSTR(MP_QSTR_MIC_DATA), MP_ROM_PTR(&pin_GPIO46) },
{ MP_ROM_QSTR(MP_QSTR_MIC_CLK), MP_ROM_PTR(&pin_GPIO43) },

@jamesjnadeau Here are the lines for microphone support in pins.c

add microphone pins, thanks @panguin6010
@jamesjnadeau
Copy link
Author

@dhalbert I'm moving this out of draft as it's confirmed working by others and we've sussed out the peripherals.

@jamesjnadeau jamesjnadeau marked this pull request as ready for review January 29, 2024 20:03
Copy link
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.

Two tweaks since the cardputer comes with a StampS3. Not a core.

Copy link

@CDarius CDarius left a comment

Choose a reason for hiding this comment

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

Cardputer has two different SPI bus: one for the display and one for the SD card.
I think it's best to configure both busses

Copy link

@CDarius CDarius left a comment

Choose a reason for hiding this comment

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

The I2C bus exposed in pins.c is not defined anyware

Copy link

@CDarius CDarius left a comment

Choose a reason for hiding this comment

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

The display initializations can be sped up.
In addition it's possible to set the color word endianing in the display and avoid to swap the word in software

@RetiredWizard
Copy link

I tried to implement I2S audio in this branch, but I haven't gotten it working yet:

Unfortunately, I pulled the trigger on purchasing my Cardputer from the manufacturer rather than a local distributor without thinking first so I won't have one to test for a month or two. I suspect that I2S Audio out will work without your PDMIn updates though. I assume you're trying to get the Mic to work using the PDMIn module?

import synthio
import audiobusio
import board
import time

i2s = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
synth = synthio.Synthesizer(sample_rate=22050)
e = synthio.Envelope(attack_time=0,decay_time=0,release_time=0,attack_level=.3,sustain_level=.3)
note = synthio.Note(frequency=261.626,envelope=e)

i2s.play(synth)

synth.press(note)
time.sleep(1)
synth.release(note)

@tannewt
Copy link
Member

tannewt commented Feb 16, 2024

Thanks for the updates! Getting close!

@jamesjnadeau
Copy link
Author

correct @RetiredWizard, I got the mic/speaker crossed. Thanks for the reply and let me know if you give it a try.

@JetForMe
Copy link

@jamesjnadeau I happen to try to connect a PDM mic to a Feather S3 today, only to discover PDMIn hadn't been implemented yet. As I started looking into doing so, I was directed to this PR and to your fork of CP. Is there anything I can do to help get PDM working?

@FoamyGuy
Copy link
Collaborator

FoamyGuy commented Mar 1, 2024

@jamesjnadeau may I ask how to get this flashed onto the device?

I found your post here: https://www.reddit.com/r/CardPuter/comments/19f7num/how_to_start_writing_your_own_codefirmware/kjhv4dg/ that mentions loading the bootloader using the instructions from the UM Feather S3 page. I followed those instructions and I think that I loaded the combined.bin bootloader successfully. Once that is loaded the device connects as a serial port but I don't seem to ever get it connected as a BOOT drive for copying UF2 file. Perhaps I am misunderstanding and it's not that type of bootloader?

In any case Once I've followed the instructions to load the bootloader, and successfully built circuitpython from this branch, what do I need to do next in order to flash the resulting build?

@FoamyGuy
Copy link
Collaborator

FoamyGuy commented Mar 2, 2024

I managed to get Circuitpython loaded. For anyone that might find this page in the future before there are steps published elsewhere these are the steps I took, I'm not entirely certain if they were all 100% necessary, but I got there in the end.

  • Loaded the combined.bin bootloader using the instructions from the UM Feather S3 download page at circuitpython.org (hold GO while powering on to get into bootloader to use with the web flasher)
  • Inside of this branch in ports/esspressif/ ran make BOARD=m5stack_cardputer PORT=/dev/ttyACM1 flash.
  • That finished successfully then I pressed the reset button and it came back up to the BOOT drive
  • Copied the firmware.uf2 that was built onto the BOOT drive with this command: cp build-m5stack_cardputer/firmware.uf2 /media/timc/UFTHRS3BOOT/

@foopod
Copy link

foopod commented Mar 5, 2024

@tannewt @dhalbert it seems like all the requested changes have been incorporated here. Is there anything else this is waiting on?

@dhalbert
Copy link
Collaborator

dhalbert commented Mar 5, 2024

@foopod There is an unresolved question about the SPI buses: #8816 (comment)

@FoamyGuy
Copy link
Collaborator

FoamyGuy commented Mar 6, 2024

I made a new branch from this and pushed in that requested change to expose the second SPI bus, that branch is here: https://github.com/FoamyGuy/circuitpython/tree/m5stack_cardputer_multi_spi with the specific change being inside pins here: https://github.com/FoamyGuy/circuitpython/blob/m5stack_cardputer_multi_spi/ports/espressif/boards/m5stack_cardputer/pins.c#L69-L70

with that change both SPI busses are listed on the board object:

>>> import board
>>> dir(board)
['__class__', '__name__', 'BOOT0', 'BUTTON', 'D1', 'D2', 'DISPLAY', 'I2C', 'I2S_BIT_CLOCK', 'I2S_WORD_SELECT', 'IR_TX', 'IS2_DATA', 'KB_A_0', 'KB_A_1', 'KB_A_2', 'KB_COL_0', 'KB_COL_1', 'KB_COL_2', 'KB_COL_3', 'KB_COL_4', 'KB_COL_5', 'KB_COL_6', 'MIC_CLK', 'MIC_DATA', 'NEOPIXEL', 'PORTA1', 'PORTA2', 'PORTA_I2C', 'RX', 'SD_CS', 'SD_MISO', 'SD_MOSI', 'SD_SCK', 'SD_SPI', 'TFT_BACKLIGHT', 'TFT_BL', 'TFT_CS', 'TFT_DATA', 'TFT_DC', 'TFT_MOSI', 'TFT_RESET', 'TFT_RS', 'TFT_RST', 'TFT_SCK', 'TFT_SPI', 'TX', '__dict__', 'board_id']

I did a very brief test of this using this code to mount the SDCard and print the contents of a test file:

sdcard = sdcardio.SDCard(board.SD_SPI(), board.SD_CS, baudrate=20_000_000)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

print(os.listdir("/sd"))

f = open(f"/sd/{os.listdir('/sd')[0]}", "r")
print(f.read())
f.close()

The pre-existing display initialization inside of board init is using the TFT_SPI and that appears to still function normally as well so far as I can tell.

If that is the only remaining change needed for this I could commit it here potentially, or make a new PR from my branch that has that commit on it. Let me know if there is anything else I can help to get this moved along, I'd love to see support for it added more officially than the PR.

@dhalbert
Copy link
Collaborator

dhalbert commented Mar 7, 2024

If that is the only remaining change needed for this I could commit it here potentially, or make a new PR from my branch that has that commit on it. Let me know if there is anything else I can help to get this moved along, I'd love to see support for it added more officially than the PR.

You can add https://github.com/jamesjnadeau/circuitpython as a remote in a clone of your own repo, pull it, and check out that remote's m5stack_cardputer branch. Then cherry-pick your changes from your own branch, and push. Assuming the usual permission box is checked for the PR, that should work to update this PR.

@FoamyGuy
Copy link
Collaborator

FoamyGuy commented Mar 7, 2024

Thank you! I've added that commit now.

@dhalbert
Copy link
Collaborator

dhalbert commented Mar 7, 2024

Any comments from anyone before we merge this? Thanks.

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

I think the requested changes are now in. Any further fixes could be PR'd.

@dhalbert dhalbert dismissed tannewt’s stale review March 7, 2024 19:50

two SPI buses now present

@dhalbert dhalbert merged commit 60bd748 into adafruit:main Mar 7, 2024
15 checks passed
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.

9 participants