Author Topic: How do I compile code to a hex file with SDCC  (Read 2252 times)

0 Members and 1 Guest are viewing this topic.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
How do I compile code to a hex file with SDCC
« on: March 11, 2023, 10:50:48 pm »
I have built a LED DIY clock and want to slightly modify some code on github and upload it to the clock controller chip.

The story so far is I have found some replacement firmware on github.   I have tried it but I want to modify it to lower the LED brightness.  I know what part of the code to change as the writer of the code explained what to change -->> https://github.com/zerog2k/stc_diyclock/issues/63 and I can do that.

What I do not know what to do is convert that to a hex file so I can upload it.   I have installed SDCC.  I can barely use the command prompt (windows 10) to get it to do stuff using other tutorials. 

But there are a heap of files in the github repository and I do not know what files I have to put into a folder for SDCC to turn into a working main.hex file

There are .c files and .h files and makerfile and .py and so on.  The tutorials I find online only seem to use one .c file to make a .hex.

https://github.com/zerog2k/stc_diyclock/find/master
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #1 on: March 11, 2023, 11:01:51 pm »
There is a Makefile, so just run 'make' in that directory and it would build you the hex file.
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #2 on: March 12, 2023, 01:44:50 am »
Thanks.   I got all the files off github.  Modified the file.  Saved it.   Moved all the files to a folder in the C: directory.

I then installed this MinGW package manager that apparently you need to run a makefile.

I try to run the file and cmd prompt says this

c:\diyclock>make
mkdir -p build/
The syntax of the command is incorrect.
Makefile:20: recipe for target 'build/adc.rel' failed
make: *** [build/adc.rel] Error 1
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #3 on: March 12, 2023, 02:48:05 am »
mkdir -p build/
Windows does not support "-p" argument. remove it, it should be fine. Or remove the whole call to mkdir and make "build" directory yourself.

Since this Makefile was not writnem to be cross-platforms, you may run into a few other issues like this.
« Last Edit: March 12, 2023, 02:49:47 am by ataradov »
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #4 on: March 12, 2023, 04:12:43 am »
OK, thanks again.   I removed that, but it just threw up another error.

It is way beyond my programming skill level which ends at;

10 print "This is my basic programming skillz"
20 goto 10
run
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #5 on: March 12, 2023, 04:14:59 am »
Well, if you show the error, it may be solved.
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #6 on: March 12, 2023, 04:47:53 am »
Well I thought I would start to be annoying as my skills are so limited.  I know the make program is working properly, as I was able to compile another file properly as a test.

Here is the error message

c:\diyclock>make
sdcc --code-size 4089 --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -Dstc15f204ea -o build/adc.rel -c src/adc.c
src/adc.c:49: error 257: Failed to open output file 'build/adc.asm' (No such file or directory)
Makefile:20: recipe for target 'build/adc.rel' failed
make: *** [build/adc.rel] Error 1

Running it with a debug, it throws up heaps of data, but the ending bit when it starts to error is

 Must remake target 'build/adc.rel'.
sdcc --code-size 4089 --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -Dstc15f204ea -o build/adc.rel -c src/adc.c
CreateProcess(C:\Program Files\SDCC\bin\sdcc.exe,sdcc --code-size 4089 --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -Dstc15f204ea -o build/adc.rel -c src/adc.c,...)
Putting child 02b4eb30 (build/adc.rel) PID 45416664 on the chain.
Live child 02b4eb30 (build/adc.rel) PID 45416664
Main thread handle = 0000015c
src/adc.c:49: error 257: Failed to open output file 'build/adc.asm' (No such file or directory)
Reaping losing child 02b4eb30 PID 45416664
Makefile:20: recipe for target 'build/adc.rel' failed
make: *** [build/adc.rel] Error 1
Removing child 02b4eb30 PID 45416664 from chain.
« Last Edit: March 12, 2023, 04:58:32 am by .RC. »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #7 on: March 12, 2023, 04:57:46 am »
Did you make "build" directory?

You either need to remove "-p" or the whole mkdir line, but in that case you need to manually do what it was supposed to do - create a directory.
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #8 on: March 12, 2023, 06:14:17 am »
I do not know how to make a build directory

If I delete -p.  It still throws up errors

c:\diyclock>make
sdcc -o build/ src/main.c --code-size 4089 --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -Dstc15f204ea -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY build/adc.rel build/ds1302.rel
?ASlink-Error-<cannot open> : "build/adc.rel"
Makefile:24: recipe for target 'main' failed
make: *** [main] Error 1

 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #9 on: March 12, 2023, 06:22:12 am »
Just create it in explorer in c:\diyclock.

This output looks like you deleted the whole compilation stage and linking fails because nothing was compiled.

To simplify this, use original Makefile, but replace "mkdir -p build/" with "mkdir build/". No other changes.
« Last Edit: March 12, 2023, 06:24:21 am by ataradov »
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #10 on: March 12, 2023, 06:55:55 am »
OK, I see what you mean.  You mean just a folder called build. That is easy enough. right click new folder, rename. 

The tutorial I watched on youtube put the output files into the folder where all the .c and .h files were.

OK, I made the Build folder.

I also did some googling and it was mentioned to put a minus sign before the mkdir.

I ran it and it threw a heap of files into the build directory. 19 in total.  Including a main.ihx file.   But no main.hex file.
I get an error

Makefile:24: recipe for target 'main' failed
make: *** [main] Error 255

I feel like I am close, but no cigar yet.
« Last Edit: March 12, 2023, 06:58:22 am by .RC. »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #11 on: March 12, 2023, 07:09:37 am »
You need to post full output. This final error is useless on its own.

Putting '-' in front of the command simply continues the run even if the command has failed, it is not helpful in this case.

But looking at the thing, you are likely missing 'tail' command in your system. Remove the lines starting with "@ tail". They just print size information, they are not needed for the build.

And it should have produces *.ihx file, which is the file you are looking for just under the different name. 'cp' does the rename, but since 'tail's failed, it sis not run. You can take that file and rename it yourself.  Edit: I see you have the ihx file. Use that, this is the file you need.
« Last Edit: March 12, 2023, 07:14:28 am by ataradov »
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #12 on: March 12, 2023, 07:22:39 am »
I removed the two @tail commands.
The error is still

c:\diyclock>make
sdcc -o build/ src/main.c --code-size 4089 --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -Dstc15f204ea -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY build/adc.rel build/ds1302.rel
cp build/main.ihx main.hex
process_begin: CreateProcess(NULL, cp build/main.ihx main.hex, ...) failed.
make (e=2): The system cannot find the file specified.
Makefile:24: recipe for target 'main' failed
make: *** [main] Error 2

I see the error seems to be line 24 or includes that line which I marked out below
It looks like this

main: $(OBJ)
   $(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $^            <--- line 24....
   @ tail -n 5 build/main.mem | head -n 2
   @ tail -n 1 build/main.mem
   cp build/$@.ihx $@.hex

So I changed it to this

main: $(OBJ)
   $(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $^
   cp build/$@.ihx $@.hex

And got the above error.
« Last Edit: March 12, 2023, 07:24:39 am by .RC. »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11263
  • Country: us
    • Personal site
Re: How do I compile code to a hex file with SDCC
« Reply #13 on: March 12, 2023, 07:26:06 am »
Windows may not have 'cp' either.

Just use the *.ihx file. Or rename "cp" to "copy", windows must have that.
« Last Edit: March 12, 2023, 07:27:59 am by ataradov »
Alex
 
The following users thanked this post: .RC.

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #14 on: March 12, 2023, 08:11:04 am »
Thanks so much.  I just changed main.ihx to main.hex.   Uploaded it to the stc ship and it worked.   The clock is now dim and suitable for use in a bedroom at night.

 

Offline .RC.Topic starter

  • Frequent Contributor
  • **
  • Posts: 257
  • Country: au
Re: How do I compile code to a hex file with SDCC
« Reply #15 on: March 12, 2023, 09:32:17 am »
I did some more playing around and googling and discovered a packihx part of SDCC

I did this from the cmd prompt with the files in their own folder.   I ended up with a main.hex file

c:\sdcc test>sdcc -c adc.c

c:\sdcc test>sdcc -c ds1302.c
ds1302.c:123: warning 158: overflow in implicit constant conversion

c:\sdcc test>sdcc main.c adc.rel ds1302.rel
main.c:448: warning 59: function 'add_BCD' must return value

c:\sdcc test>packihx main.ihx > main.hex
packihx: read 134 lines, wrote 251: OK.
 

Online HwAoRrDk

  • Super Contributor
  • ***
  • Posts: 1480
  • Country: gb
Re: How do I compile code to a hex file with SDCC
« Reply #16 on: March 12, 2023, 10:46:20 am »
I did some more playing around and googling and discovered a packihx part of SDCC

[...]

c:\sdcc test>packihx main.ihx > main.hex
packihx: read 134 lines, wrote 251: OK.

Using packihx here is really a redundant operation. The purpose of packihx is primarily to re-order the records in the file into ascending address order. You can see also that it outputs a different, shorter, record length than the input file - that's why the output file has roughly double the number of lines. The only real reason why you might need to use packihx is because whatever programmer you may be using to get the code onto the chip doesn't like non-contiguous addresses or requires a specific record length.

For you, if you just want a .hex filename extension, just rename the file! Otherwise, you're just starting with a hex file and ending with a hex file that to most purposes are functionally identical.
 
The following users thanked this post: .RC.


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf