{"id":37352577,"url":"https://github.com/itzandroidtab/klib","last_synced_at":"2026-01-16T04:04:43.044Z","repository":{"id":40503147,"uuid":"474752032","full_name":"itzandroidtab/klib","owner":"itzandroidtab","description":"Embedded hardware (arm cortex) library to use with cmake and (arm-none-eabi-)gcc","archived":false,"fork":false,"pushed_at":"2025-12-31T18:37:24.000Z","size":1433,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-04T04:10:01.288Z","etag":null,"topics":["klib","microcontroller"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itzandroidtab.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-03-27T20:29:46.000Z","updated_at":"2025-12-31T18:37:27.000Z","dependencies_parsed_at":"2023-10-21T16:39:35.730Z","dependency_job_id":"790d6180-dc43-428d-a611-6e67f69418d1","html_url":"https://github.com/itzandroidtab/klib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/itzandroidtab/klib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzandroidtab%2Fklib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzandroidtab%2Fklib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzandroidtab%2Fklib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzandroidtab%2Fklib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itzandroidtab","download_url":"https://codeload.github.com/itzandroidtab/klib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itzandroidtab%2Fklib/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["klib","microcontroller"],"created_at":"2026-01-16T04:04:42.968Z","updated_at":"2026-01-16T04:04:43.028Z","avatar_url":"https://github.com/itzandroidtab.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ cortex-m hardware library\n\n![klib library](https://github.com/itzandroidtab/klib/actions/workflows/build.yml/badge.svg)\n\nKlib uses `cmake` and `arm-none-eabi-gcc` to build excecutables for cortex targets. Currently supported targets can be found in the [target folder](./targets/).\n\nSupport for devices varies. Currently some targets have a startup file that can be enabled by uncommenting line 6 in the project CMakeLists ([project/CMakeLists.txt](./project/CMakeLists.txt#L6)). This means by default the coprocessors are not enabled and the cpu clock may not be initialized to the full clock speed.\n\n---\n\n## Starting your first project\n\nThe easiest way to start a your first project is using Github codespaces. Github codespaces will download all the required programs and will generate the required [header files](https://github.com/itzandroidtab/klib-svd) for all supported microcontrollers. If you want to create a project on your own machine the header files need to be generated manually (this can be done using the CMSIS 'svdconv' utility). The header files should be placed in the targets/chip/target folder with the same name as the target folder. Another way to get the header files is to start a github codespace and download the required headers when it is done converting all the svd files to headers.\n\nFor example the svd files for the LPC1756 can be generated using:\n```bash\nsvdconv.exe lpc1756.svd --generate=header\n```\nThe output of the svdconv utility needs to be moved to: `targets/chip/lpc1756/lpc1756.h`\n\n### Selecting target cpu\nTo select a target cpu the target cpu needs to be added to the commandline when configuring cmake. \n\n(e.g. To configure cmake for the max32660, run the following command)\n```sh\ncmake -B ./build -DTARGET_CPU=max32660\n```\nThis configures the project for the specific target cpu. To change to a different target, the project has to be reconfigured.\n\n#### Setup VSCode\n(When using vscode with the cmake plugin the following can be added to the `settings.json` to configure cmake for the max32660 evsys board)\n```json\n{\n    // target cpu, should be the same as in the cmake \n    // define this is used in the c_cpp_properties.json \n    // for intellisense\n    \"target_cpu\": \"atsam4s2b\",\n\n    // target cpu to use when using launch.json\n    // note: this might be different from the define. \n    // for example the \"atsam4s2b\" does not exist in\n    // the j-link software and requires us to use \n    // \"atsam4s2ba\" instead. To find the correct name\n    // open j-link and search for your chip\n    \"target_cpu_debug\": \"atsam4s2ba\",\n    \"cmake.configureSettings\": {\n        \"TARGET_CPU\": \"atsam4s2b\",\n        \"TARGET_LOW_POWER_SLEEP\": \"1\",\n        \"TARGET_BREAK_AT_RESERVED_HANDLER\": \"1\"\n    },\n    \"C_Cpp.default.configurationProvider\": \"ms-vscode.cmake-tools\",\n}\n```\n\n### Main file\nBy default klib has no `main.cpp` file. This has to be created by the user. To use the klib target system `klib.hpp` needs to be included. \n\nMinimal main file:\n```cpp\n#include \u003cklib/klib.hpp\u003e\n\nint main() {\n    return 0;\n}\n```\n\n### Examples\nAnother way to start a project is using one of the following examples:\n\n[2 factor authenticator dongle](https://github.com/itzandroidtab/totp)\n\n[mouse jiggler](https://github.com/itzandroidtab/mouse_jiggler)\n\n### Constructors before running main\nC++ supports global constructors for objects. These objects will be constructed before main is executed. This is supported by klib. If you want to initialize hardware before these global constructors are called you need to add the attribute `__attribute__((__constructor__(x)))` to your function definition where x is a number above 102 (the first 100 are reserved by gcc, 101 is reserved for startup code by klib and 102 is reserved for a secondary startup code by klib). This will make sure your function will be executed before any constructor is called.\n\n---\n\n## Using klib\nKlib has most library functions documented using doxygen (there is no config file). Please refrence the doxygen/doxywizzard documentation to generate the documentation. \n\n### Interrupt handling\nBy design klib has a default vector table that should not be changed. Instead one of the 3 vector table implementations should be used. \n\nKlib has the following implementations:\n* Ram based vector table (used by default)\n* Ram based vector table with entry and exit hooks (uses more ram and flash than the default implementation)\n* Flash/custom vector table (allows a vector table stored in flash or for a custom ram based implementation)\n\nWhen chosing one of the ram based vector table implementations all the code works by default as this allows the code to change the interrupt at runtime. When chosing the flash/custom vector table the user needs to create the vector table and pass it to the flash based vector table implementation. With this implementation the interrupts are not configured automaticly when needed and need to be changed by the user to the correct callback/handler. For more information about the different implementations see [irq.hpp](./klib/irq.hpp) as a reference.\n\n## Tests\nKlib has tests for the microcontroller indepented code. The resuls of the tests can be found [here](https://github.com/itzandroidtab/klib-x86/actions)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzandroidtab%2Fklib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitzandroidtab%2Fklib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitzandroidtab%2Fklib/lists"}