diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..84fd8a3bcecdcc9698ae761574e2be2eb2064036 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.13) + +include($ENV{PICO_SDK_PATH}/external/pico_sdk_import.cmake) + +project(ring C CXX ASM) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) + +pico_sdk_init() + +add_executable(ring) + +pico_generate_pio_header(ring ${CMAKE_CURRENT_LIST_DIR}/ring.RP2040PIO.pio) + +target_sources(ring PRIVATE ring.RP2040PIO.c) + +target_link_libraries(ring pico_stdlib hardware_pio) + +pico_add_extra_outputs(ring) diff --git a/README.md b/README.md index 0a1bba7462c3f65ab05ca697bc6e57c28dfa0501..f6890291f21488e2009a5c127c3b036bd7aa2ed6 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,39 @@ # rp2040-ring-pio +This is a demonstration of the RP2040's PIO system, which let you run several state machines independently of the CPU. There's exactly 0 overhead and the state machines run a custom assembly language with very few instructions. - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +In this example implementation of a [ring oscillator](https://pub.pages.cba.mit.edu/ring/), pin 1 is configured as a PIO input, and pin 2 as an output. Reading, inverting and writing is as simple as: ``` -cd existing_repo -git remote add origin https://gitlab.cba.mit.edu/quentinbolsee/rp2040-ring-pio.git -git branch -M main -git push -uf origin main +.program ring + mov pins, !pins +.wrap ``` -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.cba.mit.edu/quentinbolsee/rp2040-ring-pio/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** +## Results -# Editing this README +| CPU Freq | Ring Freq | +| -------- | ---------- | +| 133 MHz | 16.667 MHz | +| 250 MHz | 25 MHz | -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. +## Binaries -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +You can find compiled binaries in [build/](./build/). Simply drang and drop the `.uf2` file on your raspberry pi pico's storage space after putting it in reset mode (boot button + power cycle). -## Name -Choose a self-explaining name for your project. +## Build -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +Navigate to `build/` and generate the project using cmake: -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +``` +cd build/ +cmake .. +``` -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. +This should create a Makefile, and you can simply build the project every time you update the code by running: -## License -For open source projects, say how it is licensed. +``` +make +``` -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +The output is `bin`, `elf`, `hex` and `uf2` files in `build/`. diff --git a/build/ring_133MHz.bin b/build/ring_133MHz.bin new file mode 100644 index 0000000000000000000000000000000000000000..c500a6c33479d456d6f3e5cfba1b88587cd8a8ec Binary files /dev/null and b/build/ring_133MHz.bin differ diff --git a/build/ring_133MHz.elf b/build/ring_133MHz.elf new file mode 100644 index 0000000000000000000000000000000000000000..3c57d5efa1097239c6094d254e9dedeb0d41f846 Binary files /dev/null and b/build/ring_133MHz.elf differ diff --git a/build/ring_133MHz.uf2 b/build/ring_133MHz.uf2 new file mode 100644 index 0000000000000000000000000000000000000000..a065dda6a502316e110774cedd473ae60c5f73cf Binary files /dev/null and b/build/ring_133MHz.uf2 differ diff --git a/build/ring_250MHz.bin b/build/ring_250MHz.bin new file mode 100644 index 0000000000000000000000000000000000000000..91c057ebb9b088a308b9f23505ebf975e8adbc03 Binary files /dev/null and b/build/ring_250MHz.bin differ diff --git a/build/ring_250MHz.elf b/build/ring_250MHz.elf new file mode 100644 index 0000000000000000000000000000000000000000..51a5ffbfc740f10fbaa17a8182e161ef19d98ea6 Binary files /dev/null and b/build/ring_250MHz.elf differ diff --git a/build/ring_250MHz.uf2 b/build/ring_250MHz.uf2 new file mode 100644 index 0000000000000000000000000000000000000000..53bfaf8ef33763ae20b2bcbcf0e774c038733cca Binary files /dev/null and b/build/ring_250MHz.uf2 differ diff --git a/ring.RP2040PIO.c b/ring.RP2040PIO.c new file mode 100644 index 0000000000000000000000000000000000000000..4b1513bc423083a7113781e82edd572b0e160d7b --- /dev/null +++ b/ring.RP2040PIO.c @@ -0,0 +1,32 @@ +// +// ring.RP2040PIO.c +// RP2040 ring oscillator test with PIO +// connect P1 and P2 +// +// Quentin Bolsee 12/27/22 +// +// This work may be reproduced, modified, distributed, +// performed, and displayed for any purpose, but must +// acknowledge this project. Copyright is retained and +// must be preserved. The work is provided as is; no +// warranty is provided, and users accept all liability. +// + +#include "pico/stdlib.h" +#include "hardware/pio.h" +#include "hardware/clocks.h" +#include "hardware/structs/sio.h" +#include "ring.RP2040PIO.pio.h" + +#define IN_PIN 1 +#define OUT_PIN 2 + +int main() { + // set_sys_clock_khz(133000, false); + set_sys_clock_khz(250000, false); + + PIO pio = pio0; + uint offset = pio_add_program(pio, &ring_program); + uint sm = pio_claim_unused_sm(pio, true); + ring_program_init(pio, sm, offset, IN_PIN, OUT_PIN); +} diff --git a/ring.RP2040PIO.pio b/ring.RP2040PIO.pio new file mode 100644 index 0000000000000000000000000000000000000000..87deae0109a687e697cc948240b0cc42503425fc --- /dev/null +++ b/ring.RP2040PIO.pio @@ -0,0 +1,40 @@ +// +// ring.RP2040PIO.pio +// RP2040 ring oscillator test with PIO +// connect P1 and P2 +// +// Quentin Bolsee 12/27/22 +// +// This work may be reproduced, modified, distributed, +// performed, and displayed for any purpose, but must +// acknowledge this project. Copyright is retained and +// must be preserved. The work is provided as is; no +// warranty is provided, and users accept all liability. +// + +.program ring + mov pins, !pins +.wrap + + +% c-sdk { +static inline void ring_program_init(PIO pio, uint sm, uint offset, uint pin_in, uint pin_out) { + pio_sm_config c = ring_program_get_default_config(offset); + + sm_config_set_in_pins(&c, pin_in); + sm_config_set_out_pins(&c, pin_out, 1); + + // Set this pin's GPIO function (connect PIO to the pad) + pio_gpio_init(pio, pin_in); + pio_gpio_init(pio, pin_out); + + // Set the pin direction to output at the PIO + pio_sm_set_consecutive_pindirs(pio, sm, pin_in, 1, false); + pio_sm_set_consecutive_pindirs(pio, sm, pin_out, 1, true); + + // Load our configuration, and jump to the start of the program + pio_sm_init(pio, sm, offset, &c); + // Set the state machine running + pio_sm_set_enabled(pio, sm, true); +} +%}