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
85 stars 28 forks source link

Gen2.3.1 (ex2.7) = GD32E230C8T6 #16

Open RoboDurden opened 1 year ago

RoboDurden commented 1 year ago

thanks to @WizzardDr who added this new layout which needs a new Keil compiler target: https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/pull/15

As i am not really experienced at all with this Keil platform, help from anybody would be appreciated :-)

I see that this board has three mosfet gate driver chips instead of analog gate drivers like the original 2.0. Be aware that this firmware here was written for the 2.0 layout where the low side mosfets are turned on with a LOW signal !! With layouts having gate driver chips however, the on-signal might be HIGH for both high-side and low-side mosfets. If this is not correctly applied, all three half-bridges will short cut and burn !!

When testing a new layout it is mandatory to use a CC constant current power supply with only 1-2 A max !!!

WizzardDr commented 1 year ago

I think it is a similar thing. I have downloaded GD32E23x Firmware Library from that video. With the change to __SYSTEM_CLOCK_72M_PLL_IRC8M_DIV2 it works and the debug gets to main()!!!!!!

Now if I can figure out the target differences I should be able to get the hoverboard firmware to work!!!

WizzardDr commented 1 year ago

YAY!!!! I'm now in main()

https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/issues/16#issuecomment-1709849075 🤔

nvic_vector_table_set(NVIC_VECTTAB_FLASH,VECT_TAB_OFFSET); 🤔 It can't access the memory if it is protected...

image

This ain't the solution to undefined FMC_WS... This is:

image

The memory was protected 🤣

The self latch is working.... now to test the main code 🤞

WizzardDr commented 1 year ago

Motor noise and some holding torque... high current draw without spinning though... getting there!

WizzardDr commented 1 year ago

YAY It works!!! I had to connect the yellow motor wire to BH_PIN, BL_PIN and the blue motor wire to YH_PIN, YL_PIN, I suspect it is to do with this https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/issues/16#issuecomment-1709605500

WizzardDr commented 1 year ago

I've been looking through the code. There is #ifdef MASTER in main() that covers most of the code. where is the slave's code?

RoboDurden commented 1 year ago

8:15, Good morning. It is in commsmasterslave.c. A slave is a slave :-/

Great job you are doing !!!

WizzardDr commented 1 year ago

Good Morning. Everything in the while(1) in main() is in the #ifdef MASTER. How does it get called? Thx

WizzardDr commented 1 year ago

Oh, from commsmasterslave.c I think I have found it. Is it all via hardware interrupt DMA13?

RoboDurden commented 1 year ago

Yes, it.c i think is where all the magic begin. main() is called by the when the hardware is ready.

WizzardDr commented 1 year ago

I think the problem that I have with setting the option bytes via SWD is that the ST-Link programs try to set the lock byte levels 0, 1 and 2 with 0xAA, 0xBB and 0xCC whereas the GD32E32x needs 0xA5 for no protection. Due yo any value except 0xA5 or 0xCC: Protection level low and 0xCC: Protection level high the ST-Link Utility always locks it.

There may be a way to set 0xA5 via SWD using a different method, maybe with OpenOCD (I don't have a Linux OS to test with).

For now I am going to do the same as I did with the master to program via UART.

I lifted the Boot0 Pin so it isn't tied to GND, and added a 10k pull-down resistor.

IMG_20230917_204815.jpg

RoboDurden commented 1 year ago

this looks dangerous. Is that neccessary to uplaod via uart ?

RoboDurden commented 1 year ago

I do not have any ideas for this byte unlock problem. I also do not fully understand what you want to say. Maybe STM32CubeProgrammer has more options to set the bytes ?

WizzardDr commented 1 year ago

The "Read Unprotect (MCU)" in the STM32CubeProgrammer is the only way I have managed to reset the lock byte so far, it is just a workaround, the correct solution is to have the SWD programming software set the byte correctly.

I'm sure if I had a GD-Link their software is setup to set the byte correctly, or maybe OpenOCD can do it via the ST-Link but I don't know.

The problem is the Software thinks the chip is an STM32F1 variant since there isn't a STM32E23. So it tries to set the byte as though it is an STM32F1.

The required values for unlocked and locked are different.

The GD32E230 image

The STM32F1 image

So when the value is set to 00 it think it failed to unlock the chip but in fact it has locked the chip since the value isn't 0xA5 (The GD32E23 unlock value).

RoboDurden commented 1 year ago

Sorry i am to tired now to understand. I think i will not be able to help you. When you finally have found the best possible ways for other user to flash such a 2.7 board, please make a step by step tutorial.

WizzardDr commented 1 year ago

ATM the easiest way for other user would be to just buy a GD-Link and use "GD-Link Programmer.exe" which is very similar to "STM32 ST-LINK Utility.exe".

If I find a way to use an ST-Link without first unlocking via UART I will share.

maybe something like this https://www.aliexpress.com/item/1005004746411866.html https://www.aliexpress.com/item/1005004576805005.html

RoboDurden commented 1 year ago

links not working for me. page not found. 23:53 here, good night.

WizzardDr commented 1 year ago

Donno why. They are these

image

image

Candas1 commented 1 year ago

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/issues/55

WizzardDr commented 1 year ago

🤔Windows OpenOCD thanks. At some point, I'll see if I can use that version of OpenOCD standalone to unlock the MCU

RoboDurden commented 1 year ago

@WizzardDr could you post the exact model number so other users could see from a hoverboard photo that 2.7 boards are inside. I took this screenshot from your little video: grafik

happytm commented 11 months ago

Can anyone confirm whether layout 2.7 is working properly with this firmware? If so, someone post instructions to load the firmware using .bin file.

RoboDurden commented 11 months ago

Chances are good that this binary makes one motor spin smoothly:

https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/blob/main/HoverBoardGigaDevice/BinariesToTest/hoverboard%202.7%20single%20Dummy.bin

But you should test with a 2A cc constant current power supply or dcdc step down converter.

happytm commented 11 months ago

Thank you.

RoboDurden commented 11 months ago

If you confirm sooth spinning I will upload more binaries that let you control the motor from an Esp or Arduino. Or you compile and flash yourself by installing the Keil Ide.

happytm commented 11 months ago

Ok.Thanks.

andyshmandy commented 10 months ago

It turns out that I have a hoverboard with a circuit boards that are slightly different than this one. Maybe an order or newer version but the processor and almost everything else is identical. This is a working hoverboard and happens to be the one that the kids were using (but haven't in a while) so I may claim it. Anyway, if I understand this thread properly, the only issue with this board is that it is difficult to program using the standard ST-Link v2 using the standard header. I looked at the pinout and it appears to be identical to the GD32F130CX. In theory, could I replace the processor on this board with the GD32F130 and program it using the ST-Link? The other board that I was going to try to use is (see issue https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/issues/38). I fried several MOSFETs and when attempting to remove the broken ones, I destroyed several of the traces around the through holes. I also lost a surface mount resistor. My soldering skills aren't great. To be fair, its my desoldering skill that sucks. Anyway, I have replaced processors on boards using a heat gun with success. Thoughts?

andyshmandy commented 10 months ago

Here's a photo of my board: image

I will try to get a better photo in the daylight using my DSLR tomorrow (If it is sunny) I would really like to get something going and I now have a constant current power supply that I can connect so I don't end up frying anything. Yay!!

happytm commented 9 months ago

I found very easy to use new IDE which support this chip.

https://www.embeetle.com/#supported-hardware/giga/microcontrollers/gd32e230c8t6 https://www.youtube.com/watch?v=J5oNJL0QxNU

Thanks.

RoboDurden commented 9 months ago

I do not see an integrated development editor at that link. And we do not need another ide for this MCU either.

happytm commented 9 months ago

So do you have solution for this MCU? Reading this issue and others I could not find a solution to flash GD32E230C8T6.

There is a link on home page to download IDE. https://www.embeetle.com/#home

Thanks.

RoboDurden commented 9 months ago

This 2.7. should be ready for production. I only offer a test binary because @WizzardDr sadly went silent so I do not know if my general changes to the code work nicely with his 2.7. board .

How to flash the binary can be troublesome. But the code and the Keil ide should not be a problem for the gd32e230

sancheza9 commented 5 months ago

I’m fairly new to all of this but may have a board matching this I can test with. Just walk me through what is needed. I believe I successfully unlocked the mcu already. Included is a photo of my board IMG_5168 IMG_5169

RoboDurden commented 5 months ago

Yours might be a different version of 2.3.1 but if you have a 2A cc power supply you could flash this test binary

https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/blob/main/BinariesToTest/hoverboard%202.3.1%20master%20Dummy.bin

When motor is spinning nicely I will upload binaries with Uart and uartBus control.

The 2A charger might also serve as a 2A cc power supply.

RoboDurden commented 5 months ago

Use autoflash.bat or install Keil and compile/flash yourself.

dkvinyls commented 4 months ago

I've managed to flash the dummy bin to this board using the windows build of OpenOCD (also used this to unlock as ST-Link bricked the board), I can now hear the motor trying to ramp up/down when I turn it on but I don't think my 1.5a PSU is powerful enough to actually turn the motor. I'm trying to use the 42v charger as its all I have access to right now.

RoboDurden commented 4 months ago

1.5A at 26 volt should be enough to spin the motor ! Make sure the mosfets do not get hot !!! If they do get hot with the 1.5A original charger, the pin definitions might be wrong or the deadtime when switching the mosfet are too big.

dkvinyls commented 4 months ago

I'm not well versed in this stuff, I thought the PSU would be enough as well so you might be right. FET's are not hot, the heat sink feels a little warm, around 30 degrees Celsius at a guess. Vid here, I laid it on the table as you can hear the motor vibrating then. Obviously I know the axle should be fixed to let the wheel spin in normal operation.

https://youtube.com/shorts/bdcZsKIzDhc

I-hate-2FA commented 4 months ago

it is same problem as the old1.20 aka invert lowside

I-hate-2FA commented 4 months ago

or maybe hall sensor problem, try swap phase cable 6 combination

I-hate-2FA commented 4 months ago

try to drive it sensorless in autodetect, if it still vibrate then it is invert lowside problem, if it rotate normally then it is hall sensor problem

dkvinyls commented 4 months ago

try to drive it sensorless in autodetect, if it still vibrate then it is invert lowside problem, if it rotate normally then it is hall sensor problem

Do I just disconnect the hall sensor cable or do I need to alter something in firmware to enable autodetect?

I-hate-2FA commented 4 months ago

you need to flash universal firmware

RoboDurden commented 4 months ago

You can be happy that the motor is not spinning. YOU HAVE TO MOUNT THE MOTOR ! If you have Keil installed, then watch my latest autodetect video: https://youtu.be/X7bpMX8tCE8 In the battery_voltage mode, the motor is rotating without the need of hall sensors. I agree with @I-hate-2FA that

    // Set up the output channel parameter struct
    timerBldc_oc_parameter_struct.ocpolarity        = TIMER_OC_POLARITY_HIGH; //HIGH: CHx_O is the same as OxCPRE , LOW: CHx_O is contrary to OxCPRE
    timerBldc_oc_parameter_struct.ocnpolarity   = TIMER_OCN_POLARITY_LOW; //HIGH: CHx_ON is contrary to OxCPRE, LOW: CHx_O is the same as OxCPRE

in setup.c might be the problem.

dkvinyls commented 4 months ago

I don't have it installed, I'm away until Tuesday but I'll pick it back up when I'm back, so don't think I've gone quiet in the meantime.

I did have it mounted to a block of wood but it was impossible to get a video of what I could feel was happening, it will be mounted again for my first test with new firmware.

RoboDurden commented 4 months ago

The gd32e230 autodetect binaries are up to date: https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x/tree/main/BinariesToTest But no one has ever tested autodetect on a e230 target :,(

dkvinyls commented 4 months ago

Do you happen to have a copy of the ESP32 Repeater firmware, the link on the autodetect page is dead

RoboDurden commented 4 months ago

https://github.com/RoboDurden/Hoverboard-Firmware-Hack-Gen2.x-GD32/tree/main/Arduino%20Examples/Autodetect

ITBETOITALL commented 4 months ago

Man guys are really smart. I am completely brand new to this whole thing. I'm still trying to figure out how to wire my ST link to the board. I have been using chat gpt to help me. However, that appears to be working with a toddler. Consistently looking for a brand new toy. I have already Soldered in the four headers. I think that they're called in the four holes in the board. My end use is I'm trying to make like a 4 wheel drive platform that i can control by an RC controller.

RoboDurden commented 4 months ago

Rc Controller = stupid fun project :-/

ITBETOITALL commented 4 months ago

Would you suggest. RC to ESP32 to Motherboard UART  or RC to ESP32 to Arduino Uno 3 to Motherboard? You appear to be the tube god for these firmware hacks. Thank you for doing what you do. Sincerely,  

Christopher