RoboDurden / Hoverboard-Firmware-Hack-Gen2.x

with different defines_2-x.h for different board layouts :-) Compiles with Keil version 6
GNU General Public License v3.0
87 stars 29 forks source link

PlatformIO support :-) #93

Open RoboDurden opened 1 month ago

RoboDurden commented 1 month ago

Thanks @hoverboardhavoc for his pull request https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x-GD32/pull/3

Maybe adding stm32F103 support now has become closer. adding this to platformio.ini might somehow do the trick:

[env:STM32F103RC]
platform = ststm32
//platform_packages = framework-arduinoststm32@https://github.com/Candas1/Arduino_Core_STM32.git
board = genericSTM32F103RC
debug_tool = stlink
upload_protocol = stlink
framework = arduino
build_flags = -g -ggdb
              -D $PIOENV
              -D GD32F103
              -D TARGET=2
lib_deps = 
lib_archive = false

taken from https://github.com/RoboDurden/Split_Hoverboard_SimpleFOC/blob/main/platformio.ini

RoboDurden commented 1 month ago

Concerning clock speed, this might help:

build_flags =
    -g -ggdb
    -D __PIO_DONT_SET_CLOCK_SOURCE__
    -D __SYSTEM_CLOCK_48M_PLL_IRC8M_DIV2=48000000
    -D $PIOENV
Electron-py commented 1 month ago

Getting Error: This board doesn't support spl framework!, someone can help?

Electron-py commented 1 month ago

My platformio.ini file: [platformio] src_dir = Src include_dir = Inc

[env] platform = https://github.com/CommunityGD32Cores/platform-gd32.git platform_packages = framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git

[env:genericSTM32F103C8] platform = ststm32 board = genericSTM32F103C8 framework = spl build_flags = -D GD32F130 -D TARGET=1 -D USE_HSI_CLOCK -DSTM32F100xB -DSTM32F10X_MD

RoboDurden commented 1 month ago

well i guess that if you change the platform to stm32, you should also overwrite the platform_packages ?

Maybe try this blink first to reslove the STL error: https://github.com/platformio/platform-ststm32/tree/master/examples/spl-blink

Electron-py commented 1 month ago

Found this: https://github.com/CommunityGD32Cores/gd32-pio-spl-package

RoboDurden commented 1 month ago

Yes and you have it already selected in your [env] section. But in the (overwriting ?) [env:genericSTM32F103C8] section you switched back from gd32 to stm32 :-/

RoboDurden commented 1 month ago

Did you test my links for the original platfromio.ini , that works for me:

https://github.com/platformio/platformio-home/issues/42 https://github.com/platformio/platformio-home/issues/1859

Electron-py commented 1 month ago

I'm trying to

Electron-py commented 1 month ago

"Please specify platform for 'genericGD32F130C8' environment"

RoboDurden commented 1 month ago

If you are running Windows, check your platformIO folders. Mine are found in

C:\Users\PAN CF-LX6.platformio\packages C:\Users\PAN CF-LX6.platformio\platforms

Electron-py commented 1 month ago

Installed package but i still don't know how do i 'specify platform'?

RoboDurden commented 1 month ago

pio

RoboDurden commented 1 month ago

pio2

Electron-py commented 1 month ago

can you send me the gd32 file inside platform folder and the framework one?

Electron-py commented 1 month ago

platforms 06_09_2024 15_54_04

Electron-py commented 1 month ago

platformio ini - Untitled (Workspace) - Visual Studio Code 06_09_2024 15_57_39

RoboDurden commented 1 month ago

https://robosoft.de/forums/hover/

but these files should be auto downloaded when you compile the project. Try to clear and clean the project..

I-hate-2FA commented 1 month ago

will we get online editor for gen2 anytime soon

Electron-py commented 1 month ago

Can't even clean because of this "Please specify platform". Sorry if I'm not understanding something

Electron-py commented 1 month ago

I have to go. If you find a solution...

RoboDurden commented 1 month ago

I am not at all experienced with PlatformIO. I also only used it for one project two years ago. If you do no longer use PIO for this other project of yours, i would uninstall and reinstall PIO..

Electron-py commented 1 month ago

ok

RoboDurden commented 1 month ago

and google your errors. https://www.google.com/search?client=firefox-b-d&q=%22Please+specify+platform+for

Electron-py commented 1 month ago

alredy tried that

RoboDurden commented 1 month ago

@Electron-py actually i do not understand why you want to compile for a [env:genericSTM32F103C8] . You have a Gen2.1.1 which is GD32F130

When i add for the Gen2.2.t boards

[env:genericSTM32F103C8]
platform = ststm32
board = genericSTM32F103C8
framework = spl
build_flags = -D GD32F103
                -D TARGET=1
                -D USE_HSI_CLOCK
                -DSTM32F100xB -DSTM32F10X_MD

i get the Error: This board doesn't support spl framework!

that might help: https://github.com/platformio/platform-ststm32/issues/13#issuecomment-378051575

my genericSTM32F103C8.json is in C:\Users\PAN CF-LX6\.platformio\platforms\ststm32\boards

But i failed at step 2. This is my stm32f1 folder: pio3

the startup file needs to be changed in target.h line 48

    #include "startup_stm32f10x.c"
    //#include "gd32f10x.h"

But that is not working

Src\../Inc/../Inc/target.h:48:11: fatal error: startup_stm32f10x.c: No such file or directory
  #include "startup_stm32f10x.c"
           ^~~~~~~~~~~~~~~~~~~~~

And as a Keil/PIO beginner i do not really know how #include "gd32f10x.h" works successfully..

Electron-py commented 1 month ago

I made it work. Now i have an error when compiling about RemoteCallback being defined more times.

RoboDurden commented 1 month ago

I made it work.

What did you make work ? And how did youmake it work ??

RemoteCallback is declerated in remote.h once.

Electron-py commented 1 month ago

I found a pakcage for gd32 and now i don't have enviroment errors anymore

RoboDurden commented 1 month ago

this is not very instructive :-( You found the package under your kitchen table ? Still trying to compile stm32f103 ?? platformio.ini ???

hoverboardhavoc commented 1 month ago

build_flags = -g -ggdb -D PIO_DONT_SET_CLOCK_SOURCE -D __SYSTEM_CLOCK_48M_PLL_IRC8M_DIV2=48000000 -D $PIOENV

I tried this

[env:genericGD32F130C8]
board = genericGD32F130C8
framework = spl
build_flags = -D GD32F130
              -D TARGET=1
              -g -ggdb
            -D __PIO_DONT_SET_CLOCK_SOURCE__
            -D __SYSTEM_CLOCK_48M_PLL_IRC8M_DIV2=48000000
            -D $PIOENV

and this:

[env:genericGD32F130C8]
board = genericGD32F130C8
framework = spl
build_flags = -D GD32F130
              -D TARGET=1
            -D USE_HSI_CLOCK
            -DSTM32F100xB
            -DSTM32F10X_MD

but the beeper tones are still lower than they should be

I-hate-2FA commented 1 month ago

you need to use proper stm32f103 core if you want to set system clock

RoboDurden commented 1 month ago

based on

//----------------------------------------------------------------------------
// SysTick_Handler
//----------------------------------------------------------------------------
void SysTick_Handler(void)
{
  msTicks++;
}

in it.c you should be able to let the buzzer beep (or let red led blink) in 10 second intervals. Then measure the time it really takes and we might be able to see at how many Mhz the cpu is running. This might give us a clue why the clock is wrong.

And if the motor is still running nicely, we might live with the wrong cpu clock and scale the beeper tone .. But i guess that the uart baud rate would also have to bee scaled :-/

RoboDurden commented 1 month ago

This platformio.ini did make the GD32F130 run with correct clock. Serial communcation was working. https://github.com/RoboDurden/Split_Hoverboard_SimpleFOC/blob/main/platformio.ini

I-hate-2FA commented 1 month ago

it is very clear, you are using gd32f103 core, its normal that clock cannot be configured, its same for mm32f103, the clock will be lefty as default

Electron-py commented 1 month ago

I installed this: https://github.com/CommunityGD32Cores/platform-gd32 in PlatformIO for GD32 support and this is my platformio.ini file: [platformio] src_dir = Src include_dir = Inc

[env] platform = https://github.com/CommunityGD32Cores/platform-gd32.git platform_packages = framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git

[env:genericGD32F130C8] board = genericGD32F130C8 platform = gd32 framework = spl build_flags = -D GD32F130 -D TARGET=1

Now the enviroment works. The error that I have is that the RemoteUpdate function is defined multiple times: One in remoteUartBus.c and one in remoteUart.c . When Platform IO tries to link those files gives errors because when it links them there are two RemoteUpdate functions. It needs to be defined only once or, if they are two separate functions, to rename it in one file. remoteUartBus c remoteUart c

Electron-py commented 1 month ago

I made it compile! I simply renamed the conflicting functions in remoteUart adding a 2 and now it compiles. working

Electron-py commented 1 month ago

But the beeping is wrong.

Electron-py commented 1 month ago

https://github.com/user-attachments/assets/04be07be-f72d-448d-8dc0-405a6ee89684

hoverboardhavoc commented 1 month ago

based on

//----------------------------------------------------------------------------
// SysTick_Handler
//----------------------------------------------------------------------------
void SysTick_Handler(void)
{
  msTicks++;
}

in it.c you should be able to let the buzzer beep (or let red led blink) in 10 second intervals. Then measure the time it really takes and we might be able to see at how many Mhz the cpu is running. This might give us a clue why the clock is wrong.

And if the motor is still running nicely, we might live with the wrong cpu clock and scale the beeper tone .. But i guess that the uart baud rate would also have to bee scaled :-/

I added some logic to turn on the led for 50ms every 5 seconds: https://github.com/hoverboardhavoc/Hoverboard-Firmware-Hack-Gen2.x-GD32/tree/hoverboardhavoc/debug_clock

In the videos below which show hoverboardhavoc/debug_clock running, you can see the LED flashing every five seconds but the behavior of the motor and buzzer is different. The tones are different pitch and the motor makes a kind of metallic sound on the Platform IO build

Keil:

https://github.com/user-attachments/assets/103863e0-74b4-4327-a064-ee0be5972f09

Platform IO:

https://github.com/user-attachments/assets/05b87db9-5f98-4c3c-9b65-fb16dd42c303

Electron-py commented 1 month ago

@hoverboardhavoc i can confirm. Don't know why it makes that metallic sound.

Electron-py commented 1 month ago

Maybe it's a different implmentation for PWM. idk

RoboDurden commented 1 month ago

One in remoteUartBus.c and one in remoteUart.c .

As I said, you must only uncomment ONE RemoteXy in config.h

Is uart working with 19200 baud ?

Bldc is running from a 16 kHz interrupt that is triggered when ADC dma has finished, if I remember correctly.

Add a counter and blink led every 160000 counts to that function in bldc.c to verify that it is indeed 16 kHz...

This firmware has the very simple block communication only. If you set the speed to 1000 = 100% pwm duty cycle, then the 16 kHz is the only thing that should affect motor sound.

I think that the buzzer tone is also generated in that calculateBldc function !

Electron-py commented 1 month ago

One in remoteUartBus.c and one in remoteUart.c .

As I said, you must only uncomment ONE RemoteXy in config.h

Right, sorry. Now it compiles with the original void names.

Electron-py commented 1 month ago

What am I doing wrong? Using REMOTE_DUMMY

https://github.com/user-attachments/assets/b6eadf11-398a-4bf0-8ed2-0a405b0f0ff2

RoboDurden commented 1 month ago

Looks like not all three hall sensors working . Are the three led blinking with always two overlapping ?

But it might be the wrong 16 kHz timing of calculateBldc that needs your push with a hand at low speed to make the motor start spinning

Electron-py commented 1 month ago

But even when it starts spinning it doesn't want to. It seems like there are only two fases. And my hoverboard has only red and green light, not orange.

RoboDurden commented 1 month ago

With a Gen2.1.1 you should have a two color led module and a three color led module. And if not you could reasign the up-led or down-led to be the orange one in your defines file. Was the motor spinning correctly with the precompiled dummy ? does it spin correctly with remoteUart and arduino/esp spinning forward and backwards ?

Electron-py commented 1 month ago

I'll try with uart

Electron-py commented 1 month ago

nope. still wrong

RoboDurden commented 1 month ago

i can not really help you. With all your short one liners i never really know what you are doing :-(