Page 1 of 1

Modify and compile a program

Posted: Sat Oct 25, 2025 9:59 am
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?

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 10:29 am
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.

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 11:10 am
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.

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 11:24 am
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

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 12:36 pm
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?

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 12:58 pm
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.

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 1:35 pm
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?

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 1:42 pm
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.

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 2:14 pm
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.

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 2:35 pm
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?

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 2:59 pm
by manny
Sorry did not see that they are expired. Maybe johu can redo the copile or change the expire settings?

Re: Modify and compile a program

Posted: Sat Oct 25, 2025 7:36 pm
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?

Re: Modify and compile a program

Posted: Sun Oct 26, 2025 9:45 am
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

Re: Modify and compile a program

Posted: Mon Oct 27, 2025 9:04 pm
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

Re: Modify and compile a program

Posted: Mon Oct 27, 2025 9:31 pm
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".

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 3:12 am
by johu
I think it may not work with downloaded zip as the git submodule command will likely fail.

So use clone instead

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 1:04 pm
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.

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 1:09 pm
by muehlpower
Ubuntu is installed, make and git are running. “make get-deps” produces an error message.

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 1:54 pm
by davefiddes
make get-deps will not work on the unzipped source. You need to "git clone https://github.com/jsphuebner/stm32-sine.git"

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 3:23 pm
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?

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 4:38 pm
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.

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 6:35 pm
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?

Re: Modify and compile a program

Posted: Tue Oct 28, 2025 7:16 pm
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.