I tried to write a blinking LED program on Megawin MG82F6D17
microcontroller. All the source files compile fine. However there are
problems in linking and the ihx files are not created. I am attaching all
the source files and makefile (all kept in the same directory for now).
Am I providing incorrect linker options? Request help in getting
this fixed, so that it can form the prototype for further development
on the Megawin microcontrollers.
I am new to SDCC and so I may be making an error in specifying
linker / compiler options.
Did you get any error message?
Thanks for your prompt reply.
After running makefile, I get the following messages on the
console.
$ make
sdcc -c main.c -I. --model-large
sdcc -c MG82F6D17_IAP_DRV.c -I. --model-large
sdcc -c MG82F6D17_COMMON_DRV.c -I. --model-large
sdcc -c MG82F6D17_INTERRUPT.c -I. --model-large
sdcc -c MG82F6D17_WIZARD.c -I. --model-large
sdcc main.rel MG82F6D17_IAP_DRV.rel MG82F6D17_COMMON_DRV.rel \
MG82F6D17_INTERRUPT.rel MG82F6D17_WIZARD.rel --xram-loc 0x00 --xram-size 0x2FF --data-loc 0x30 --code-size 0x3FFF "-Wl,-bBSEG=0x20" --model-large
?ASlink-Error-<cannot open=""> : "main.ihx"
make: *** [makefile:19: main.ihx] Error 1</cannot>
I'd start by fixing the sfr definitions. SDCC does not support the Keil way of specifiying them.
It's probably best if you use the macros from our #include <compiler.h>
So change
__sfr SP = 0x81;to
SFR(SP, 0x81)etc.
Feel free to upload the new register definitions include file to our patch tracker, but also to the origin of REG_MG82F6D17.h. You may also send compiler.h alongside.</compiler.h>
The source of the startup files (meant for Keil compiler ; runs fine with Keil)
is Megawin website.
http://www.megawin.com.tw/en-global/support/index/72/194
So REG_MG82F6D17.h (and the other files) was originally from
Megawin supplied source code for LED blink program (but for Keil
compiler).
I made all the changes necessary from the Keil version (available
from their website) to the recommendations made in SDCC manual
about sfr, asm, etc. So each of the files in the zip file I attached are
changed files (by myself). They also give no compilation errors after
all those changes made. In the manual it mentions changing _sfr to
__sfr (two leading underscore) for example.
Megawin folks did not respond to our request to provide SDCC
compatible codes, and so we started to make the changes ourselves.
These 8051 microcontrollers seem pretty feature packed and also
attractively priced. Hence our aim to make them suitable for use
by SDCC users.
I will try making the changes you indicated and get back on the
forum.
The SDCC developers think that
sfr SP = 0x81is an assignment of the value 0x81 to SP, not defining its address. That is why SDCC uses__at (0x81)to specify an address. This is abstracted incompiler.hmacros to support many different compilers from a single header file. It would be wise for Megawin to use this abstraction so they can easily support multiple compilers with a single file.Hi Maarten,
Your recommendations were spot on. I made the changes to sfr address specification as suggested and got SDCC to compile and link the files as intended. I am attaching the working code for the blinking LED in this post. This tests only the GPIO functions for now, and minor changes may be required to make the other modules to work. I will upload them later, as and when they get tested. For now the main.c along with the 'driver' files provided by Megawin (and modified for use with SDCC) is a working template for LED blinking program.
Thanks for your help, and hope this will allow others to get started on Megawin microcontrollers. I also intend to upload any support libraries I create for Megawin, and suitable for use with SDCC (or other compilers).
I see you only used the SFR() macro.
I strongly recommend to also use the SBIT() macro.
Further, you should also define an alias named
__XPAGEforXRPSso SDCC can properly initialize variables in xdata. See the manual.You cannot use
nop()from TYPEDEF.h, use NOP from compiler.h instead.There is a bug in TYPEDEF.h which checks
#ifdef uint8which should checkuint8_tinstead. But IMHO it's better to use C99 standard#include <stdint.h>though Keil probably doesn't come with that header file.Also note that all struct/union typedefs in TYPEDEF.h are for big-endian Keil , where SDCC is little-endian.
Thanks, will use your inputs on updating the code further (SBIT macro, etc) and upload them on the forum. Thanks so much for your expertise.
In the meantime, here is the earlier 'working' code which is organized in directories and compiled with the makefile provided.