Arduino IDE
Adafruit ItsyBitsy M4
Load SimpleFOC example full_control_serial
Click Verify
Get loads of errors like this…
C:\Users\Richard\Documents\Arduino\libraries\Simple_FOC\src\drivers\hardware_specific\samd51_mcu.cpp:32:17: error: ‘TC4_CH1’ was not declared in this scope; did you mean ‘TC3_CH1’?
32 | { PORTB, 9, TC4_CH1, 1, NOT_ON_TIMER, 0, NOT_ON_TIMER, 0},
| ^~~~~~~
| TC3_CH1
Does anyone know a fix?
It seems like the hardware definitions for this board are wrong?
Richard
I should add I am using the latest simpleFOC library along with latest ArduinoSAMD and AdafruitSAMD board libraries.
I did have some challenges with the timers for the SAME51. Take a look at the source. There is a table for the various timers and it’s set up to choose the most suitable. You may have to specify which timer you wanna use.
It may also be the adafruit board definitions (pin_map) which is faulty (lacking some definitions)
Thanks for the reply. I can’t find any pin_map files on my computer.
The …Simple_FOC/…/samd51_mcu.cpp file refers to constants such as PORTB and TC4_CH1. I can’t figure out where it is looking for these. Anyone know?
That is because it is hitten
The thing is, maybe the pin you are using can use several timers but only one is assigned by adafruit.
The files relevant for your MCU should be in a Adafruit or SAM folder.
You could consider changing pins …
That is, find the timer/pins in the Datasheet. Then find the corresponding board_pin in the Adafruid docs.
The thing is that the example sketch provided by SimpleFOC doesn’t compile for SAMD51 (itsybitsy M4) there has to be a simple reason for this.
The example is found from the Arduino IDE…File - Examples - Simple FOC - motor_commands_serial_examples - magnetic_sensor - full_control_serial
I hear you, it certainly is a lot to take in, going through hidden code. I’m sorry to say, there is no way around the Datasheet. Best of luck!
All I can do is show you the door.
You mean lead you to the door. Show you the door means you are asking him to GTFO.
Thanks for your input - I suppose I was hoping someone had come across this before!
Hahaha, very good one, thank you.
Hi, late to the party on this one… I wrote the SAMD51 support, and I thought the PWM/timers peripherals table I made covers the SAMD51s, but perhaps the Itsy M4 has a different number of timers or something.
Or perhaps the board files from it just don’t define these constants.
I’ll make an issue on github and check it out, but it might take me a little while… if you manage to find the issue @dickiefixit , I’d sure appreciate some feedback, either here or on GitHub: SAMD51 compile problems on Adafruit ItsyBitsy M4 · Issue #217 · simplefoc/Arduino-FOC · GitHub
Hey @dickiefixit, I have committed a fix to our dev branch, here:
If you feel up to it you could check out the dev branch from GitHub and try it out… I unfortunately don’t have an Itsy Bitsy M4 here to test the fix myself at the moment. But the code now compiles for me in PlatformIO, when it didn’t before.
The reason is also clear now: the SAMD51G19A used on the ItsyBitsy has few timer units than the other SAMD51s, so these constants just weren’t defined.
Hey @runger, thank you very much for the guidance here. I am away for the next few weeks and I don’t have my hardware with me, but I will be on the case as soon as I get back. I am an experienced microcontroller programmer (mostly TI Tiva recently), but new to Arduino and really enjoying it.
Is there a “better” IDE than the Arduino IDE to work in? May be I’m missing something but I can’t find a way of following constants and references back through library files, hence the difficulty in figuring out the structure and what was wrong/missing from the simpleFOC library for the M4.
Hi @dickiefixit ,
Arduino IDE is great for people who are completely new to programming. For anyone with even a little experience it is horrible.
There are a few options for working with embedded systems and Arduino framework.
- Sloeber is an eclipse based solution which pre-configures the CDT support in eclipse to work with Arduino toolchains, and has a library manager and boards manager built-in to download the packages needed
- ArduinoIDE 2.0 (based on VS Code but not much better than the original Arduino IDE in terms of features) internally uses arduino-cli - you can also use this, and make your own build system based on makefiles or whatever
- PlatformIO: an embedded development environment based on VS Code. Unlike Ardunio IDE 2.0 it gives access to the full VS Code functionality, and adds embedded development tools on top. PlatformIO has support for Arduino framework, comes with its own boards and packages manager, supports Arduino library discovery, debugging via various programmers, and more. VS Code comes with highlighting, code completion, code search, git integration, and anything else you might need via VS Code’s plugin system.
PlatformIO is what I currently use. We have a “quick start” guide in our documentation, and there are also lots of online resources to learn it.
Try VS Code with PlatformIO + Github Co-Pilot - that makes for next level code completion
Hi @runger,
I now have VSCode with PlatformIO installed. Even though I don’t have my hardware with me, and I’ve only been playing for half an hour, I can see that this IDE is so much better.
You say above… you could check out the dev branch from GitHub and try it out… should I just overwrite my library samd51_mcu.cpp file with your edited version? Or is there a better way to update my simpleFOC library. I think I need to learn how to use GitHub properly!
Hi, yes,
in platformIO the best way can be to put the dev branch library inside the “lib” folder of your project.
I won’t go into details about git and GitHub as there are so many resources for this.
But basically you can “git clone” the dev branch directly into the lib folder using a command like this
git clone --branch dev https://github.com/simplefoc/Arduino-FOC.git
Either you do it in the lib folder of your project, or you put it elsewhere and create a symlink (“Directory Junction” in windows) in the lib folder.
There’s also plenty of GUI git clients to make it easier to work with git. it’s also built into VSCode.
Note you don’t need a GitHub account just to clone the repository.