lucysrausch / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.
GNU General Public License v3.0
702 stars 407 forks source link

New motherboard YST-DXT-J20 V4 with "ATERY" AT32F403RCT6 #97

Open cloidnerux opened 5 years ago

cloidnerux commented 5 years ago

Hello,

I bought a hoverboard mainboard off ebay in order to use this firmware, hover on arrival I realized that this mainboard seems to be newer and different to the ones currently used. It features a "AT32F403RCT6" which seems to be a Chinese STM32F103RCT6 clone with faster clock speed, a M4F core, more peripherals, and more RAM. As far as I could see it, it should be possible to compile the current firmware for the new controller. 2019-05-25 11 19 24

Also, it seems to have dedicated gate driver ICs instead of the discrete ones, some of the connectors are different and the layout changed. They also changed the pinout of the SWD connection. I try to reverse engineer the layout as I could not find anything on the internet at the moment.

Does anybody already have any experience with these boards?

TomTinkering commented 5 years ago

Allright, posted an update on @cloidnerux's fork. This issue should probably be closed as the latest discussions have been unrelated to the original issue?

EFeru commented 5 years ago

@TomTinkering

Please see below the correct mapping of current phases thanks to STM Studio logging (amazing tool). (The mapping is from my STM32 board). Also the same comment can be found here #41.

Data below is real measured data (not simulation).

LEFT motor (long wired motor)

Motor_LEFT_SIN3

Mapping: Phase A current: adc_buffer.rl1 (flipped) Phase B current: adc_buffer.rl2 (flipped)

RIGHT motor (short wired motor)

Motor_RIGHT_SIN3

Mapping: Phase B current: adc_buffer.rr1 (flipped) Phase C current: adc_buffer.rr2 (flipped)

Important Note: The sign of all phase current measurements is flipped:

juodumas commented 5 years ago

@TomTinkering / @EmanuelFeru Sorry to bother you, but a question about AT32F403RCT6 boards - looks like they are becoming more popular.

So my question: if you manage to implement FOC control, will it be portable to AT32F403RCT6 (i.e. no hw limitations)?

I have ordered 2 YST boards with GD32F103 (according to product photo), but seller sent me AT32F403RCT6...

EFeru commented 5 years ago

@juodumas

So my question: if you manage to implement FOC control, will it be portable to AT32F403RCT6 (i.e. no hw limitations)?

Yes, it will be portable. From HW point of view I will use the measured Phase currents, which are available in YST board too. And there will be more calculations, but this was expected.

This board that I ordered from Aliexpress was a GD board. Shipping was fast and quality was also good. I recommend.

lacrimosa2k2 commented 4 years ago

Hello, i have the same board and trying it to flash, but whatelse i am doing i cannot connect with a st-link v2 to the board. when i try to connect with the st-utility it beeps and reset i cant find any information about that, what do i wrong?

cloidnerux commented 4 years ago

Hi,

did you read my information in my fork? https://github.com/cloidnerux/hoverboard-firmware-hack The SWD pins have a different order. You also have to patch something to make the ST-Link work with OpenOCD and the AT32.

Lastly you have to hold the power button to not power cycle the system during a MCU reset.

lacrimosa2k2 commented 4 years ago

Hi,

did you read my information in my fork? https://github.com/cloidnerux/hoverboard-firmware-hack The SWD pins have a different order. You also have to patch something to make the ST-Link work with OpenOCD and the AT32.

Lastly you have to hold the power button to not power cycle the system during a MCU reset.

i have a brige in the power button that is correct? yes that i found out that the connectors on the board different.

in your fork you write "Or use the Windows ST-Link utility" thats old from the stm32?

i have try it with the st tool on windows. i testet it with the st-link under linux, but i dont understand how to patch the openocd/st-link can you explain me this? or files that ready to compile? st-link -- probe brings only this Found 1 stlink programmers serial: 343d050232123853354b4e00 openocd: "\x34\x3d\x05\x02\x32\x12\x38\x53\x35\x4b\x4e\x00" flash: 0 (pagesize: 0) sram: 0 chipid: 0x0000 descr: unknown device

IzidorM commented 4 years ago

Just wondering. Is anybody replaced the AT32F403RCT6 with the old stm32f103 on the new board?

Rettigran commented 3 years ago

hi i am building one wheels, connecting both wheels toghter to be controlled by same dougther board . before i used the ARM controller yst dxt j20 v5.5 , and connected the 2 dougther bords together by connecting the green and yellow wires on both 4wire connectors. i just got this new controller , and could not find the wiring diagram. does anybody has one? has anybody connected this type in this way?

123JRM commented 3 years ago

I was not able to program the AT32. Like Izidor I am tempted to just replace this AT with an ST chip and be done with it. it's a lot easier for me to do some SMD rework than fight with a chip for which there is little documentation. checking if the pins match .. anyone do this yet ?

123JRM commented 3 years ago

the parts are physically interchangeable.
http://www.arterytek.com/download/DS_AT32F403_V1.06_EN.pdf page 27
https://pdf1.alldatasheet.com/datasheet-pdf/view/499696/STMICROELECTRONICS/STM32F103RCT6.html page 26 I may give it a go.

Brnpimenta commented 3 years ago

Hello! Anyone flashed and reprogramed using st-link?

Velix762 commented 3 years ago

Hello! I have the same board and i can't figure it out how to flash it . I got it connected to my pc and stlink utility sees it but can't connect . My question is does anybody know of a video or a step by step quide how to set it up . (i have never used OpenOCD or gcc-arm-none-eabi binary)

Brnpimenta commented 3 years ago

Velix762, I'm still stuck on this.

cloidnerux commented 3 years ago

You have to compile your own version of OpenOCD with the path described here: https://github.com/bipropellant/bipropellant-hoverboard-firmware/issues/67#issuecomment-516657520

It is not that complicated as there is a makefile for the OpenOCD code.

With the patched OpenOCD you can just use openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "mww 0x40022004 0x45670123" -c "mww 0x40022004 0xCDEF89AB" -c "mww 0x40022008 0x45670123" -c "mww 0x40022008 0xCDEF89AB" -c targets -c "halt" -c "stm32f1x unlock 0" The ST-Link utility does not work, but doing this little bit of manual work is not that hard.

leChrisLessieur commented 3 years ago

Hi all, Did someone manage to flash an AT32 motherboard with an ST-link v2 ? It seems pretty tricky, even with Cloidnerux advices on OpenOCD patch ...

juodumas commented 3 years ago

I am using this patch with https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/: 0001-Support-for-board-with-AT32F403-CPU.txt

Only sinusoidal control is working. Current limiting is not working. I am flashing with openocd: openocd -f interface/stlink-v2.cfg -f target/stm32f3x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0" -c "flash write_image erase $(BUILD_DIR)/$(TARGET).hex 0 ihex" -c "shutdown"

Brnpimenta commented 3 years ago

Hello, can anybony describe step by step (like youtube video) on how to reprogram an AT32 motherboard with an ST-link v2?

still stuck on this! looking foward to solve it.

Regards, Bruno O.

leChrisLessieur commented 3 years ago

Thanks, Juodumas, for your response.

Maybe I'm doing something wrong around openocd. Would you mind giving your opignon on this ?

I use a raspberry pi with debian (raspbian) and an ST-link v2 usb stick. I try to flash an AT32F403 motherboard.

So, I downloaded the lastest version of openocd and modified the file stm32f1x.c as describe here. That only add an case (0x242), right ? Then I ./configure, make and then make install

When I try to use openocd I get an error :

Open On-Chip Debugger 0.11.0+dev-00294-g3d9534b8a-dirty (2021-08-11-14:38) Licensed under GNU GPL v2 Error: The specified debug interface was not found (hla) The following debug adapters are available: 1: jlink 2: buspirate Does it mean that my st-link usb stick is not reconized ? I tried with root permission, also.

Maybe I forgot something ?

Thanks for your help.

Another point : The command to flash using openocd refere to the file interface/stlink.cfg This file contains HLA PID (??) but not the one we add in the "case" to patch openocd Is that a hint ?

interface/stlink.cfg : adapter driver hla hla_layout stlink hla_device_desc "ST-LINK" hla_vid_pid 0x0483 0x3744 0x0483 0x3748 0x0483 0x374b 0x0483 0x374d 0x0483 0x374e 0x0483 0x374f 0x0483 0x3752 0x0483 0x3753

juodumas commented 3 years ago

@leChrisLessieur what happens when you use openocd that is shipped with raspbian and execute the openocd command that I posted above? If it's not working, then yes, you probably need to patch openocd. I do not remember the details because it's been a while, but I have used the below patch by sjamthe. In your case your openocd complains about missing interfaces. Most probably you have configured it incorrectly (check ./configure --help before compiling) or didn't install some parts.

diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c
index cf10e374..a5b69952 100644
--- a/src/flash/nor/stm32f1x.c
+++ b/src/flash/nor/stm32f1x.c
@@ -728,6 +728,27 @@ static int stm32x_probe(struct flash_bank *bank)

        /* set page size, protection granularity and max flash size depending on family */
        switch (device_id & 0xfff) {
+        case 0x240: /* AT32F403 added by sjamthe */
+                LOG_WARNING("Found 0x700 for ATF32F403");
+                // BAD
+                /* page_size = 2048; */
+                /* stm32x_info->ppage_size = 2; */
+                /* page_size = 1024; */
+                /* stm32x_info->ppage_size = 2; */
+                /* page_size = 1024; */
+                /* stm32x_info->ppage_size = 4; */
+                /* page_size = 2048; */
+                /* stm32x_info->ppage_size = 4; */
+                page_size = 2048;
+                stm32x_info->ppage_size = 2;
+                max_flash_size_in_kb = 256;
+                break;
+        case 0x242: /* AT32F403 added by sjamthe */
+                LOG_WARNING("Found 0x700 for ATF32F403");
+                page_size = 2048;
+                stm32x_info->ppage_size = 2;
+                max_flash_size_in_kb = 512;
+                break;
        case 0x410: /* medium density */
                page_size = 1024;
                stm32x_info->ppage_size = 4;
Brnpimenta commented 3 years ago

Hello Guys, I'm using the ubuntu running on vm and st linkv2, the steps I go through were below,

What other programs I need to install and other steps? like gcc, stlink utility, etc... Please let me know, my email is brnpimenta@gmail.com if you want to contact me direct, I'll create a detailed instructions of the procedure to reprogram the hoverboard which uses at32f403 chip. step 1: Create folder hoverboard/orig/opencd Step 2: Download Openocd openocd-0.11.0.tar.bz2 At hoverboard /orig/opencd Step 3: install openocd-0.11.0.tar.bz2 At HOVERBOADsrc/opencd/openocd-0.11.0 Step 4: Enter At HOVERBOADsrc/opencd/openocd-0.11.0 Press ./configure--enabe-stlink

image

/ Step 5: At hoverboard/src/opencd/openocd-0.11.0/ src/flash/nor/stm32f1x.c Add the command (

case 0x242: / AT32F403 / page_size = 2048; stm32x_info->ppage_size = 2; max_flash_size_in_kb = 512; break;

image

Regards,

Bruno Oliveira

Brnpimenta commented 3 years ago

Guys,

1 - Created folder hoverboard/orig and downloaded the openocd in the link below: https://sourceforge.net/projects/openocd/files/openocd/0.11.0/

2 - Create folder hoverboard/scr/openocd Export openocd from hoverboard/orig to hoverboard/scr/openocd

3 - Change the file src/flash/nor/stm32f1x.c Adding the code: case 0x242: / AT32F403 / page_size = 2048; stm32x_info->ppage_size = 2; max_flash_size_in_kb = 512; break;

4 - go to terminal in the hoverboard/scr/openocd/openocd/0.11.0/ execute the command sudo apt-get install build-essential .configure –enable-stlink sudo apt-get install libusb-1.0.0-dev

after that execute again the command

.configure –enable-stlink

Final message will be presented:

image

got the following error after execute the command: openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0"

image

anyone knows what to do to move foward?

Regards,

Bruno Oliveira

svenssonjoel commented 3 years ago

Guys,

1 - Created folder hoverboard/orig and downloaded the openocd in the link below: https://sourceforge.net/projects/openocd/files/openocd/0.11.0/

2 - Create folder hoverboard/scr/openocd Export openocd from hoverboard/orig to hoverboard/scr/openocd

3 - Change the file src/flash/nor/stm32f1x.c Adding the code: case 0x242: / AT32F403 / page_size = 2048; stm32x_info->ppage_size = 2; max_flash_size_in_kb = 512; break;

4 - go to terminal in the hoverboard/scr/openocd/openocd/0.11.0/ execute the command sudo apt-get install build-essential .configure –enable-stlink sudo apt-get install libusb-1.0.0-dev

after that execute again the command

.configure –enable-stlink

Final message will be presented:

image

got the following error after execute the command: openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f1x unlock 0"

image

anyone knows what to do to move foward?

Regards,

Bruno Oliveira

If you have "open failed" maybe that can be because of access rights to the usb device? Maybe there is a specific group you need to be in to access it or you may need to set up UDEV rules?

Brnpimenta commented 3 years ago

yes,

exactly I rerun the udev rules. I'm using ubuntu and latest version openocd 0.11.0. I finally make the board listening to the port 6666 and 4444. what is the next step? how do I upgrade the firmware? is openocd necessary only to unlock the board?

image

image

After perform it I'll do a step-by-step to all users won't be stuck on this like I did.

Regards, Bruno Oliveira

Brnpimenta commented 3 years ago

Hey Guys, trying the next steps. 1 - installed gcc-arm-none-eabi and 2 - downloaded the firmware of https://github.com/cloidnerux/hoverboard-firmware-hack. 3 - specified the location of gcc-arm-none in the file makefile of https://github.com/cloidnerux/hoverboard-firmware-hack previoes downloaded 4 - executed the command make AT32, got the error:

collect2: error: ld returned 1 exit status make: *** [Makefile:224 build/hover.elf] Erro 1

image

any insight how to solve it?

123JRM commented 3 years ago

Wondering if this could be the cause ? [image: image.png]

Kind Regards,

Jeffrey Morrison

954.214.6322

On Sat, Sep 11, 2021 at 4:39 AM Brnpimenta @.***> wrote:

Hey Guys, trying the next steps. 1 - installed gcc-arm-none-eabi and 2 - downloaded the firmware of https://github.com/cloidnerux/hoverboard-firmware-hack. 3 - specified the location of gcc-arm-none in the file makefile of https://github.com/cloidnerux/hoverboard-firmware-hack previoes downloaded 4 - executed the command make AT32, got the error:

collect2: error: ld returned 1 exit status make: *** [Makefile:224 build/hover.elf] Erro 1

[image: image] https://user-images.githubusercontent.com/20492936/132941955-912cf343-1462-4e54-b1d0-9957fe134054.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NiklasFauth/hoverboard-firmware-hack/issues/97#issuecomment-917368626, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIW77MCCEM3USACBFAI2KUTUBMIVDANCNFSM4HPUHNJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Brnpimenta commented 3 years ago

hey @123JRM / jeffrey,

the image didn't show up.

Regards,

Bruno Oliveira

123JRM commented 3 years ago

Ah sorry that seems to happen

I saw the line

" -specs=nano.specs -tat32f403rct

The " t " in front of the processor definition did not look right.

On Sat, Sep 11, 2021, 8:07 AM Brnpimenta @.***> wrote:

hey jeffrey,

the image didin't show.

Regards,

Bruno Oliveira

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NiklasFauth/hoverboard-firmware-hack/issues/97#issuecomment-917396328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIW77MD3TMCC3INM3GGC6DTUBNA7XANCNFSM4HPUHNJA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.