Menu

#158 Help with porting from Keil to SDCC for Megawin microcontrollers

open
nobody
5
2022-06-13
2022-05-26
Dipankar
No

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.

1 Attachments

Discussion

  • Maarten Brock

    Maarten Brock - 2022-05-27

    Did you get any error message?

     
  • Dipankar

    Dipankar - 2022-05-27

    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>

     
    • Maarten Brock

      Maarten Brock - 2022-05-27

      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>

       
  • Dipankar

    Dipankar - 2022-05-27

    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.

     
  • Maarten Brock

    Maarten Brock - 2022-05-27

    The SDCC developers think that sfr SP = 0x81 is 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 in compiler.h macros 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.

     
  • Dipankar

    Dipankar - 2022-05-29

    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).

    • Dipankar
     
    • Maarten Brock

      Maarten Brock - 2022-05-30

      I see you only used the SFR() macro.
      I strongly recommend to also use the SBIT() macro.

       
  • Maarten Brock

    Maarten Brock - 2022-05-30

    Further, you should also define an alias named __XPAGE for XRPS so SDCC can properly initialize variables in xdata. See the manual.

    SFR(__XPAGE, 0x8F);
    

    You cannot use nop() from TYPEDEF.h, use NOP from compiler.h instead.

    There is a bug in TYPEDEF.h which checks #ifdef uint8 which should check uint8_t instead. 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.

     
  • Dipankar

    Dipankar - 2022-06-13

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.