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
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"
/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;
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.
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.
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.
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 {
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..
That way, @jonathanberi will be able to continue is work with Firmata, since both HardwareSerial and USBSerial will derived from Stream.
Thats fine.
Leave it empty. I may have done the same thing on the F1’s USB serial.
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.
No worries.
I recall looking at USBSerial peek() but it was several months ago and I couldnt remember precisely what I’d done ![]()
The PR has been actioned.
@jonathanberi, please grab the latest copy of the repo and see if this addresses your issue.
Thanks
Now when I start trying out the different builds variations of Firmata (with different features,) I get all different, albeit useful, errors.
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.
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.
#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
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.
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
Thanks,
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
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
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
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
fpiSTM wrote:I don’t think you should use the repo STM from my github. You should keep the one from stm32duino.
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.
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 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.
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.
…..
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].
.
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);
}
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.
Thanks,
Aram

