{"id":16276533,"url":"https://github.com/virgesmith/pico-c-pymodules","last_synced_at":"2025-07-04T12:34:21.597Z","repository":{"id":87710796,"uuid":"482063085","full_name":"virgesmith/pico-c-pymodules","owner":"virgesmith","description":"C and C++ custom modules for micropython","archived":false,"fork":false,"pushed_at":"2022-04-22T11:42:01.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T16:55:16.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/virgesmith.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-15T19:24:41.000Z","updated_at":"2022-04-15T20:15:45.000Z","dependencies_parsed_at":"2023-03-13T18:39:50.531Z","dependency_job_id":null,"html_url":"https://github.com/virgesmith/pico-c-pymodules","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/virgesmith/pico-c-pymodules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpico-c-pymodules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpico-c-pymodules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpico-c-pymodules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpico-c-pymodules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virgesmith","download_url":"https://codeload.github.com/virgesmith/pico-c-pymodules/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virgesmith%2Fpico-c-pymodules/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260988028,"owners_count":23093427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-10T18:48:44.957Z","updated_at":"2025-06-20T17:33:53.469Z","avatar_url":"https://github.com/virgesmith.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Custom C and C++ modules for micropython\n\n## prerequisites\n\n- Raspberry Pi Pico, C/C++ SDK and toolchain\n- micropython source tree\n- python enviroment with [requirements.txt](requirements.txt) installed\n\n## dynamic\n\nCompiles C into an mpy file that can be loaded dynamically (without recompiling micropython)\n\nNB micropython dynruntime.mk has been altered as per here: https://forums.raspberrypi.com/viewtopic.php?f=146\u0026t=310282\u0026p=1856106#p1856106\n\n`armv7m` arch now targets `cortex-m0plus` cpu (previously `cortex-m3`)\n\nSee `py/dynruntime.h`\n\nIn the dynamic subdir, just do\n\n```sh\nmake\n```\n\nThe resulting mpy binary file can be uploaded to a device running micropython (e.g. using `rshell`) and imported like any other module:\n\n```txt\n$ rshell\nConnecting to /dev/ttyACM0 (buffer-size 512)...\nTrying to connect to REPL  connected\nRetrieving sysname ... rp2\nTesting if sys.stdin.buffer exists ... Y\nRetrieving root directories ... /echo.py/ /main.py/ /rainbow.py/ /thermometer.py/\nSetting time ... Apr 15, 2022 20:37:17\nEvaluating board_name ... pyboard\nRetrieving time epoch ... Jan 01, 1970\nWelcome to rshell. Use Control-D (or the exit command) to exit rshell.\n/mnt/data/dev/rpi-pico/pico-c-pymodules/dynamic\u003e cp string.mpy /pyboard\nCopying '/mnt/data/dev/rpi-pico/pico-c-pymodules/dynamic/string.mpy' to '/pyboard/string.mpy' ...\n/mnt/data/dev/rpi-pico/pico-c-pymodules/dynamic\u003e repl\nEntering REPL. Use Control-X to exit.\n\u003e\nMicroPython v1.18-329-g9d7c168bf-dirty on 2022-04-15; Raspberry Pi Pico with RP2040\nType \"help()\" for more information.\n\u003e\u003e\u003e\n\u003e\u003e\u003e import string\n\u003e\u003e\u003e string.reverse(\"reverse\")\n'esrever'\n\u003e\u003e\u003e\n```\n\nN.B. python source can be compiled to assembly using the `mpy-cross` cross-compiler, part of the micropython build, e.g:\n\n```sh\n../../micropython/mpy-cross/mpy-cross python/add.py\n```\n\nthen copy the resulting `.mpy` file to the device using (e.g.) `rshell` and import it in the usual way.\n\n```\n/mnt/data/dev/rpi-pico/pico-c-pymodules\u003e cp python/add.mpy /pyboard/\nCopying '/mnt/data/dev/rpi-pico/pico-c-pymodules/python/add.mpy' to '/pyboard/add.mpy' ...\n/mnt/data/dev/rpi-pico/pico-c-pymodules\u003e repl\nEntering REPL. Use Control-X to exit.\n\u003e\nMicroPython v1.18-329-g9d7c168bf-dirty on 2022-04-22; Raspberry Pi Pico with RP2040\nType \"help()\" for more information.\n\u003e\u003e\u003e\n\u003e\u003e\u003e import add\n\u003e\u003e\u003e add.add(2, 2)\n4\n\u003e\u003e\u003e\n```\n\n## static\n\nRequires recompilation of micropython. Supports C++. Based on micropython/examples/usercmodule.\n\nFrom the micropython repo root (adjust path as necessary):\n\n```sh\ncd ports/rp2/\ncmake -S . -B build-PICO -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pico-c-pymodules/static/micropython.cmake -DMICROPY_BOARD=PICO\ncmake --build build-PICO -j\n```\n\nCopy the micropython image onto the device, e.g.\n\n```sh\ncp build-PICO/firmware.uf2 /media/$USER/RPI-RP2/\n```\n\nThen\n\n```\n$ rshell\nConnecting to /dev/ttyACM0 (buffer-size 512)...\nTrying to connect to REPL  connected\nRetrieving sysname ... rp2\nTesting if sys.stdin.buffer exists ... Y\nRetrieving root directories ... /echo.py/ /main.py/ /rainbow.py/ /string.mpy/ /thermometer.py/\nSetting time ... Apr 15, 2022 20:58:31\nEvaluating board_name ... pyboard\nRetrieving time epoch ... Jan 01, 1970\nWelcome to rshell. Use Control-D (or the exit command) to exit rshell.\n/mnt/data/dev/rpi-pico/pico-c-pymodules\u003e repl\nEntering REPL. Use Control-X to exit.\n\u003e\nMicroPython v1.18-329-g9d7c168bf-dirty on 2022-04-15; Raspberry Pi Pico with RP2040\nType \"help()\" for more information.\n\u003e\u003e\u003e import usermodule\n\u003e\u003e\u003e usermodule.add(2, 2)\n(4, 'usermodule_cpp')\n\u003e\u003e\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgesmith%2Fpico-c-pymodules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirgesmith%2Fpico-c-pymodules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirgesmith%2Fpico-c-pymodules/lists"}