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

Seeeduino XIAO (SAMD21G18 Cortex-M0+) #78

Open
courtens opened this issue Jul 19, 2021 · 6 comments
Open

Seeeduino XIAO (SAMD21G18 Cortex-M0+) #78

courtens opened this issue Jul 19, 2021 · 6 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested

Comments

@courtens
Copy link

courtens commented Jul 19, 2021

Is this library compatible with my Seeeduino XIAO? It is a SAMD21G18 Cortex-M0+ chip.

This is what I get trying to run UsageExample.ino:

WARNING: library FastAccelStepper claims to run on avr, esp32 architecture(s) and may be incompatible with your current board which runs on samd architecture(s).
In file included from c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.h:10:0,
                 from c:\Users\Nathaniel\Documents\Arduino\FilmFix\FilmFix.ino:52:
c:\users\nathaniel\documents\arduino\libraries\fastaccelstepper\tests\pc_based\stubs.h:5:0: warning: "pgm_read_byte_near" redefined
 #define pgm_read_byte_near(x) (*(x))
 
In file included from C:\Users\Nathaniel\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.1\cores\arduino/Arduino.h:36:0,
                 from C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\sketch\FilmFix.ino.cpp:1:
C:\Users\Nathaniel\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.1\cores\arduino/avr/pgmspace.h:110:0: note: this is the location of the previous definition
 #define pgm_read_byte_near(addr) pgm_read_byte(addr)
 
In file included from c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.h:10:0,
                 from c:\Users\Nathaniel\Documents\Arduino\FilmFix\FilmFix.ino:52:
c:\users\nathaniel\documents\arduino\libraries\fastaccelstepper\tests\pc_based\stubs.h:19:0: warning: "abs" redefined
 #define abs(x) ((x) > 0 ? (x) : -(x))
 
In file included from C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\sketch\FilmFix.ino.cpp:1:0:
C:\Users\Nathaniel\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.1\cores\arduino/Arduino.h:135:0: note: this is the location of the previous definition
 #define abs(x) ((x)>0?(x):-(x))
 
C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\libraries\FastAccelStepper\FastAccelStepper.cpp.o: In function `FastAccelStepperEngine::stepperConnectToPin(unsigned char)':
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.cpp:82: undefined reference to `StepperQueue::isValidStepPin(unsigned char)'
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.cpp:116: undefined reference to `StepperQueue::queueNumForStepPin(unsigned char)'
C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\libraries\FastAccelStepper\FastAccelStepper.cpp.o: In function `FastAccelStepper::setDirectionPin(unsigned char, bool)':
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.cpp:476: undefined reference to `fas_queue'
C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\libraries\FastAccelStepper\FastAccelStepper.cpp.o: In function `FastAccelStepper::move(long)':
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/FastAccelStepper.cpp:545: undefined reference to `fas_queue'
C:\Users\NATHAN~1\AppData\Local\Temp\arduino-sketch-4B354A760F649884E833B790D5F4E104\libraries\FastAccelStepper\RampGenerator.cpp.o: In function `RampGenerator::_startMove(long, long)':
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/RampGenerator.cpp:139: undefined reference to `noInterrupts()'
c:\Users\Nathaniel\Documents\Arduino\libraries\FastAccelStepper\src/RampGenerator.cpp:147: undefined reference to `interrupts()'
collect2.exe: error: ld returned 1 exit status
Compilation error: Error: 2 UNKNOWN: exit status 1
@courtens
Copy link
Author

courtens commented Jul 19, 2021

I replaced defined(ARDUINO_ARCH_AVR) with defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) .

Now I am getting:

error: 'MAX_STEPPER' was not declared in this scope
   FastAccelStepper* _stepper[MAX_STEPPER];

MAX_STEPPER is defined in FastAccelStepper\src\RampGenerator.h as:

#if defined(TEST)
#define MAX_STEPPER 2
#define TICKS_PER_S 16000000L
#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_SAMD) 
#if defined(__AVR_ATmega328P__)
#define MAX_STEPPER 2
#elif defined(__AVR_ATmega2560__)
#define MAX_STEPPER 3
#endif
#define TICKS_PER_S F_CPU
#elif defined(ARDUINO_ARCH_ESP32)
#define MAX_STEPPER 6
#define TICKS_PER_S 16000000L
#else
#define MAX_STEPPER 6
#define TICKS_PER_S 16000000L
#endif

so I also I replaced defined(__AVR_ATmega2560__) with defined(__AVR_ATmega2560__) || defined(ARDUINO_ARCH_SAMD) .
and also tried defined(__AVR_ATmega328P__) with defined(__AVR_ATmega328P__) || defined(ARDUINO_ARCH_SAMD) instead --- but got stuck. I don't know enough about Timers.

The Seeeduino runs at 48MHz

@gin66
Copy link
Owner

gin66 commented Jul 20, 2021

From the datasheet the Seeduino Xiao could drive three steppers:

Three 24-bit Timer/Counters for Control (TCC), with extended functions:
• Up to four compare channels with optional complementary output
• Generation of synchronized pulse width modulation (PWM) pattern across port pins

But it is quite an effort to implement. If there are a couple of comments wanting this chip to be supported, then I will look into it. So I keep it open, for others to register their wish. A patch (MIT licensed) would be welcomed, too

@courtens
Copy link
Author

courtens commented Jul 20, 2021

Thank you -- very much appreciated!

I would need to drive just one stepper (... if that helps.)

I am still new to the github concept and I am not sure what this would entail: "A patch (MIT licensed) would be welcomed, too"; I plan on using it privately, and found FlexyStepper to do the job for now. It would be nice if I could run it faster so I can use 1/8 or 1/16 steps.

@clazarowitz
Copy link
Collaborator

clazarowitz commented Jul 25, 2021

You are in so much luck....I'm not sure what the seeduino xiao is, (duh, its in your title) but I'm still not sure how much it is like the DUE/SAM8x3e. Might have to change the ifdefs a bit to exclude certain ARDUINO_ARCH_SAM boards..., but I'm pretty close to forking/committing/pull-requesting Due support. You're addition of ARDUINO_ARCH_SAM makes me wonder.

I didn't look too closely at the full line. My code is using the PWM generator peripheral, not synchronous, to generate up to 8 channels...but not all pins are easily accessible, and some share functions with other pins you're likely to want. I arbitrarily capped it at 6. gin66 is correct, this was a non-trivial effort. It probably would have been easier for him, and I suspect he will need to "fix" some of my code (or tell me what to fix).

I chose NOT to use the timers because I need them to read servo PWM signals. It looks like those timers have a rise time capture, as well as a fall time capture, so no ISR delay on pulses that are synchronous and end within a few microseconds of one another. I'm working pretty hard to get this committed tonight....as evident by the fact I just registered a github account (I havent had need/want to contribute/collaborate until very recently). Anyhow, off to fork...

@clazarowitz
Copy link
Collaborator

You can give my fork a shot and see if it works...I didn't look at the datasheet for the SAMD21G18, so I honestly have no idea.
https://github.com/clazarowitz/FastAccelStepper

@clazarowitz
Copy link
Collaborator

So, I did just have a look at the data sheet for the SAMD21G18. Sorry, my fork will definatly not work. The M0 and M3 from atmel are just too different. Looks like my #defines will need to be updated. ARDUINO_ARCH_SAM is far too broad.

@gin66 gin66 added enhancement New feature or request question Further information is requested labels Nov 15, 2021
@gin66 gin66 added the help wanted Extra attention is needed label May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants