Working with Keil Toolchain to Convert my Custom Firmware to a .HEX File

embedded.jpg


For my ESC custom firmware, I finished testing every command and every edge case and ironed out all wrinkles in the code for that. Everything was working great and so now that my code file has ballooned to 3200 lines, I determined the next best thing to do is to retain a dummy command hard coded into the firmware for now and get the firmware tested on the ESC itself. The hard coded dummy command we left in there is [[Backward Nudge 5 5 5]]. That will validate and launch the backward nudge animation section which will launch the first commutation step, activating a commutation phase. I can then test the phase wires with a multimeter and verify the code is working on the ESC. Once that is verified then I'll feel comfortable to write the code that does the actual commutation. The single commutation step and verification that works is acting as my "blink" program to just verify signs of life on the ESC.

So once I had this plan in place, I went in and replaced all windows code written like /*-*/cout << with //-/count << and this served to comment it out since it won't work in the keil toolchain when converting the code to .hex for the ESC to run. I also replaced all code written like //-/IT01CF = 0x04; with /*---*/IT01CF = 0x04; and this served to uncomment out keil toolchain specific code while still leaving a distinct marker in front of it so that we can use the find and replace tool to swap it back to being commented out again later. In this way I was able to swap from windows dev mode to keil toolchain dev mode. Once that was done, I created a .bat file with chatgpt's help whose job was to create a .c file copy of my .cpp source file and then compile the .c file using the keil C51 compiler exe and then it ran the Keil BL51.exe linker to convert the compiled .OBJ file to a .ABS file (absolute object file) and then it ran OH51.exe to convert the .ABS file into a .hex file (Intel HEX). The .hex file can then be flashed onto the ESC.

During the compiling process there were errors and warnings and chatgpt helped me sort them all out quickly and after that no more errors and warnings were found. It all builds error and warning free. A single double click on the .bat file and we are making .hex file. That easy. So now all that remains is to do the steps to flash the code onto the ESC. For that I believe I'll need to connect USB to a arduino and connect a arduino to the ESC and then use blhelisuite to flash the .hex by way of the arduino over to the ESC. This process I have a vague idea on and I think it should work but we'll see. If not I'll flash it some other way or w/e.

Blog entry information

Author
Artbyrobot
Views
16
Last update

More entries in General

More entries from Artbyrobot

Share this entry

Top