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

SparkFun updates for the PSRAM draft/work #3

Open
wants to merge 88 commits into
base: feature/psram
Choose a base branch
from

Conversation

gigapod
Copy link

@gigapod gigapod commented Aug 30, 2024

Hi Pimoroni -

This repo:branch looks like the best path to get our updates in the discussion around the PSRAM PR on the micropython/micropython repo.

This PR contains updates that reflect the work we've done to support PSRAM and continues on the discussion/work that took place prior to the RP2350 announcement. We

Updates of note:

  • The frequency of the PSRAM depends on the VDD to the IC (noted in data sheet) - so added a define for that, and made it a parameter to the PSRAM setup/timing functions
  • Separated out the timing setup logic into a separate function - this is called the system clock is changed and after flash is written/erased.
  • Removed all the magic numbers we had in our code - created a variety of constants based on the PSRAM datasheet ..etc
  • Add a variety of comments and supporting links to outline what is taking place ...etc
  • Added board file for our Pro Micro RP2350

-Kirk

dpgeorge and others added 30 commits August 22, 2024 15:11
Signed-off-by: Phil Howard <[email protected]>
Signed-off-by: Damien George <[email protected]>
Remove references to hardware_rtc for rp2350
Reimplement time functioniality
Use hardware_powman instead
Define PICO_PLATFORM for RPI_PICO
move PICO_TINYUSB_PATH until PICO_PLATFORM is defined
PICO_TINYUSB_PATH has to be defined before calling pico_sdk_init
Make sure powerman timer is using xosc
ports/rp2: Updates for powman changes.
Probably another change coming to remove powman and use the new aon
    timer that supports both rp2040 and rp2350
ports/rps: Use aon_timer module.
ports/rp2: Remove rp2350 specific source.
ports/rp2: Use correct CMSIS header for rp2350.
ports/rp2: Add hardware_resets.
ports/rp2: For rp2350 just use aon timer
For rp2040 there's a workaround for RTC having only 1s resolution. This
    is not needed for rp2350
Stop setting PICO_RP2040_B* for rp2350
Only set PICO_RP2040_USB_DEVICE_ENUMERATION_FIX for rp2040

Signed-off-by: Damien George <[email protected]>
Check a target exists before accessing properties.

Usermod_gather_sources would recurse into garbage property names and
break.

Signed-off-by: Phil Howard <[email protected]>
Changes:
- NUM_BANK0_GPIOS > pins defined in pins.csv = hardfault
- make-pins.py: NUM_GPIOS is hard-coded in make-pins.py, make it bigger
- machine_pin.h: Pin "ID" must be six bits, not five (breaks bit packing?)
- mphalport.h/machine_pin.c: open drain mask must be 64bits.

Signed-off-by: Phil Howard <[email protected]>
Add support for 32 and 48 pin variants of RP2350.

Add new gpio_base, mirroring the Pico SDK.

Signed-off-by: Phil Howard <[email protected]>
NUM_GPIOS amd NUM_EXT_GPIOS is currently hardcoded in this python
script.

Pass the count in via the new parameters num-gpios and num-ext-gpios.
These default to the current values supported by Pico 30/10. This can be
changed with PICO_NUM_GPIOS and PICO_NUM_EXT_GPIOS in
mpconfigboard.cmake. Without this you will get a build error because
NUM_BANK0_GPIOS can be too small.

Signed-off-by: Damien George <[email protected]>
Fix the gpio_irq function so that it looks at all six
iobank0_hw->intr[n] registers, for up to 48 IOs.

Signed-off-by: Phil Howard <[email protected]>
Note: This might be a tempoarary measure until we might fix this
properly to avoid copying code.

Signed-off-by: Damien George <[email protected]>
dpgeorge and others added 18 commits August 30, 2024 15:18
To test construction of UART instances.

Signed-off-by: Damien George <[email protected]>
Provide stub implementations of localtime_r() and mktime() to avoid
code size increase.

Reported upstream at raspberrypi/pico-sdk#1810

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Add PSRAM support with auto detection.

Performs a best-effort attempt to detect attached PSRAM,
configure it and *add* it to the MicroPython heap.

If PSRAM is not present, should fall back to use internal
RAM.

Introduce two new port/board defines:

* MICROPY_HW_ENABLE_PSRAM to enable PSRAM.
* MICROPY_HW_PSRAM_CS_PIN to define the chip-select pin.

Changes:

ports/rp2/rp2_psram.c/h: Add new PSRAM module.
ports/rp2/main.c: Add optional PSRAM support.
ports/rp2/CMakeLists.txt: Include rp2_psram.c.
ports/rp2/rp2_flash.c: Add buffered write to avoid reads from PSRAM.
ports/rp2/mpconfigport.h: Enable MICROPY_GC_SPLIT_HEAP
for boards that set MICROPY_HW_ENABLE_PSRAM.

Co-authored-by: Kirk Benell <[email protected]>
Co-authored-by: Mike Bell <[email protected]>
Signed-off-by: Phil Howard <[email protected]>
My tests found issues when PSRAM is combined with the existing
RAM in a split-heap configuration. Since this option is not
enabled by default on RP2 I have changed it to be optional.

PSRAM will be used exclusively if MICROPY_GC_SPLIT_HEAP == 0,
it will be added to RAM if MICROPY_GC_SPLIT_HEAP == 1,
and the system will fall back to RAM only if it's not detected.

Signed-off-by: Phil Howard <[email protected]>
@Gadgetoid Gadgetoid force-pushed the feature/psram branch 2 times, most recently from 2fae3a9 to 3cd6781 Compare September 5, 2024 08:24
@Gadgetoid Gadgetoid force-pushed the feature/psram branch 2 times, most recently from b504e66 to c98c139 Compare September 27, 2024 13:39
@Gadgetoid Gadgetoid force-pushed the feature/psram branch 3 times, most recently from 55880bf to 1585553 Compare October 23, 2024 10:01
@Gadgetoid
Copy link
Member

Sorry this PR had totally slipped me by!

On the off chance you (Or anyone else passing by here) hasn't seen it, I have an open pull request against the MicroPython repository if you want your comments/concerns to be heard by the maintainers there - micropython#15620

From a first glance it looks like I should cherry pick over the split heap enable for SPARKFUN_PROMICRO_RP2350.

Since rebases tend to go very badly, I've been constantly deleting the feature/psram branch, grabbing a fresh copy of upstream and cherry picking our current work over to it.

If you get time to do the same - take a clean copy of feature/psram and add the commits you need on top - that would be super helpful!

I think we're missing a lot of testing/feedback on micropython#15620 so if you've got any experience with PSRAM (good or bad) (I guess you've deployed it to customers like we have) then weighing in there would help keep things moving. The PR is a little buried and probably not a super high priority so anything we can do to keep the flame alive will be helpful.

@gigapod
Copy link
Author

gigapod commented Oct 24, 2024

No worries - it's been a busy couple months.

Let me look at getting this into the micorpython PR mentioned - doing this PR hear seemed easier at the time... This will probably take a couple weeks (out at RPi event next week).

I'll also provide feedback to the micropython PR based on our experience with PSRAM and feedback we've received on the binary we've published

Cheers,
-Kirk

@dhalbert
Copy link

Also take a look at adafruit#9759, re cache invalidation. Maybe you are already doing that way: there are a lot of commits here and I couldn't find the relevant code 🙂 .

@gigapod
Copy link
Author

gigapod commented Oct 25, 2024

Thanks for the pointer to what was done on circuit py - we'll check this when we merge our impl back on the micro py branch. Should be straightforward -I suspect the difficult bit will be the merge logistics :)

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