{"id":14963414,"url":"https://github.com/cpq/mdk","last_synced_at":"2025-09-11T21:09:17.559Z","repository":{"id":43766965,"uuid":"372150891","full_name":"cpq/mdk","owner":"cpq","description":"A bare metal SDK for the ESP32 \u0026 ESP32C3","archived":false,"fork":false,"pushed_at":"2024-07-22T17:07:52.000Z","size":4352,"stargazers_count":237,"open_issues_count":5,"forks_count":33,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-05-19T22:08:55.252Z","etag":null,"topics":["bare-metal","baremetal","esp32","esp32c3","sdk"],"latest_commit_sha":null,"homepage":"","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/cpq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2021-05-30T07:28:06.000Z","updated_at":"2025-05-18T16:27:45.000Z","dependencies_parsed_at":"2024-09-13T19:14:49.930Z","dependency_job_id":"c5f6eaab-ab56-4b9e-9ae9-a8233e148382","html_url":"https://github.com/cpq/mdk","commit_stats":{"total_commits":169,"total_committers":5,"mean_commits":33.8,"dds":"0.035502958579881616","last_synced_commit":"e2c1d4e4bd9b152dfa32b48a7c0ae5f5a8b8276d"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cpq/mdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpq%2Fmdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpq%2Fmdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpq%2Fmdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpq%2Fmdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cpq","download_url":"https://codeload.github.com/cpq/mdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cpq%2Fmdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274705124,"owners_count":25334462,"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","status":"online","status_checked_at":"2025-09-11T02:00:13.660Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bare-metal","baremetal","esp32","esp32c3","sdk"],"created_at":"2024-09-24T13:31:28.376Z","updated_at":"2025-09-11T21:09:17.542Z","avatar_url":"https://github.com/cpq.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# A baremetal, single header ESP32/ESP32C3 SDK\n\nA bare metal, single header make-based SDK for the ESP32/ESP32C3 chips.\nWritten from scratch using datasheets ( [ESP32 C3\nTRM](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf),\n[ESP32\nTRM](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf)).\nIt is completely independent from the ESP-IDF and does not use any ESP-IDF\ntools or files. MDK implements its own flashing utility `esputil`, which is\ndeveloped in a separate repo. Esputil is\nwritten in C, with no dependencies on python or anything else, working on\nMac, Linux, and Windows as a static, singe no-dependencies executable.\n\nA screenshot below demonstrates a [examples/ws2812](examples/ws2812)\nRGB LED firmware flashed on a ESP32-C3-DevKitM-1 board. It takes \u003c 2 seconds\nfor a full firmware rebuild and flash:\n\n![](examples/ws2812/rainbow.gif)\n\nCurrently, \"esp32c3\" and \"esp32\" architectures are supported.\nMDK file structure is as follows:\n\n- $(ARCH)/[link.ld](esp32c3/link.ld) - a linker script file. ARCH is esp32 or esp32c3\n- $(ARCH)/[boot.c](esp32c3/boot.c) - a startup code \n- $(ARCH)/[mdk.h](esp32c3/mdk.h) - a single header that implements MDK API\n- $(ARCH)/[build.mk](esp32c3/build.mk) - a helper Makefile for building projects\n\n\n# Environment setup\n\n1. Use Linux or MacOS. Install Docker\n2. Execute the following shell commands (or add them to your `~/.profile`):\n  ```sh\n  $ export MDK=/path/to/mdk     # Points to MDK directory\n  $ export ARCH=esp32c3         # Valid choices: esp32 esp32c3\n  $ export PORT=/dev/ttyUSB0    # Serial port for flashing\n  ```\n\nVerify setup by building and flashing a blinky example firmware.\nFrom repository root, execute:\n\n```sh\n$ make -C examples/blinky clean build flash monitor\n```\n\n# Firmware Makefile\n\nFirmware Makefile should look like this (see [examples/blinky/Makefile](examples/blinky/Makefile)):\n\n```make\nSOURCES = main.c another_file.c\n\nEXTRA_CFLAGS ?=\nEXTRA_LINKFLAGS ?=\n\ninclude $(MDK)/$(ARCH)/build.mk\n```\n\n# Environment reference\n\n- **Environment / Makefile variables:**\n  - `ARCH` - Architecture. Possible values: esp32c3, esp32\n  - `TOOLCHAIN` - Crosscompiler prefix. riscv64-unknown-elf or xtensa-esp32-elf\n  - `PORT` - Serial port for flashing. Default: /dev/ttyUSB0\n  - `FLASH_PARAMS` - Flash parameters, see below. Default: empty\n  - `FLASH_SPI` - Flash SPI settings, see below. Default: empty\n  - `EXTRA_CFLAGS` - Extra compiler flags. Default: empty\n  - `EXTRA_LINKFLAGS` - Extra linker flags. Default: empty\n- **Makefile targets:**\n  - `make clean` - Clean up build artifacts\n  - `make build` - Build firmware in a project directory\n  - `make flash` - Flash firmware. Needs PORT variable set\n  - `make monitor` - Run serial monitor. Needs PORT variable set\n- **Board defaults:** - overridable by e.g. `EXTRA_CFLAGS=\"-DLED1=3\"`\n  - `LED1` - User LED pin. Default: 2\n  - `BTN1` - User button pin. Default: 9\n\n\n# API reference\n\nCurrently, a limited API is implemented. The plan is to implement WiFi/BLE\nprimitives in order to integrate [cesanta/mongoose](https://github.com/cesanta/mongoose)\nnetworking library. Unfortunately radio registers are not documented\nby Espressif - please [contact us](https://mongoose.ws/contact/) if\nyou have more information on that.\n\n- GPIO\n  - `void gpio_output(int pin);` - set pin mode to OUTPUT\n  - `void gpio_input(int pin);` - set pin mode to INPUT\n  - `void gpio_write(int pin, bool value);` - set pin to low (false) or high\n  - `void gpio_toggle(int pin);` - toggle pin value\n  - `bool gpio_read(int pin);` - read pin value\n- SPI\n  - `struct spi { int miso, mosi, clk, cs; };` - an SPI descriptor\n  - `bool spi_init(struct spi *spi);` - initialise SPI\n  - `void spi_begin(struct spi *spi, int cs);` - start SPI transaction\n  - `void spi_end(struct spi *spi, int cs);` - end SPI transaction\n  - `uin8_t spi_txn(struct spi *spi, uint8_t);` - do SPI transaction: write one byte, read response\n- UART \n  - `void uart_init(int no, int tx, int rx, int baud);` - initialise UART\n  - `bool uart_read(int no, uint8_t *c);` - read byte. Return true on success\n  - `void uart_write(int no, uint8_t c);` - write byte. Block if FIFO is full\n- Misc\n  - `void wdt_disable(void);` - disable watchdog\n  - `uint64_t uptime_us(void);` - return uptime in microseconds\n  - `void delay_us(unsigned long us);` - block for \"us\" microseconds\n  - `void delay_ms(unsigned long ms);` - block for \"ms\" milliseconds\n  - `void spin(unsigned long count);` - execute \"count\" no-op instructions\n\n\n# Toolchain Docker images\n\nBy default, docker is used for builds. For `ARCH=esp32`, the `espressif/idf`\nimage is used. For `ARCH=esp32c3`, the `mdashnet/riscv` image is used,\nwhich is built using the following Dockerfile:\n\n```Dockerfile\nFROM alpine:edge\nRUN apk add --update build-base gcc-riscv-none-elf newlib-riscv-none-elf \u0026\u0026 rm -rf /var/cache/apk/*\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpq%2Fmdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcpq%2Fmdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcpq%2Fmdk/lists"}