Menu

Use XC8 on Command Line for ATmega328

2022-04-21
2023-02-20
  • Lief Koepsel

    Lief Koepsel - 2022-04-21

    Hi Mikael,
    FlashForth is remarkable! I enjoy how well it works on 8-bit processors such as the ATmega328!

    I've used avrasm2 on the command line in the past to recompile FlashForth for the ATmega328p and it appears that this won't work in the new XC8 format.

    My previous command was:

    avrasm2.exe -I avr_inc ..\flashforth\avr\src\ff-atmega.asm -o out.hex -fI
    

    Is there something similar to this using the XC8 compiler/assembler?

    Thanks,
    Lief

     
  • Mikael Nordman

    Mikael Nordman - 2022-04-22

    Hi Lief.
    This is one way to do it but it requires that you first make a project in MPLABX.
    Add -DOPERATOR_UART = "{OPERATOR_UART}" to the MPLABX project XC8 global options

    cd FF.X
    make clean all MP_PROCESSOR_OPTION=ATmega328  OPERATOR_UART=0
    

    The hex file can be found at

    FF.X/dist/default/production/FF.X.production.hex
    

    Mikael

     

    Last edit: Mikael Nordman 2022-04-22
  • Lief Koepsel

    Lief Koepsel - 2022-04-22

    Thank you, Mikael

    I will try that.

     
  • Lief Koepsel

    Lief Koepsel - 2023-02-19

    Hi Mikael,

    I needed to work on some other things, so I left this for a while. :)

    I attempted to do as you advised:
    1) I believe the addition to global options is: (added $), correct?
    -DOPERATOR_UART="${OPERATOR_UART}"
    2) I had quite a few errors (> 200) with the usbcdc-xc8.asm file included:

    src/usbcdc-xc8.asm: Assembler messages:
    src/usbcdc-xc8.asm:93: Error: unknown opcode `fdw'
    src/usbcdc-xc8.asm:99: Error: constant value required
    src/usbcdc-xc8.asm:100: Error: constant value required
    src/usbcdc-xc8.asm:100: Error: register number above 15 required
    

    So I excluded the file as I don't believe it is required for the Uno (328P), correct?
    3) With that exclusion, I ended up with the follow error, which I haven't determined how to fix:

    Info: Loading file: /Applications/microchip/xc8/v2.40/avr/avr/bin/../lib/ldscripts/avr5.xn
    /Applications/microchip/mplabx/v6.05/packs/Microchip/ATmega_DFP/3.0.158/xc8/avr/lib/avr5/memx-const/crtatmega328.o:../../../../../crt1/gcrt1.S:352: undefined reference to `main'
    /Applications/microchip/mplabx/v6.05/packs/Microchip/ATmega_DFP/3.0.158/xc8/avr/lib/avr5/memx-const/crtatmega328.o:../../../../../crt1/gcrt1.S:353: undefined reference to `exit'
    collect2: error: ld returned 1 exit status
    make[3]: *** [dist/default/production/FF.X.production.hex] Error 1
    make[2]: *** [.build-conf] Error 2
    make[1]: *** [.build-impl] Error 2
    make: *** [.all-impl] Error 2
    

    I attempted many variations inside the configuration file for the Project, to no avail.
    Could you please provide some guidance?

    Thank you,
    Lief

     
  • Mikael Nordman

    Mikael Nordman - 2023-02-19

    You should not add the usbcdc-xc8.asm file to the project. It is automatically included for m32u4.

    You need to add "-nostartfiles" to the XC8 linker options.
    https://flashforth.com/atmega.html

    BR Mikael

     
  • Lief Koepsel

    Lief Koepsel - 2023-02-20

    Thanks! It works pefectly!!

     

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.