cloidnerux / hoverboard-firmware-hack

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

Q: How to flash using st-link? #3

Open juodumas opened 5 years ago

juodumas commented 5 years ago

From the readme:

I did not test to flash the AT32 with a ST-Link but I think this should be no big problem.

Any ideas how to flash using ST-Link V2 (st-flash or openocd)? In the readme you mention that a special flash loader is needed. Do you know if there is any way to use the loader with openocd?

I can communicate with the CPU using openocd:

> flash list
{name stm32f2x base 0 size 0 bus_width 0 chip_width 0} {name stm32f2x base 536836096 size 0 bus_width 0 chip_width 0}

> stm32f4x unlock 0
device id = 0x70050242
Cannot identify target as a STM32 family.
auto_probe failed

> stm32f2x unlock 1
flash size = 512 bytes
Device Security Bit Set
stm32f2x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.

> flash list
{name stm32f2x base 0 size 0 bus_width 0 chip_width 0} {name stm32f2x base 536836096 size 512 bus_width 0 chip_width 0}

But flash bank 0 shows this: device id = 0x70050242 Cannot identify target as a STM32 family.

juodumas commented 5 years ago

@cloidnerux @TomTinkering Managed to get hold of STM32 Nucleo and reflashed it to JLink (https://www.segger.com/products/debug-probes/j-link/models/other-j-links/st-link-on-board/), but still cannot flash firmware.

  1. Did you connect anything besides SWDIO, SWDCLK, GND?
  2. Maybe something else is needed before running make flash-jlink to unlock the flash like on STM32F1x boards?
Connecting to J-Link via USB...O.K.                                                                                                                                                   [42/1942]
Firmware: J-Link STLink V21 compiled Jun 26 2017 10:35:16
Hardware version: V1.00
S/N: 775963281                                                   
VTref=3.300V                                                                                                       
Device "CORTEX-M4" selected.

Target connection not established yet but required for command.
Device "CORTEX-M4" selected.  
Device "AT32F403RCT6" selected.

Connecting to target via SWD
Found SW-DP with ID 0x4BA01477
Scanning AP map to find all available APs
AP[1]: Stopped AP scan as end of AP map has been reached                     
AP[0]: AHB-AP (IDR: 0x24770011)                     
Iterating through AP map to find AHB-AP to use
AP[0]: Core found
AP[0]: AHB-AP ROM base: 0xE00FF000
CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
Found Cortex-M4 r0p1, Little endian.
FPUnit: 6 code (BP) slots and 2 literal slots
CoreSight components:                                      
ROMTbl[0] @ E00FF000
ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM    
Cortex-M4 identified.                                 
Reset delay: 0 ms                                       
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.      

PC = FFFFFFFE, CycleCnt = 00000000                        
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000 
R12= 00000000                                               
SP(R13)= FFFFFFFC, MSP= FFFFFFFC, PSP= 00000000, R14(LR) = FFFFFFFF                          
XPSR = 01000000: APSR = nzcvq, EPSR = 01000000, IPSR = 000 (NoException)
CFBP = 00000000, CONTROL = 00, FAULTMASK = 00, BASEPRI = 00, PRIMASK = 00

FPS0 = 00000000, FPS1 = 00000000, FPS2 = 00000000, FPS3 = 00000000
FPS4 = 00000000, FPS5 = 00000000, FPS6 = 00000000, FPS7 = 00000000
FPS8 = 00000000, FPS9 = 00000000, FPS10= 00000000, FPS11= 00000000
FPS12= 00000000, FPS13= 00000000, FPS14= 00000000, FPS15= 00000000
FPS16= 00000000, FPS17= 00000000, FPS18= 00000000, FPS19= 00000000
FPS20= 00000000, FPS21= 00000000, FPS22= 00000000, FPS23= 00000000
FPS24= 00000000, FPS25= 00000000, FPS26= 00000000, FPS27= 00000000
FPS28= 00000000, FPS29= 00000000, FPS30= 00000000, FPS31= 00000000
FPSCR= 00000000

CPU is halted.

Erasing device...
J-Link: Flash download: Only internal flash banks will be erased.
To enable erasing of other flash banks like QSPI or CFI, it needs to be enabled via "exec EnableEraseAllFlashBanks"
Erasing done.

Downloading file [build/hover.hex]...
Comparing flash   [100%] Done.
Erasing flash     [100%] Done.

****** Error: Failed to erase sectors 0 @ address 0x08000000 (unspecified error)
Unspecified error -1

Reset delay: 0 ms
Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
Reset: Halt core after reset via DEMCR.VC_CORERESET.
Reset: Reset device via AIRCR.SYSRESETREQ.

Script processing completed.

P.S. I had to rename <ChipInfo Vendor="Artery" Name="AT32F403RCT6" -> <ChipInfo Vendor="ST" Name="AT32F403RCT6" to prevent JLink from complaining with this error: The connected J-Link (S/N 775963281) has been designed to work with devices made by ST only..

123JRM commented 3 years ago

I hope this note finds everyone safe. I found my way here as I have a YST board with the AT32F403RCT6. I have noticed a few changes that you did not mention in any of your documentation ( I have read most of it ) since I bought my board as part of a kit it came with everything, new LED boards marked 4LED, 6LED, L and R and 2 side boards marked YST-TLY-J20 V3 ( has the inertial module ) and YST-TLY-BT-J20 V1 ( mostly unpopulated ) both boards have the foot sensors but no microprocessors except for the Inertial Module. I am assuming they use GPIO ? I have yet to determine if you have code in your firmware to read the inertial modules but I came here in order to build a self balancing robotic camera platform so eventually I will take code from some of the other self balancing robot projects and piece that together with whatever i find here that works. I work with some pretty cool systems now at https://robotstudios.com/ . I was wondering if everything was ok with you @cloidnerux because i see this repository has not been updated in more than a year. the website where you posted your diagrams is also down so perhaps you lost interest in the project. either way I was hoping to shake this tree as I will be going thru your work with a fine tooth comb to make it work in my application. Thank you for doing all this.

cloidnerux commented 3 years ago

Hi, I am fine, I just didn't get around to update anything, or to be more precise I just changed some small stuff and put it in a fork. I never used the IMUs, but they should not be to different to the normal ones. Someone in the telegram group said that he could use the binary for the STM32F103 directly on the AT32F403, so I think there is not too much difference between the two devices. Therefore you should be able to very quickly port the code from the other repos to the AT32 chip.

There are some major changes to the EmanualFeru FOC firmware which should be checked on the AT32F403 platform, but I don't get around to do this in the next weeks.

cebrax commented 3 years ago

@juodumas

P.S. I had to rename <ChipInfo Vendor="Artery" Name="AT32F403RCT6" -> <ChipInfo Vendor="ST" Name="AT32F403RCT6" to prevent JLink from complaining with this error: The connected J-Link (S/N 775963281) has been designed to work with devices made by ST only..

I am trying to flash a microchip device but j-link is complaining about "NXP only" for me.. I couldn't find my device in JLinkDevices.xml file.. There are only a handful of devices there..

How did you manage to do this?

Brnpimenta commented 3 years ago

Hello everyone, 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? image

image

Regards,

Bruno Oliveira

123JRM commented 3 years ago

Hello All,

I decided to swap out the AT32 for a ST32 as the pins are the same and it's a lot easier to program. not a big deal... I put the original Avery chip back on the donor dev board and it lives as well. I will let you know how programming goes.

[image: image.png]

Cheers.

Kind Regards,

Jeffrey Morrison

954.214.6322

On Mon, Sep 6, 2021 at 1:40 PM Brnpimenta @.***> wrote:

Hello everyone, I'm using ubuntu and latest version openocd 0.11.0, after install it and try to execute the command:

openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c init -c "reset halt" -c "stm32f2x unlock 0"

I got the message: Open On-Chip Debugger 0.9.0 (2015-07-26-16:02) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html Info : auto-selecting first available session transport "hla_swd". To override use 'transport select '. Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD Info : clock speed 1000 kHz

any insight?

Regards,

Bruno Oliveira

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cloidnerux/hoverboard-firmware-hack/issues/3#issuecomment-913787788, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIW77MH6OJP7PHMO7ILGDG3UAT4JTANCNFSM4IFQFVFQ . 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 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?