Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlatformIO support :-) #93

Open
RoboDurden opened this issue Sep 4, 2024 · 54 comments
Open

PlatformIO support :-) #93

RoboDurden opened this issue Sep 4, 2024 · 54 comments

Comments

@RoboDurden
Copy link
Owner

Thanks @hoverboardhavoc for his pull request RoboDurden/Hoverboard-Firmware-Hack-Gen2.x-GD32#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
Copy link
Owner Author

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
Copy link

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

@Electron-py
Copy link

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
Copy link
Owner Author

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
Copy link

@RoboDurden
Copy link
Owner Author

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
Copy link
Owner Author

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

platformio/platformio-home#42
platformio/platformio-home#1859

@Electron-py
Copy link

I'm trying to

@Electron-py
Copy link

Electron-py commented Sep 6, 2024

"Please specify platform for 'genericGD32F130C8' environment"

@RoboDurden
Copy link
Owner Author

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
Copy link

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

@RoboDurden
Copy link
Owner Author

pio

@RoboDurden
Copy link
Owner Author

pio2

@Electron-py
Copy link

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

@Electron-py
Copy link

platforms 06_09_2024 15_54_04

@Electron-py
Copy link

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

@RoboDurden
Copy link
Owner Author

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
Copy link

will we get online editor for gen2 anytime soon

@Electron-py
Copy link

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

@Electron-py
Copy link

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

@RoboDurden
Copy link
Owner Author

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
Copy link

ok

@RoboDurden
Copy link
Owner Author

RoboDurden commented Sep 6, 2024

@Electron-py
Copy link

alredy tried that

@RoboDurden
Copy link
Owner Author

@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: platformio/platform-ststm32#13 (comment)

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
Copy link

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

@RoboDurden
Copy link
Owner Author

RoboDurden commented Sep 6, 2024

I made it work.

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

RemoteCallback is declerated in remote.h once.

@Electron-py
Copy link

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

@RoboDurden
Copy link
Owner Author

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

@hoverboardhavoc
Copy link

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
Copy link

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

@RoboDurden
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link

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
Copy link

Electron-py commented Sep 7, 2024

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
Copy link

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

@Electron-py
Copy link

Electron-py commented Sep 7, 2024

But the beeping is wrong.

@Electron-py
Copy link

VID20240907092807.mp4

@hoverboardhavoc
Copy link

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:

1.mp4

Platform IO:

2.mp4

@Electron-py
Copy link

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

@Electron-py
Copy link

Electron-py commented Sep 7, 2024

Maybe it's a different implmentation for PWM. idk

@RoboDurden
Copy link
Owner Author

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
Copy link

Electron-py commented Sep 7, 2024

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
Copy link

What am I doing wrong? Using REMOTE_DUMMY

VID20240907100410.mp4

@RoboDurden
Copy link
Owner Author

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
Copy link

Electron-py commented Sep 7, 2024

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
Copy link
Owner Author

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
Copy link

I'll try with uart

@Electron-py
Copy link

nope. still wrong

@RoboDurden
Copy link
Owner Author

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

@Electron-py
Copy link

Electron-py commented Sep 7, 2024

I tested with Uart with esp32 and its the same of the video i sent.

@RoboDurden
Copy link
Owner Author

By the way, there is a great visualization tool that also supports GD32F130: https://www.st.com/en/development-tools/stm-studio-stm32.html
If i remember correctly, you have to compile in debug mode, then choose the generated .elf file, and then you can log every global variable. No need to led an led blink..

@Electron-py
Copy link

Is there a way to make the motors spin faster?

@I-hate-2FA
Copy link

1.use higher voltage
2.use field weakening

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants