Modify and compile a program

Introduction and miscellaneous that we haven't created categories for, yet
Post Reply
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Modify and compile a program

Post by muehlpower »

Maybe I'm the only one here who doesn't get it, but how do I modify a program and compile it? I installed the toolchain and downloaded the latest zip file from git. Now I have a new folder in Programs (x86) and a zip file with lots of subfolders. How do I modify the program and how do I get a bin or hex file that I can then transfer?
User avatar
manny
Posts: 164
Joined: Sun Jan 23, 2022 4:15 pm
Location: Netherlands
Has thanked: 38 times
Been thanked: 125 times

Re: Modify and compile a program

Post by manny »

You can modify the code with you favorite text editor.
The files are in the src folder

On windows I use WSL linux command line for windows to compile the firmware. With the Make command.
[DRIVING] Citroen Saxo electrique
  • Volvo ERAD motor, XC90 inverter/DCDC (custom OI board)
  • PSA battery (50kWh)
  • Foccci and MG ZS charger 6.6kW
  • Zombie VCU
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

manny wrote: Sat Oct 25, 2025 10:29 am favorite test editor
Which editor is suitable? Normally, I start the Arduino IDE, type in the program, and then press upload. I can view the relevant program section with the Windows editor and also change it, but without checking the syntax.

What is “WSL Linux command line for Windows”? I can type “cmd” in the bottom left corner of my Windows screen, and then something that looks like DOS appears.
User avatar
tom91
Posts: 2753
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 264 times
Been thanked: 717 times

Re: Modify and compile a program

Post by tom91 »

muehlpower wrote: Sat Oct 25, 2025 9:59 am a program and compile it?
Uhmm thanks for the clarity on what you are on about. Please be more specific.

You can search the forum for threads on compling. search.php?st=0&sk=t&sd=d&sr=posts&keywords=compile

viewtopic.php?p=76553&hilit=compile#p76553
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

Johu recommends in another thread: “Install the latest version of stm32-sine, which you can find on Git, i.e., compile it yourself. It fixes various CAN issues compared to 5.35.R.” 5.35.R is the latest version I can download as a binary file.

On Git, it says to install “arm-none-eabi toolchain.” I did that. I also downloaded “stm32-sine-master.zip.”

The question now is how do I use the toolchain to create the “stm32_sine.bin” file from the “stm32-sine-master.zip” and what can I use to make additional changes to the source code?
User avatar
tom91
Posts: 2753
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 264 times
Been thanked: 717 times

Re: Modify and compile a program

Post by tom91 »

Depends on your preference.

I use Docker and this https://github.com/crasbe/ZombieBuild can be adapted to work for any OI software repo.

For writing code I use Code Blocks.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

I have now installed Code Blocks. It looks good. It found a GNU when it started, which I think is good. Then I opened stm32_sine.cpp and clicked on “build.” I got this error message: "C:\compile test\stm32-sine-5.35.R\src\stm32_sine. cpp|22|fatal error: libopencm3/stm32/usart.h: No such file or directory|||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|"

Johu writes on Git: “The only external dependency is libopencm3, which I forked.”
What does that mean and how should I proceed?
User avatar
manny
Posts: 164
Joined: Sun Jan 23, 2022 4:15 pm
Location: Netherlands
Has thanked: 38 times
Been thanked: 125 times

Re: Modify and compile a program

Post by manny »

muehlpower wrote: Sat Oct 25, 2025 12:36 pm Johu recommends in another thread: “Install the latest version of stm32-sine, which you can find on Git, i.e., compile it yourself. It fixes various CAN issues compared to 5.35.R.” 5.35.R is the latest version I can download as a binary file.
If you want the latest software. You can download it from github. You need to be logged in to github. got to https://github.com/jsphuebner/stm32-sine/actions

And select the the latest commit of the branche you want. Scroll down to Artifacts and select the FOC or SINE file.

muehlpower wrote: Sat Oct 25, 2025 11:10 am Which editor is suitable?
Visual Studio Code is a good option
muehlpower wrote: Sat Oct 25, 2025 11:10 am What is “WSL Linux command line for Windows”? I can type “cmd” in the bottom left corner of my Windows screen, and then something that looks like DOS appears.

WSL is similar to cmd but its linux on windows.
[DRIVING] Citroen Saxo electrique
  • Volvo ERAD motor, XC90 inverter/DCDC (custom OI board)
  • PSA battery (50kWh)
  • Foccci and MG ZS charger 6.6kW
  • Zombie VCU
User avatar
tom91
Posts: 2753
Joined: Fri Mar 01, 2019 9:15 pm
Location: Bristol
Has thanked: 264 times
Been thanked: 717 times

Re: Modify and compile a program

Post by tom91 »

muehlpower wrote: Sat Oct 25, 2025 1:35 pm What does that mean and how should I proceed?
tom91 wrote: Sat Oct 25, 2025 12:58 pm I use Docker and this https://github.com/crasbe/ZombieBuild can be adapted to work for any OI software repo.
On windows I would strongly recommend using ZombieBuild and docker to compile. Code Blocks is not used to compile.
Creator of SimpBMS
Founder Volt Influx https://www.voltinflux.com/
Webstore: https://citini.com/
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

manny wrote: Sat Oct 25, 2025 1:42 pm Scroll down to Artifacts and select the FOC or SINE file
Now I see that. Where is the bin file?
Attachments
111.png
User avatar
manny
Posts: 164
Joined: Sun Jan 23, 2022 4:15 pm
Location: Netherlands
Has thanked: 38 times
Been thanked: 125 times

Re: Modify and compile a program

Post by manny »

Sorry did not see that they are expired. Maybe johu can redo the copile or change the expire settings?
[DRIVING] Citroen Saxo electrique
  • Volvo ERAD motor, XC90 inverter/DCDC (custom OI board)
  • PSA battery (50kWh)
  • Foccci and MG ZS charger 6.6kW
  • Zombie VCU
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

I think I now have Debian Linux, WSL2, Code Blocks, the arm-none-eabi toolchain, Docker and Windows Terminal installed. And I have downloaded the ZombieBuild-main.zip, stm32-sine-master.zip and libopencm3-5ba1bb5f8b0287a0ccec9def20f3a6185c3a2a8e files.

How do I turn all of this into a bin or hex file that I can then load onto my LDU board using ST-Link?
User avatar
manny
Posts: 164
Joined: Sun Jan 23, 2022 4:15 pm
Location: Netherlands
Has thanked: 38 times
Been thanked: 125 times

Re: Modify and compile a program

Post by manny »

In the command line go to the Stm32-sine directory and execute the commands on the guthub.

https://github.com/jsphuebner/stm32-sin ... #compiling

Good luck
[DRIVING] Citroen Saxo electrique
  • Volvo ERAD motor, XC90 inverter/DCDC (custom OI board)
  • PSA battery (50kWh)
  • Foccci and MG ZS charger 6.6kW
  • Zombie VCU
User avatar
uhi22
Posts: 1143
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 231 times
Been thanked: 638 times

Re: Modify and compile a program

Post by uhi22 »

Another way, which was straight forward (for me):
- I forked the repository to my github account. https://github.com/uhi22/stm32-sine
- Have git installed on my windows 10 machine.
- Open a git bash
- clone the repository to my machine: git clone https://github.com/uhi22/stm32-sine
- change into the new directory: cd stm32-sine
- using a text editor (I prefer Notepad++), change in the file param_prj.h the VERSION number
- back in the git bash, check the differences (git status) (git diff), stage them (git add .), commit them (git commit -m "changed version") and finally push them to the github server (git push)
- On github, the continuous integration is enabled, which means, that github itself will build every change directly, and provide the binary files (bin and hex) in the "actions" tab: https://github.com/uhi22/stm32-sine/actions

Pro:
- No need to install the tool chain for building.
- The changes and the binaries are accessable by everybody for "community testing"
Contra:
- Needs a github account
- Pushing un-tested software to github is a bad habbit. So only recommended for very small changes.


Alternatively made a local build. On windows 10. Precondition: git installed.
- Have git installed on my windows 10 machine.
- Open a git bash
- clone the repository to my machine: git clone https://github.com/jsphuebner/stm32-sine
- change into the new directory: cd stm32-sine
- using a text editor (I prefer Notepad++), change in the file param_prj.h the VERSION number or whatever else
- back in the bit bash, follow the compile commands described here: https://github.com/jsphuebner/stm32-sine#compiling with the difference, that on my windows the "make" does not work, instead I have to use mingw32-make.
- mingw32-make get-deps
-> this takes two minutes to compile a lot of library stuff
- mingw32-make
-> compiles and links the project:
OBJCOPY stm32_sine.bin
OBJCOPY stm32_sine.hex
text data bss dec hex filename
50988 4596 928 56512 dcc0 stm32_sine
User avatar
uhi22
Posts: 1143
Joined: Mon Mar 14, 2022 3:20 pm
Location: Ingolstadt/Germany
Has thanked: 231 times
Been thanked: 638 times

Re: Modify and compile a program

Post by uhi22 »

muehlpower wrote: Sat Oct 25, 2025 7:36 pm I think I now have Debian Linux, WSL2, Code Blocks, the arm-none-eabi toolchain, Docker and Windows Terminal installed. And I have downloaded the ZombieBuild-main.zip, stm32-sine-master.zip and libopencm3-5ba1bb5f8b0287a0ccec9def20f3a6185c3a2a8e files.

How do I turn all of this into a bin or hex file that I can then load onto my LDU board using ST-Link?
- 1. Find out how to open a command line ("shell").
- 2. In the shell navigate into your stm32-sine directory (that you have extracted from zip, or got using the git clone command). Something like cd ~/downloads/stm32-sine
- 3. make get-deps
- 4. make

I'm not sure whether it works to put the stm32-sine-master.zip and the libopencm3...zip together somehow. I prefer getting the data from github not using the zip, but using the command "git clone".
User avatar
johu
Site Admin
Posts: 6968
Joined: Thu Nov 08, 2018 10:52 pm
Location: Kassel/Germany
Has thanked: 454 times
Been thanked: 1771 times
Contact:

Re: Modify and compile a program

Post by johu »

I think it may not work with downloaded zip as the git submodule command will likely fail.

So use clone instead
Support R/D and forum on Patreon: https://patreon.com/openinverter - Subscribe on odysee: https://odysee.com/@openinverter:9
davefiddes
Posts: 375
Joined: Mon Jan 18, 2021 12:39 pm
Location: Edinburgh, Scotland, UK
Has thanked: 149 times
Been thanked: 195 times

Re: Modify and compile a program

Post by davefiddes »

Yep. The GitHub releases source tarballs don't build because they are missing the submodules. I have added code to create working standalone source tarballs for the stm32-sine M3_DU project: https://github.com/davefiddes/stm32-sin ... 55C2-L73C1

If you just want binaries of a up to date stm32-sine then the release I put together here: https://github.com/davefiddes/stm32-sin ... DU_v5.39.0 might be of interest. It has the most recent CAN fixes and has been tested on the M3_DU. No testing on other boards but it *should* be OK.
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

Ubuntu is installed, make and git are running. “make get-deps” produces an error message.
Attachments
make_get-deps.png
davefiddes
Posts: 375
Joined: Mon Jan 18, 2021 12:39 pm
Location: Edinburgh, Scotland, UK
Has thanked: 149 times
Been thanked: 195 times

Re: Modify and compile a program

Post by davefiddes »

make get-deps will not work on the unzipped source. You need to "git clone https://github.com/jsphuebner/stm32-sine.git"
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

I have now created a local copy using git clone, and the result looks exactly like the unzipped version of the downloaded master zip file. Is there a difference?
Attachments
clone.png
davefiddes
Posts: 375
Joined: Mon Jan 18, 2021 12:39 pm
Location: Edinburgh, Scotland, UK
Has thanked: 149 times
Been thanked: 195 times

Re: Modify and compile a program

Post by davefiddes »

The "git clone" will have created a special ".git" folder which is not present in the zip file. You should be able to run "make get-deps" now which will fetch and build libopencm3 and libopeninv which the project needs.
User avatar
muehlpower
Posts: 750
Joined: Fri Oct 11, 2019 10:51 am
Location: Germany Fürstenfeldbruck
Has thanked: 17 times
Been thanked: 168 times

Re: Modify and compile a program

Post by muehlpower »

davefiddes wrote: Tue Oct 28, 2025 4:38 pm created a special ".git" folder
You're absolutely right, I didn't see that. “make get-deps” worked, and so did “make.” So the newly created hex and bin files should be the ones I can load onto my board? I've only changed the version number for now and will test whether it's correct after loading.
What does the warning mean?
Attachments
binhex.png
davefiddes
Posts: 375
Joined: Mon Jan 18, 2021 12:39 pm
Location: Edinburgh, Scotland, UK
Has thanked: 149 times
Been thanked: 195 times

Re: Modify and compile a program

Post by davefiddes »

Yep. You can take the bin file and upload it via the web interface or CAN as you would with an official release. The stm32_sin file (without an extension) is what you need for debugging.

The warning can be safely ignored. It's a compiler bug(ish) cause by some slightly convoluted code in libopeninv. Newer compilers like gcc 15.1 don't complain.
Post Reply