Have you done anything so that UART2 is used in the code ?
I replaced all Serial.stuff with Serial2.
Iâm still using ArduinoIDE.
/**
* Hall sensor example code
*
* This is a code intended to test the hall sensors connections and to demonstrate the hall sensor setup.
*
*/
#include <SimpleFOC.h>
// Hall sensor instance
// HallSensor(int hallA, int hallB , int cpr, int index)
// - hallA, hallB, hallC - HallSensor A, B and C pins
// - pp - pole pairs
HallSensor sensor = HallSensor(PA0, PF1, PC15, 15); // blue, green, yellow, 15PP
// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}
void setup() {
// monitoring port
Serial2.begin(115200);
// check if you need internal pullups
//sensor.pullup = Pullup::USE_EXTERN;
// initialise encoder hardware
sensor.init();
// hardware interrupt enable
sensor.enableInterrupts(doA, doB, doC);
Serial2.println("Sensor ready");
_delay(1000);
}
void loop() {
// iterative function updating the sensor internal variables
// it is usually called in motor.loopFOC()
sensor.update();
// display the angle and the angular velocity to the terminal
Serial2.print(sensor.getAngle());
Serial2.print("\t");
Serial2.println(sensor.getVelocity());
delay(100);
}
Ok, after a bit of testing and adding a debug-LED I figured out, that Serial2 needs a bit more encouragement.
I had to add
#define SERIAL_UART_INSTANCE 2
#define PIN_SERIAL_RX PA15
#define PIN_SERIAL_TX PA14
to make the code pass the Serial2.begin(115200);
Now the code runs through the loop and the LED blinks nicely, but all the Serial2.print lines donât do anything.
The chip is able to use single wire UART (TX only), but does the FTDI adapter too?
Hmmm does it expect pin names here or Arduino pin numbers?
Have you tried using PA_15 rather than PA15?
I copied these lines directly from the stm32duino forum and other examples use same style of pin names.
Where would I find arduino pin numbers? Are they the same as the real ones?
Tomorrow Iâll solder the RX2 wire. Itâl be a bit of a surgery, but then I have a complete UART.
Another option would be a i2c LCD as debug channel, but thatâs plan B
I didnât understand what you described there. Itâs all about platformio and python and hacking the st-linkâŚway over my head.
Itâs a way to send data from the ARM microprocessor using the SWD debug channel instead of a serial port. Itâs faster than Serial, and doesnât require additional serial pins on the board, nor a VCP serial port on the PC.
SWD is the protocol used by STLink and other debugging tools, so by using RTT you donât need any other connection. It takes a bit of time to understand how it works, but once you do, it works for every ARM device and over the existing SWD lines
Arduino pin number: 7 or A4 (examples)
STM32 define for Arduino pin number: PB4, PA9, PF0 (examples)
STM32 PinName: PB_4, PA_9, PF_0 (note the underscore)
When using the defines like PIN_SERIAL_RX, sometimes it likes PinNames. Thatâs what I meant.
Where are you putting these #defines? they canât just go in your code, they need to go somewhere where the framework will pick them up.
To make VCP work, I usually just do this in my platformio.ini:
-DSERIAL_UART_INSTANCE=2
This will activate hardware serial on USART2, and make it available via Ardunio âSerialâ (no â2â!)
Then I can use the standard Arduino âSerialâ object to print to the ST-Link VCP.
On some boards you also have to set the serial pins like you show.
Is it the STM32F030C8 ? PA_14/PA_15 are correct for USART2 that MCU.
I think, I take a break of this project.
To me it seems, the whole generic STM32F0 stuff in Arduino isnât really Arduino-ready.
Everywhere I look, I see platfomio-here; platformio-thereâŚ
I tried various suggestions, the last thing I did was trying SoftwareSerial.
That seem to have bricked my MCU, because after flashing I canât connect to it anymore.
I tried to erase the chip with ST-Link tool as I did before, but no connect.
As a last attempt, I upgraded the firmware of the ST-Link itself. Now it doesnât work at all!
I guess, Iâll get me a nice ESP32 based MKS Dual FOC+ and try to brick that too
Using any kind of board in Arduino IDE for which there isnât a proper board file set up is very difficult.
ArduinoIDE provides no insight into whatâs going on, and no way to configure anything on a project by project basis.
While their philosophy makes it simple to write and download âbaby sketchesâ, any actual real-world problem quickly has requirements you canât directly configure in ArduinoIDE, and then it becomes harder to use than other options.
It is âover-user-friendlyâ software, that only serves beginner users, but even intermediate users quickly hit its limits.
When working with custom boards or the generic board variants, it is 1000% easier in PlatformIO. In PlatformIO you can bring up a new board without having to do any modifications in the framework files, everything can reside within your projectâŚ
Thatâs not to say that PlatformIO makes the job easier or offers any support for configuring unknown boards, but at least it does not make the job unnecessarily hard by preventing access to options and configuration.
I donât want to be discouraging, but Iâd say, TBH, that the number of concerns and tasks involved in bringing up a new board for which there is no good board definition is really high, and will be very difficult if youâre not already quite familiar with embedded development in general, Arduino framework specifically, and further have good knowledge of the hardware and platform variant youâre working with.
My aim is to add custom board variants for all the supported hoverboard controllers.
But this will take time, and that means I either have to own all those boards and do the job myself, or someone else has to contribute.
For now I am focusing on a single controller.
I think that would be really great!
If you would like a home for them, there is already this project: GitHub - simplefoc/simplefoc_arduino_boards: Arduino board vendor files for SimpleFOC boards
But perhaps youâre planning to create your ownâŚ
Thanks for sharing this, I didnât know about it.
I havenât looked at the details how this works yet.
My case is a bit complicated as there are stm32 and gd32 boards, so different platforms.
One can combine different platforms in the same vendor package, IIRC.
Happy to help once youâre ready, if youâd like
Sure, much appreciated.
The only problem is that you cannot identify most the controllers by brand or model lol
So I need to thing about how to help people identify the variants.
Weâll train a classifier to recognize them by picture
I thought about it
or maybe a sketch that can try to identify the board variant
There is a generic stm32F0 class and I selected the more specific stm32f030x8 board.
Is it asked too much to have a working serial port? Even worse, I picked an example program for this MCU and it bricked my boardâŚ
Sorry for the rant, I donât blame anyone of the sFOC team.
On the sFOC docs page it looks so easy, every STM32 MCU is supported and all the examples are made for arduinoIDE.
You cannot brick those chips like that.
Worst I saw is that someone altered the configuration of pa13/pa14 and had to do that