Firmata

jonathanberi
Sat Aug 01, 2015 7:56 pm
I wanted to port Firmata to STM32 boards and figured STM32duino would be the easiest path. I was able to upload a blinking programming via stlink on a nucleoF401RE board. I actually don’t need help ATM (though help is always welcome!) but posted here since there isn’t a “in progress” section. You can follow along at https://github.com/beriberikix/Arduino_STM32.

RogerClark
Sat Aug 01, 2015 9:42 pm
Hi Jonathan,

I suspect that porting Fermata may not be too hard, because there is already support for the Due.

At least to start with, I would just change the code that checks for the SAM hardware, and add code to OR __STM32F1__ or perhaps just replace the tests for SAM with __arm__. But you may need to do a mix of both.

Various people on this forum have ported a large number of libs, so I’m sure if you get stuck, someone will be able to help


jonathanberi
Sun Aug 02, 2015 5:27 am
Thanks Roger! I think it’ll be pretty straight-forward as well. Just need to steal more time :) Firmata also has a HAL of sorts, which I need to decrypt, but it looks simple.

jonathanberi
Mon Aug 10, 2015 4:01 am
I’m running into an issue where the Stream lib isn’t found (link). Any ideas?

RogerClark
Mon Aug 10, 2015 4:17 am
The core has Stream.h and Stream.cpp

My guess is that we don’t include Stream in quite the same place as the AVR Arduion’s do.

Its included in a load of places

Arduino_STM32\STM32F1\cores\maple\HardwareSerial.h (1 hits)
Line 40: #include "Stream.h"
Arduino_STM32\STM32F1\cores\maple\Stream.cpp (1 hits)
Line 24: #include "Stream.h"
\Arduino_STM32\STM32F1\cores\maple\Stream.h (1 hits)
Line 2: Stream.h - base class for character-based streams.
Arduino_STM32\STM32F1\cores\maple\usb_serial.h (1 hits)
Line 36: #include "Stream.h"


jonathanberi
Mon Aug 10, 2015 2:50 pm
Added Stream.h to Firmata.h and most of the compilation errors went away. However, HardwareSerial is complaining:

/Users/me/Documents/Arduino/libraries/firmata/Firmata.cpp: In member function 'void FirmataClass::begin(long int)':
/Users/me/Documents/Arduino/libraries/firmata/Firmata.cpp:70:17: error: cannot convert 'HardwareSerial*' to 'Stream*' in assignment
FirmataStream = &Serial;


RogerClark
Mon Aug 10, 2015 9:11 pm
The F1 and F4 have the same ancestry, i.e libmaple, but took different routes to where we are now.

The F4 code, was forked from libmaple several years ago by the AeroQuad community, and developed separately from what leaflabs was doing on the F1 libmaple.

I did a major refactor of the F1 code when I took this whole thing on, almost a year ago, to attempt to bring libmaple in line with the Arduino 1.0 API ( as libmaple was written at the time of Arduino 0022 and not extensively updated by Leaflabs ).

@Martinaoette has done a load of work on the F4 side of things, to bring it up to Arduino 1.0 API level, but has his changes and the initial codebase are not identical for the F1 and my changes, where are still some differences between the F1 and the F4.

That being said. If you can let us know what compiles for the F1 but not the F4, or vice versa, I’d be happy to change the F4 repo, or even the F1 repo,
as long as the change didnt break any existing stuff.


martinayotte
Tue Aug 11, 2015 2:39 am
This error need to be investigated.
But since I don’t use HardwareSerial directly, I’ve never faced the problem.
Maybe HardwareSerial is a legacy of libmaple, that is not needed anymore, because, tell me if I’m wrong, normal Serial is using hardware port when pins match the real hardware pins.

RogerClark
Tue Aug 11, 2015 3:40 am
I thought hardware serial was used.

Serial is either mapped to USBSerial or Hardware serial depending on which configs you pick from the boards menu (controlled by #defines)

So.. Hardware serial is used and works.


martinayotte
Tue Aug 11, 2015 6:51 pm
Yesterday, I was falling to sleep, so I didn’t try to investigate.

Today, I’ve just looked at HardwareSerial of F4, and it is derived from Print not from Stream like the F1.
So, maybe it just requires to change that for both HardwareSerial and USBSerial, since same phenomena apply the this one too.
I didn’t catch this before since I didn’t had any code such Firmata that requires that and was producing the error “cannot convert ‘HardwareSerial*’ to ‘Stream*’ in assignment”.

So, @jonathanberi, maybe you can try it on your side : simple change Print to Stream in HardwareSerial.h and add #include “Stream.h”

class HardwareSerial : public Stream {


jonathanberi
Tue Aug 11, 2015 7:43 pm
Oh insomnia – the best fix (and creator) of bugs! Let me know how & when I can help with testing.

RogerClark
Tue Aug 11, 2015 9:01 pm
Martin,

In the F1, I changed the Print / Steam stuff last year when i realised that the original libmaple was considerably different from the way the AVR and Due Arduinos handle Print etc.

I recall needing change quite a lot of files, but I think I also did some other reorganisation at the same time, as libmaple had headers in a sub folder etc, which didn’t correspond with the AVR code, so I think I took the opportunity to do a load of changes at the same time.

It was on my ToDo list, to change this myself, but I have a very long list, and it was not at the top ;-)

So thanks for looking at it..


martinayotte
Tue Aug 11, 2015 10:16 pm
Roger, if you don’t care if I leave the USBSerial::peek() as an empty stub for now, I think I will commit those changes soon and send you a PR.
That way, @jonathanberi will be able to continue is work with Firmata, since both HardwareSerial and USBSerial will derived from Stream.

RogerClark
Tue Aug 11, 2015 10:26 pm
Hi Martin

Thats fine.

Leave it empty. I may have done the same thing on the F1’s USB serial.


martinayotte
Tue Aug 11, 2015 10:29 pm
Ok ! Thanks ! I will probably commit later tonight …

I may have done the same thing on the F1’s USB serial.

No, you did the call to low level CDC peek(), but under F4, the CDC is completely different than the one from F1, and there is no peek() in the F4.


RogerClark
Tue Aug 11, 2015 10:30 pm
Hi Martin,

No worries.

I recall looking at USBSerial peek() but it was several months ago and I couldnt remember precisely what I’d done ;-)


martinayotte
Tue Aug 11, 2015 10:54 pm
I’ve done the commit and the PR while my souper was cooking … ;)

RogerClark
Tue Aug 11, 2015 11:21 pm
Martin,
The PR has been actioned.

@jonathanberi, please grab the latest copy of the repo and see if this addresses your issue.

Thanks


jonathanberi
Wed Aug 12, 2015 12:03 am
w00t, progress! After a git pull EchoPing now compiles without error. I don’t have the board handy ATM the moment but will test it when I get home.

Now when I start trying out the different builds variations of Firmata (with different features,) I get all different, albeit useful, errors.

StandardFIrmata:

Arduino: 1.6.5 (Mac OS X), Board: "STM32 NUCLEO F401RE"

Using library Servo in folder: /Applications/Arduino.app/Contents/Java/libraries/Servo
Using library Firmata in folder: /Users/me/Documents/Arduino/libraries/firmata

WARNING: library Servo claims to run on [avr, sam] architecture(s) and may be incompatible with your current board which runs on [STM32F4] architecture(s).

/Users/me/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -MMD -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_nucleo_f401re -DVECT_TAB_BASE -DERROR_LED_PORT=GPIOD -DERROR_LED_PIN=14 -mcpu=cortex-m4 -DF_CPU=168000000L -DARDUINO=10605 -DARDUINO_STM32F4_NUCLEO_F401RE -DARDUINO_ARCH_STM32F4 -DMCU_STM32F406VG -mthumb -DSTM32_HIGH_DENSITY -DSTM32F2 -DSTM32F4 -DBOARD_discovery_f4 -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/usbF4 -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/usbF4/STM32_USB_Device_Library/Core/inc -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/usbF4/STM32_USB_Device_Library/Class/cdc/inc -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/usbF4/STM32_USB_OTG_Driver/inc -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple/libmaple/usbF4/VCP -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/cores/maple -I/Users/me/Documents/Arduino/hardware/Arduino_STM32/STM32F4/variants/nucleo_f401re -I/Applications/Arduino.app/Contents/Java/libraries/Servo/src -I/Users/me/Documents/Arduino/libraries/firmata /var/folders/00/144nr000h01000cxqpysvccm004hkq/T/build3263617536636599899.tmp/StandardFirmata.cpp -o /var/folders/00/144nr000h01000cxqpysvccm004hkq/T/build3263617536636599899.tmp/StandardFirmata.cpp.o
In file included from StandardFirmata.ino:28:0:
/Applications/Arduino.app/Contents/Java/libraries/Servo/src/Servo.h:67:2: error: #error "This library only supports boards with an AVR or SAM processor."
#error "This library only supports boards with an AVR or SAM processor."
^
StandardFirmata.ino:29:18: fatal error: Wire.h: No such file or directory
compilation terminated.
Multiple libraries were found for "Firmata.h"
Used: /Users/me/Documents/Arduino/libraries/firmata
Not used: /Applications/Arduino.app/Contents/Java/libraries/Firmata
Error compiling.


mrburnette
Wed Aug 12, 2015 12:10 am
martinayotte wrote:Ok ! Thanks ! I will probably commit later tonight …

I may have done the same thing on the F1’s USB serial.

No, you did the call to low level CDC peek(), but under F4, the CDC is completely different than the one from F1, and there is no peek() in the F4.


RogerClark
Wed Aug 12, 2015 12:35 am
re:

#error “This library only supports boards with an AVR or SAM processor.”

This is caused because one of the libs has a setting which explicitly says it only works on AVR and SAM

The only way to fix this is to update the library.

Look in the library.properties file for the library in question and you’ll see a line that says something like

architectures=avr


martinayotte
Wed Aug 12, 2015 12:36 am
jonathanberi wrote:w00t, progress! After a git pull EchoPing now compiles without error. I don’t have the board handy ATM the moment but will test it when I get home.

Now when I start trying out the different builds variations of Firmata (with different features,) I get all different, albeit useful, errors.

[…]

Looking at the F4 core, I don’t see Wire (only wirish) and I don’t see Servo in libraries. Copying Servo from the F1 directory allows ServoFirmata to compile but I’m not sure what do with the Wire issues on the other files like StandardFirmata.


RogerClark
Wed Aug 12, 2015 12:53 am
(@Roger, should we have library folder for all common libs between F1/F2/F3/F4 ?)

I don’t think its possible for the Arduino IDE to look elsewhere apart from /CORE/libraries

So I can’t see how we can put the lib’s elsewhere


aramperez
Tue Nov 08, 2016 1:00 pm
Has any further work been done on getting Firmata running with an STM32 board? I’d like to run Firmata on a Chinese Maple Mini clone.

Thanks,
Aram


fpiSTM
Fri Dec 02, 2016 2:08 pm
Hi aram,

It was already done for STM32F103 and STM32L476.
Have a look to those commits:
Update for L476 (based on Firmata library v2.5.2):
https://github.com/fpistm/STM/commit/c5 … e19354b298
Update for F103 (based on L476):
https://github.com/fpistm/STM/commit/b6 … 09428f7b1c

BR


aramperez
Sun Dec 04, 2016 1:16 pm
Hi fpiSTM,

Sorry, I’m new to how the Arduino IDE internal structure works and how “Arduino for STM32” modifies that structure. From a quick glance at the links, it appears that the changes are against something other than “Arduino for STM32”. So how would I add those changes to “Arduino for STM32”?

Thanks,
Aram


aramperez
Sun Dec 04, 2016 5:19 pm
Hi Frederic,

[Sorry, this a long post because of all the Arduino compile results.]

fpiSTM wrote:Hi aram,
It was already done for STM32F103 and STM32L476.
Have a look to those commits:
Update for L476 (based on Firmata library v2.5.2):
https://github.com/fpistm/STM/commit/c5 … e19354b298
Update for F103 (based on L476):
https://github.com/fpistm/STM/commit/b6 … 09428f7b1c
BR


fpiSTM
Mon Dec 05, 2016 9:28 am
Hi Aram,

I don’t think you should use the repo STM from my github.
You should keep the one from stm32duino.
I only give you an example how the firmata library has been updated.
I think you should copy the firmata library to the hardware/xxxx/libraries/ and customize it or modify the one to the libraries/ it as it has been done for the STM32F103.
Just think to use a switch related to the maple mini in the header:
#elif defined(STM32) <– STM32 to update


aramperez
Mon Dec 05, 2016 12:57 pm
Hi Frederick,

fpiSTM wrote:I don’t think you should use the repo STM from my github. You should keep the one from stm32duino.


fpiSTM
Mon Dec 05, 2016 1:41 pm
Which one from stm32duino? If I search https://github.com/rogerclarkmelbourne/Arduino_STM32, I do not find anything related to Firmata.

Yes this one, I think. As it mentions “including LeafLabs Maple, and Maple mini”.
For the library, I don’t know it, I provided you only an example on how it has been adapted for the STM32F103. If it request more update, you will have to do it.
I do not know the maple part, maybe @RogerClark could help/advise.

RogerClark
Mon Dec 05, 2016 7:46 pm
Aram

You seem to somehow have a mix of both the Libmaple based core and STMs new core.

Did you install from both the boards manager package and download the zip file from my repo.


aramperez
Mon Dec 05, 2016 9:05 pm
Hi Roger,

RogerClark wrote:You seem to somehow have a mix of both the Libmaple based core and STMs new core.
Did you install from both the boards manager package and download the zip file from my repo.


RogerClark
Mon Dec 05, 2016 9:49 pm
The LibMaple version can be installed via boards manager, as @ddrown has done this on his site.

However generation of the boards manager package files is not straight forward and I don’t personally have time to do this

With the STM official version, we added a WIP branch which adds support for the Maple mini and Blue Pill, but as it is not official there is not a Boards Manager for this either.


RogerClark
Mon Dec 05, 2016 9:57 pm
aramperez wrote:
…..

However, the Maple Mini code uses Libmaple and it’s Wire implementation hasn’t been updated to the latest Arduino Wire API, it is missing an endTransmission(argument) method [I believe that ‘argument’ is a bool but I haven’t dug into the code yet].
.


aramperez
Mon Dec 05, 2016 11:53 pm
RogerClark wrote:
If you can tell me what the new function does, perhaps we can include it

BTW. I took a look at the Arduino Wire code and it has this extra code

if (stopBit)
{
sercom->prepareCommandBitsWire(WIRE_MASTER_ACT_STOP);
}


RogerClark
Tue Dec 06, 2016 12:36 am
OK

I suspect we can perhaps do this simply by not calling i2c_stop()

I’m not precisely sure why the Arduino team wrote another version of the function, rather than just changing the existing function to include a parameter and then default that parameter to true.


aramperez
Tue Dec 06, 2016 2:41 am
Or why not use a ‘bool’ as the argument type instead of an ‘uint8_t’.

Thanks,
Aram


RogerClark
Tue Dec 06, 2016 3:19 am
Our endTransmission does not have an argument, its current (void)

Leave a Reply

Your email address will not be published. Required fields are marked *