{"id":21442261,"url":"https://github.com/thotypous/mikrostm-link","last_synced_at":"2025-10-10T03:32:12.014Z","repository":{"id":69726819,"uuid":"13561991","full_name":"thotypous/mikrostm-link","owner":"thotypous","description":"Link together gcc and mikroC projects for STM32","archived":false,"fork":false,"pushed_at":"2013-10-14T14:42:53.000Z","size":208,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T10:43:26.052Z","etag":null,"topics":["gcc","linker","microcontroller","mikroc"],"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/thotypous.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}},"created_at":"2013-10-14T13:28:47.000Z","updated_at":"2017-02-19T15:58:15.000Z","dependencies_parsed_at":"2023-02-23T02:30:16.019Z","dependency_job_id":null,"html_url":"https://github.com/thotypous/mikrostm-link","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thotypous%2Fmikrostm-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thotypous%2Fmikrostm-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thotypous%2Fmikrostm-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thotypous%2Fmikrostm-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thotypous","download_url":"https://codeload.github.com/thotypous/mikrostm-link/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243955722,"owners_count":20374372,"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":["gcc","linker","microcontroller","mikroc"],"created_at":"2024-11-23T01:53:15.436Z","updated_at":"2025-10-10T03:32:06.975Z","avatar_url":"https://github.com/thotypous.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"mikrostm-link\n=============\n\nLink together gcc and mikroC projects for STM32\n\n\nWhy?\n----\n\nThis code was originally developed because I had to quickly deploy a project which I was not able to build using mikroC PRO for ARM. However, other parts of the project used hardware libraries provided by mikroC. I did not have the time to rewrite those libraries, and thus could not deploy the project using only gcc. Therefore, the solution was to create a kind of a linker to put together both projects.\n\n\nRunning the example\n-------------------\n\nThe example is meant for a **STM32F407VG** microcontroller, for example the one present in the **mikromedia for STM32** board.\n\n1. Install a bare metal ARM toolchain. [Build](https://github.com/vedderb/summon-arm-toolchain) your own or download a [prebuilt](https://launchpad.net/gcc-arm-embedded) toolchain.\n2. Install [libopencm3](http://libopencm3.org/wiki/Downloads).\n3. Clone this repository.\n4. Go to the `example/example-gcc` directory, and create a symbolic link to the libopencm3 directory. For example: `cd mikrostm-link/example/example-gcc \u0026\u0026 ln -s /home/user/codes/libopencm3 .`\n5. Go back to the `example` directory, and run `make`.\n6. Program your board with the generated `example.hex` file using [mikroe-uhb](https://github.com/thotypous/mikroe-uhb) or another programmer.\n\n\nWhat about other microcontrollers?\n----------------------------------\n\nOther STM32 devices should be straightforward to support. Just modify `FLASH_SIZE` and `RAM_SIZE` in the first lines of the `mikrostm-link` file. Also, remember to modify `Makefile.include` and the ld script of the gcc project accordingly.\n\nOther microcontrollers should be doable to support, but I did not care much about code extensibility. This was just a quick hack!\n\n\nHow do I create my own project?\n-------------------------------\n\nThis is a quick guide on how to create a pair of projects which can be linked together. Please use the example for further reference.\n\n### mikroC project\n\n* Declare the functions which you want to import from the gcc project as function pointers. For example:\n\n```C\nvoid (*const reset_handler)(void) = 0xdeadbeef;\nvoid (*const my_function)(void) = 0xdeadbeef;\n```\n\nThe functions can point to any address. The addresses will be modified later by mikrostm-link directly in the generated .hex file.\n\n* The `reset_handler` function is always needed. It is already implemented for you, and its purpose is to call any required initialization code. You need to call this function from you mikroC project before calling any other function imported from the gcc project.\n\n* You need to force the mikroC linker to include in its output the functions which you want to export to gcc. If the functions are not used in other parts of your mikroC project code, you can easily do this by inserting a dead code section inside your `main` function:\n\n```C\n\tif(0) {\n\t\t// functions imported by gcc\n\t\tasm {\n\t\t\tBL _HID_Read;\n\t\t\tBL _HID_Write;\n\t\t};\n\t}\n```\n\n* Please build your mikroC project *before* calling mikrostm-link. This is needed because mikrostm-link was originally designed to be used in a Linux system, with mikroC running inside a Windows VM.\n\n### gcc project\n\n* Use our `Makefile` as a template. Modify it to build objects for each source file of you project. Keep the `reset_handler.c` file intact and always list its `reset_handler.o` object in the `Makefile`.\n\n* Create an `imports.h` file containing a **constant** pointer to each function and to each variable which you want to import from the mikroC project. For example:\n\n```C\nstatic char (*const HID_Read)(void);\nstatic unsigned char *const readbuff;\n```\n\nThis file will be modified by mikrostm-linker each time it runs, in order to initialize the pointers with their correct addresses.\n\n* Create an `exports.ld` file containing an `EXTERN` declaration for each function you want to export to the mikroC project. For example:\n\n```\nEXTERN (do_calculation)\n```\n\n\nHow does it work?\n-----------------\n\nWhen you run mikrostm-link, it:\n\n1. Reads symbol positions from the `*.lst` file generated by the mikroC compiler.\n2. Creates a `memory_map.ld` file which instructs ld to link the gcc project only after the memory already being used by the mikroC project.\n3. Modifies the `imports.h` file, inserting the correct addresses.\n4. Runs `make` in the gcc project directory.\n5. Glues together the `.hex` files generated by mikroC and by gcc, and replaces pointers to functions imported by mikroC with the correct addresses.\n\n\nWhich version of the compilers did you try?\n-------------------------------------------\n* Linaro GCC 4.8-2013.07-1\n* mikroC PRO for ARM version 3.3.1.0\n* mikroC PRO for ARM version 4.0.0.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthotypous%2Fmikrostm-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthotypous%2Fmikrostm-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthotypous%2Fmikrostm-link/lists"}