Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino setup #101

Open
kevinresol opened this issue Jan 16, 2019 · 6 comments
Open

Arduino setup #101

kevinresol opened this issue Jan 16, 2019 · 6 comments
Labels
bug Something isn't working

Comments

@kevinresol
Copy link

Describe the problem. What did you see? What did you expect to see?

First of all, Arduino expects two "main" functions void setup() and void loop().
From what I learned from other resources, when compiling manually (instead of compiling with the Arduino IDE), one has to include the Arduino.h header. I did so in Kit with include "Arduino.h"; and used #[extern] to keep the function name. However kit complains setup and loop is re-declared because it is already declared in Arduino.h.

Anyway, I commented out the #[extern] just to see if I can use the avr gcc to compile the code. But then I get this output https://pastebin.com/Jp1VRYLE

If this is a code issue, provide a minimal code example:

./build.sh:

#!/bin/bash

kitc \
  --cc /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/gcc-avr \
  --lib \
  -s src \
  -I /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino \
  -I /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard \
  -c -MMD \
  -c -c \
  -c -D__PROG_TYPES_COMPAT__ \
  -c -mmcu=atmega328p \
  -c -DF_CPU=16000000L \
  -c -DARDUINO=185 \
  -c -DARDUINO_ARCH_AVR\
  -c -Wall \
  -c -ffunction-sections \
  -c -fdata-sections \
  -c -Os \
  -c -std=gnu11 \
  -c -flto \
  -c -fno-fat-lto-objects \
  -c -fdiagnostics-color=always \
  -v \
  hello.kit

./src/hello.kit:

include "Arduino.h";

// #[extern]
function setup() {
    printf("%s\n", "Hello from Kit!");
}

// #[extern]
function loop() {
    printf("%s\n", "Hello from Kit!");
}

Environment

[2019-01-17 00:23:42.1359] ===> kitc version
[2019-01-17 00:23:42.1371] DBG: 0.1.0
[2019-01-17 00:23:42.1375] ===> OS
[2019-01-17 00:23:42.1378] DBG: darwin
[2019-01-17 00:23:42.1382] ===> Compiler
[2019-01-17 00:23:42.1386] DBG: /Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/gcc-avr
gcc-avr (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[2019-01-17 00:23:42.1421] ===> Include paths
[2019-01-17 00:23:42.1427] DBG: ["/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/../../../../avr/include","/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/include-fixed","/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.9.2/include"]
[2019-01-17 00:23:42.1448] ===> Compiler flags
[2019-01-17 00:23:42.1452] DBG: ["-D_GNU_SOURCE","-D_BSD_SOURCE","-D_DEFAULT_SOURCE","-std=c99","-pedantic","-O3","-Os","-U__BLOCKS__","-Wno-expansion-to-defined","-Wno-gnu-zero-variadic-macro-arguments","-Wno-missing-braces","-Wno-shift-op-parentheses","-MMD","-c","-D__PROG_TYPES_COMPAT__","-mmcu=atmega328p","-DF_CPU=16000000L","-DARDUINO=185","-DARDUINO_ARCH_AVR","-Wall","-ffunction-sections","-fdata-sections","-Os","-std=gnu11","-flto","-fno-fat-lto-objects","-fdiagnostics-color=always","-fPIC","-I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino","-I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard"]
[2019-01-17 00:23:42.1482] ===> Linker flags
[2019-01-17 00:23:42.1486] DBG: []
[2019-01-17 00:23:42.1489] ===> Source paths
[2019-01-17 00:23:42.1492] DBG: [".","src","/Users/kevin/Codes/kit/std"]
[2019-01-17 00:23:42.1497] ===> Standard prelude location
[2019-01-17 00:23:42.1543] DBG: found module <prelude> at /Users/kevin/Codes/kit/std/prelude.kit
[2019-01-17 00:23:42.1549] DBG: /Users/kevin/Codes/kit/std/prelude.kit
@bendmorris bendmorris added the bug Something isn't working label Jan 16, 2019
@bendmorris
Copy link
Member

However kit complains setup and loop is re-declared because it is already declared in Arduino.h.

This needs to be fixed. Kit shouldn't complain about things that are declared but not implemented.

We're at least getting to code generation; if you run kitc with --no-link it'll stop at the point where it's failing, and you can try linking yourself, without -shared:

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/gcc-avr build/obj/kit_hello.o build/obj/kit/array/kit_Array.o build/obj/kit/common/kit_CString.o build/obj/kit/io/Writable/kit_84558aa4a52e53199fd20a2b.o build/obj/kit/map/Hashable/kit_00ece7b11dd99d06a92da4ba.o build/obj/kit/map/Hashable/kit_245c01af2be1c62453ba052f.o build/obj/kit/map/Hashable/kit_2a867e0193ff634180614473.o build/obj/kit/map/Hashable/kit_84558aa4a52e53199fd20a2b.o build/obj/kit/map/Hashable/kit_a8e36feebcdf611d5ad0266f.o build/obj/kit/kit_math.o build/obj/kit/kit_mem.o build/obj/kit/mem/kit_LinearAllocator.o build/obj/kit/mem/kit_StackAllocator.o build/obj/kit/mem/Allocator/kit_0c47d7e6ba82e05c2d931be3.o build/obj/kit/mem/Allocator/kit_4221090da42112d334709b60.o build/obj/kit/mem/Allocator/kit_6381ed4a392eb3039656f126.o build/obj/kit/numeric/kit_Char.o build/obj/kit/numeric/kit_Float.o build/obj/kit/numeric/kit_Int.o build/obj/kit/numeric/kit_Size.o build/obj/kit/numeric/kit_Uint.o build/obj/kit/option/kit_Option.o build/obj/kit/kit_random.o build/obj/kit/slice/kit_Slice.o build/obj/kit/string/kit_String.o build/obj/kit/string/kit_StringBuffer.o build/obj/kit/kit_utils.o build/obj/kit/vector/kit_Vector.o -Ibuild/include -omain -lm

Thanks for the report; we can definitely make the process smoother.

@kevinresol
Copy link
Author

Also, the gcc name is actually avr-gcc, I just symlinked it as gcc-avr so that the prefix check works

@kevinresol
Copy link
Author

This needs to be fixed. Kit shouldn't complain about things that are declared but not implemented.

For now I hacked by removing the declaration there.

I have successfully use kit to generate the c code and compiles manually and upload an arduino and it is blinking!

@kevinresol
Copy link
Author

Ahh, forgot to mention, I also need to disable these two lines in std/utils.kit because stderr is not supported:

// vfprintf(stderr, msg, (args...));
// fputs("", stderr);

@bendmorris
Copy link
Member

Good note - Rust has a specific mode for embedded which disables most of its standard library, Kit will need something like that as well.

@bendmorris
Copy link
Member

bendmorris commented Mar 3, 2019

Keeping this open as a TODO. There are a few things to tackle:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants