Hoverboard main board with simpleFOC

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?

1 Like

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

You could try this also

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

2 Likes

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 :sob:

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.

1 Like

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.

1 Like

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…

1 Like

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 :sweat_smile:

I thought about it :sweat_smile:
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