ryansuchocki / microscheme

A Scheme subset for Atmel microcontrollers.
http://ryansuchocki.github.io/microscheme/
MIT License
300 stars 20 forks source link

Linking errors #27

Closed YPares closed 7 years ago

YPares commented 8 years ago

Hi! I'm on Ubuntu 15.10 x64, I installed both gcc-avr and avrdude, but when trying the example with ./microscheme -m UNO -d /dev/ttyUSB0 -auc examples/BLINK.ms I get

>> 18 lines compiled OK
>> Assembling...
/usr/lib/gcc/avr/4.8.1/../../../avr/bin/ld: cannot find crtm328p.o: No such file or directory
/usr/lib/gcc/avr/4.8.1/../../../avr/bin/ld: cannot find -lm
/usr/lib/gcc/avr/4.8.1/../../../avr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
ryansuchocki commented 8 years ago

Hi!

I'll set up an ubuntu virtual machine, to see if I can replicate this. In the meantime, can you check whether avr-libc and binutils-avr are installed?

ryansuchocki commented 8 years ago

OK, I have recreated the crtm328p.o error. This is provided by avr-libc, which seems to be an optional dependency. This should solve it:

$ sudo apt-get install avr-libc

Let me know if there are any further issues, and I will update the documentation...

YPares commented 8 years ago

Can't upload the result to my arduino right now but it has fixed the linking problem, yes. Thanks!

YPares commented 8 years ago

I've got another problem now:

$ microscheme BLINK.ms -m UNO -d /dev/ttyUSB0 -u 
Microscheme 0.9.3, (C) Ryan Suchocki
Treeshaker: After 4 rounds: 89 globals purged! 22 bytes will be reserved.
18 lines compiled OK
Assembling...
Uploading...
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
YPares commented 8 years ago

Note I tried both with my Duemilanove and my Nano. Same output. And it doesn't happen when I use arduino-mk or the arduino IDE And ttyUSB0 is the right device, as it appears only when I plug the board.

ryansuchocki commented 8 years ago

Hi. The simple answer is that each Arduino model is slightly different, and neither the Duemilanove nor the Nano are supported by microscheme yet. (This is mainly because I don't own them, so it's hard to make the necessary adjustments.) The supported models are Uno, Mega and Leonardo.

However, the Nano is very similar to the UNO, so it may be possible to use yours. (It depends on the version of the board, and whether it's an official board or a clone...)

I suggest you try again with the Nano, and experiment with pressing the physical reset pin (on the Nano) repeatedly, after microscheme has started to run.

ryansuchocki commented 8 years ago

Also, one of the reasons I made this project open source is because it would be impractical (and expensive!) for me to do development and testing on all the Arduino models, but hopefully other people can fill in those gaps over time.

I know it should be quite simple to support the Duemilanove, for example, but without one in front of me, I can only provide hints...

YPares commented 8 years ago

Okay! I understand, even if that's a bit puzzling as duemilanove & Uno are programmed in the same way by the Arduino IDE (you don't have to change options), same for the Mini Pro & Nano I also have a Mini Pro 5v, I can try with it. (Both my mini pro and my nano are unofficial)

2016-05-20 3:08 GMT+02:00 Ryan Suchocki notifications@github.com:

Also, one of the reasons I made this project open source is because it would be impractical (and expensive!) for me to do development and testing on all the Arduino models, but hopefully other people can fill in those gaps over time.

I know it should be quite simple to support the Duemilanove, for example, but without one in front of me, I can only provide hints...

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/ryansuchocki/microscheme/issues/27#issuecomment-220493011

ryansuchocki commented 8 years ago

You could try using microscheme with arduino-mk, on the Nano.

e.g., just run microscheme -m UNO BLINK.ms.

This tells ms to compile the program, but not assemble or upload it. It will generate BLINK.s.

BLINK.s is an assembly source which can be passed to avr-gcc, just like any C source. So, in theory, arduino-mk should be able to handle the assembly and uploading process from there...

ryansuchocki commented 8 years ago

I can confirm that this works with my UNO.

I used a simple makefile:

BOARD_TAG     = uno
MONITOR_PORT  = /dev/ttyACM0
include /usr/share/arduino/Arduino.mk

Arduino-mk expects .S extension, so I just ran:

$ microscheme -m UNO BLINK.ms
$ mv BLINK.s BLINK.S
$ make upload

Arduino-mk then successfully uploaded the program! I would be surpised if this doesn't work on your Nano :)

YPares commented 8 years ago

@ryansuchocki Thank you! I give you the Makefile I made, if you want to include it to docs re. support of other boards:

ARDUINO_DIR = /opt/arduino
BOARD_TAG = diecimila
BOARD_SUB = atmega328

include ../Arduino-Makefile/Arduino.mk

PROJ := BLINK

ms: $(PROJ).S upload

$(PROJ).S: $(PROJ).ms
    microscheme -m UNO $(PROJ).ms
    mv $(PROJ).s $(PROJ).S

And I just do make ms to build/upload everything. The only problem I have with this approach is that Arduino.mk wants some .S, .cpp or .ino to be present before everything. So I worked around it by creating a dummy.cpp before running it. Also the first time I have to run it twice or else it complains about setup and loop symbols not being defined. I'm not the boss of Makefiles, I'm afraid...

ryansuchocki commented 8 years ago

Yeah, It is bizarre that Arduino-mk does all its checks immediately, rather than when a rule is invoked.

Anyway, I can't stand having dummy files lying around, so I found a way of telling Arduino-mk about the source file before it really exists. We just create an empty .s file, to be filled in by microscheme later. This forces it to accept the lower-case extension too:

BOARD_TAG     = ...
MONITOR_PORT  = ...
PROJ := BLINK

# Create an empty source file:
$(shell touch $(PROJ).s)
# This effectifely overrides line 770 in Arduino-mk:
LOCAL_AS_SRCS := $(PROJ).s $(wildcard *.S *.s)

include .........../Arduino.mk

ms: $(PROJ).s upload

# Since we created an empty PROJ.s, we must force it to be compiled for real:
$(PROJ).s: $(PROJ).ms FORCE
    microscheme -m UNO $(PROJ).ms

FORCE: