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

Upgrade HardwareSPI library with Rp2040 support #2470

Merged
merged 8 commits into from
Jan 21, 2022

Conversation

mikee47
Copy link
Contributor

@mikee47 mikee47 commented Jan 20, 2022

This PR adds support for Rp2040 to the HardwareSPI and Graphics libraries.

Host support is also improved to allow integration testing.
This includes revisions to thread/interrupt handling to more closely emulate real hardware behaviour.

HardwareSPI

  • Refactor using architecture-specific ControllerBase class to simplify/clarify Controller.h.

  • Replace maxTransactionSize with sizeAlign

    Required only where requests have to be split up due to size.

    For example, transferring 4K of display pixel data for ESP8266 will require splitting into transactions of 64 bytes or less.
    The data must be transferred strictly in groups of 3 bytes (R, G, B) so sizeAlign=3 ensures this happens.

    ESP32 has ~4K DMA capability, so still must be considered.
    RP2040 has no DMA size restriction so can be simplified.

  • Fix Host Controller sequencing

    A complex application (e.g. Basic_Graphics) should run without stalling, race conditions or exceptions.

Improvements

  • Add version header

  • Add loopback method to Controller

  • Copy pin setup from SPI library

    Provides some consistency between the two libraries.

  • Supported device IO mode also depends on controller capability

    e.g. Device may support quad modes but controller may not,
    so Device::isSupported method returns intersection of device/controller capabilities.

  • Add Rp2040 implementation

    DMA transaction sizes are unrestricted which simplifies code, offset by lack of cmd/address/dummy
    phase support which complicates it.

    Hardware CS behaviour is weird. It gets asserted for every word in mode 0 or 2 (but not 1 or 3).
    This breaks operation with some devices, e.g. ILI9341.
    Also, there's no 'request complete' interrupt available.

    This is solved by using standard GPIO for CS control and completing request on RX DMA interrupt.

  • Add test application

    Provides a vehicle for testing basic operation and performing integration testing.

    Improved Host interrupt support in framework allows inclusion in CI testing,
    inserting calculated delay (based on number of bits being transferred) before firing interrupt.

Graphics

  • Add Rp2040 support

  • Remove extraneous file added in error - duplicate of file in resource/fonts/Linux/

  • Fix issue with showFonts in Basic_Graphics sample

    Gets stuck second time around the loop

  • Update Basic_Graphics sample, use for integration tests

    Simplify font functions.
    Add build variables to configure application to run more quickly so it can be used in CI testing.

    Host HardwareSPI may not do much but it allows the control flow to be verified and checked with valgrind, etc.

  • Fix access violation rendering fonts

    Detected in Windows CI run.

  • Don't assume location of Graphics library

    Running CI on standalone library means it won't be in the Sming repo.

Framework

  • Fix flashmem read

    Must claim DMA channel so it doesn't get given to HardwareSPI.

  • Improve CThread interrupt handling

    Make host_printf, etc. threadsafe using write instead of buffered printf calls.

    Honour interrupt levels, masking out lower-level threads during interrupt

    Main thread synchronisation fixed. Mitigate signal deadlock using timer.

    Note: Running in valgrind may encounter 'undefined syscall' errors (407, 409)
    due to missing wrappers for 64-bit time functions.
    Valgrind version 3.17 has the wrappers (available in Ubuntu 21.04).

  • Add CI test notification support

    Graphics library test uses a sample application rather than SmingTest,
    so notifications are handled in a makefile.

  • Update Graphics & HardwareSPI libraries

    RP2040 support added.

  • Use 64-bit python

    Freetype python library doesn't work on Windows as DLL isn't installed for 32-bit python.
    This only happens with standard appveyor system as C:\Python39 contains 32-bit python installation.

Honour interrupt levels, masking out lower-level threads during interrupt
Main thread synchronisation fixed
Mitigate signal deadlock using timer
@slaff slaff added this to the 4.6.0 milestone Jan 20, 2022
@mikee47 mikee47 force-pushed the feature/rp2040-hwspi branch from 4dc634e to a73796a Compare January 20, 2022 14:48
Fix `Device::isSupported` method
Handle full/half duplex transfers for Rp2040
Run `testCombos` for all supported IO modes
@slaff
Copy link
Contributor

slaff commented Jan 21, 2022

@mikee47 are you ready with this PR or would like to add something more? I have tested only the host emulator and so far looks good to me. Were you able to test the changes on real Rp2040?

@mikee47
Copy link
Contributor Author

mikee47 commented Jan 21, 2022

@slaff Yes, all done. Tested on real Rp2040, runs great.

@slaff slaff merged commit 98d189c into SmingHub:develop Jan 21, 2022
@slaff slaff mentioned this pull request Jan 26, 2022
5 tasks
@mikee47 mikee47 deleted the feature/rp2040-hwspi branch February 24, 2022 20:18
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.

2 participants