How do I 'link' an outside file (.s) to an arduino sketch?

(I'm a beginner user)

I know that what I'm asking can be done because I did it on a Windows, but I can't on my Mac. The '.s' file contains code to make my Adruino Uno's light flash.

.file "test.s" .text .global testf testf: ldi r17, 0x20 out 0x04, r17 ldi r16, 50 all: ldi r17, 0x20 out 0x05, r17 ldi r18, 0xff dl1: ldi r19, 0xff dl2: nop nop nop nop dec r19 brne dl2 dec r18 brne dl1 ldi r17, 0x00 out 0x05, r17 ldi r18, 0xff dl3: ldi r19, 0xff dl4: nop nop nop nop dec r19 brne dl4 dec r18 brne dl3 dec r16 brne all ret

On Windows I was able to access this code using this in my sketch

extern "C" { void testf(); } void setup() { testf(); } void loop() { }

My Sketchbook location is: /Users/John/CS273/arduino/labber1

And I try linking the .s with the sketch by going to: Sketch --> Add Files --> /Users/John/CS273/arduino/labber1/test.s -but then I get this error after compiling:

Arduino: 1.5.5 (Mac OS X), Board: "Arduino Uno" Lab1_.cpp.o: In function `setup': /Applications/Lab1_.ino:2: undefined reference to `testf'

What should I do? Please help!

Try using the suffix .S instead of .s

Is there a way around this whole issue by posting the .s information in the sketchbook somehow?

Once you have "added" the file it should have copied it into the sketch folder. Check it's there.

Cross-posts merged. DO NOT CROSS-POST - IT WASTES TIME.

majenko: Once you have "added" the file it should have copied it into the sketch folder. Check it's there.

No that didn't work unfortunately. Is there a way around this whole issue by posting the .s information in the sketchbook somehow?

Is there a way around this whole issue by posting the .s information in the sketchbook somehow? Can somebody please show me what that code would look like?

Close the IDE, manually copy the file into the sketch's folder, then open the IDE, load the sketch, and you may find the code is now in a tab in the IDE. Try compiling, see what happens.

majenko: Close the IDE, manually copy the file into the sketch's folder, then open the IDE, load the sketch, and you may find the code is now in a tab in the IDE. Try compiling, see what happens.

No strangely that didn't work to. Does this have something to do with cshrc? Because I'm not to sure if I set that up correctly...but so I don't have to link files can't I just copy and paste the .s code into the Arduino environment like this:

extern "C" { void .file "test.s" .text .global testf testf: ldi r17, 0x20 out 0x04, r17 ldi r16, 50 all: ldi r17, 0x20 out 0x05, r17 ldi r18, 0xff dl1: ldi r19, 0xff dl2: nop nop nop nop dec r19 brne dl2 dec r18 brne dl1 ldi r17, 0x00 out 0x05, r17 ldi r18, 0xff dl3: ldi r19, 0xff dl4: nop nop nop nop dec r19 brne dl4 dec r18 brne dl3 dec r16 brne all ret(); } void setup() { testf(); } void loop() { }


OR LIKE THIS

extern "C" { void (); } void setup() { .file "test.s" .text .global testf testf: ldi r17, 0x20 out 0x04, r17 ldi r16, 50 all: ldi r17, 0x20 out 0x05, r17 ldi r18, 0xff dl1: ldi r19, 0xff dl2: nop nop nop nop dec r19 brne dl2 dec r18 brne dl1 ldi r17, 0x00 out 0x05, r17 ldi r18, 0xff dl3: ldi r19, 0xff dl4: nop nop nop nop dec r19 brne dl4 dec r18 brne dl3 dec r16 brne all ret(); } void loop() { }

Please tell me if this code or similar code works on your Arduino.

I don't have the Arduino IDE installed at the moment, but using UECIDE (it should be the same in the Arduino IDE) I create a new file (Sketch -> New File) and name it "test.S" (note the capital S there) and paste your code into it.

Then in the main sketch .ino file I put:

extern "C" {
    extern void testf();
}

void setup() {  
}

void loop() {
    testf();
}

... and it compiles. I don't know if it works, but it compiles.

There is a huge difference between .s files and .S files. .S files get preprocessed by the compiler, whereas .s files don't (it is assumed they are already preprocessed).