Programmation
On branche le ST-link V2
Il nous faut les programmes St-link ou openodc
https://github.com/stlink-org/stlink
https://github.com/stlink-org/stlink/releases
https://repo.or.cz/openocd.git
Mon OpenOCD utilise probablement le nouveau driver ST-Link natif, pas l’ancien mode HLA (hla_swd).
donc on utilise interface/stlink-dap.cfg qui se trouve dans /usr/share/openocd/scripts/interface/
Test avec :
st-info --probe
Found 1 stlink programmers
version: V2J37S7
serial: 130065000400004E3757574E
flash: 262144 (pagesize: 2048)
sram: 65536
chipid: 0x414
dev-type: F1xx_HD
Mon MCU est bien un :
STM32F1 High Density
Chip ID 0x414
probablement un STM32F103ZE/ZET6 512 KB
On lance :
openocd -f interface/stlink-dap.cfg -f target/stm32f1x.cfg
Puis dans un autre shell :
telnet localhost 4444
> init
> reset halt
Si on trouve :
stm32x device protected
stm32x failed to erase options
C'est que le firmware est protégé il faut essayer :
openocd -f interface/stlink-dap.cfg -f target/stm32f1x.cfg -c “transport select swd” -c “adapter speed 10”
puis
reset halt
stm32f1x unlock 0
Si on a :
stm32x unlocked.
INFO: a reset or power cycle is required
C'est gagné !
Ensuite on cherche un firmware, j'ai pris :
https://github.com/EFeru/hoverboard-firmware-hack-FOC
Sur conseil de chatgpt, il faut changer 2 3 truc dans Inc/config.h
Il faut décommenter :
#define VARIANT_PWM // Variant for RC-Remote with PWM Signal
Puis dans :
// ################################# VARIANT_PWM SETTINGS ##############################
#ifdef VARIANT_PWM
/* ###### CONTROL VIA RC REMOTE ######
* Right sensor board cable. Connect PA2 to channel 1 and PA3 to channel 2 on receiver.
* Channel 1: steering, Channel 2: speed.
*/
// #define DUAL_INPUTS // ADC*(Primary) + PWM(Auxiliary). Uncomment this to use Dual-inputs
#ifdef DUAL_INPUTS
#define FLASH_WRITE_KEY 0x1105 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
#define CONTROL_ADC 0 // use ADC as input. Number indicates priority for dual-input. Disable CONTROL_SERIAL_USART2, FEEDBACK_SERIAL_USART2, DEBUG_SERIAL_USART2!
// #define CONTROL_PWM_RIGHT 1 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
#define CONTROL_PWM_RIGHT 0 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
#define PRI_INPUT1 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#define PRI_INPUT2 3, 0, 0, 4095, 0 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#define AUX_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#define AUX_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#else
#define FLASH_WRITE_KEY 0x1005 // Flash memory writing key. Change this key to ignore the input calibrations from the flash memory and use the ones in config.h
// #define CONTROL_PWM_LEFT 0 // use RC PWM as input on the LEFT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART2!
#define CONTROL_PWM_RIGHT 0 // use RC PWM as input on the RIGHT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART3!
#define PRI_INPUT1 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#define PRI_INPUT2 3, -1000, 0, 1000, 100 // TYPE, MIN, MID, MAX, DEADBAND. See INPUT FORMAT section
#endif
//#define FILTER 6553 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
#define FILTER 10000 // 0.1f [-] fixdt(0,16,16) lower value == softer filter [0, 65535] = [0.0 - 1.0].
// #define SPEED_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
#define SPEED_COEFFICIENT 8000 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14
//#define STEER_COEFFICIENT 16384 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
#define STEER_COEFFICIENT 6000 // 1.0f [-] fixdt(1,16,14) higher value == stronger. [0, 65535] = [-2.0 - 2.0]. In this case 16384 = 1.0 * 2^14. If you do not want any steering, set it to 0.
// #define TANK_STEERING // use for tank steering, each input controls each wheel
// #define INVERT_R_DIRECTION
// #define INVERT_L_DIRECTION
// #define SUPPORT_BUTTONS_LEFT // use left sensor board cable for button inputs. Disable DEBUG_SERIAL_USART2!
// #define SUPPORT_BUTTONS_RIGHT // use right sensor board cable for button inputs. Disable DEBUG_SERIAL_USART3!
#if defined(CONTROL_PWM_RIGHT) && !defined(DUAL_INPUTS)
// #define DEBUG_SERIAL_USART2 // left sensor cable debug
#elif defined(CONTROL_PWM_LEFT) && !defined(DUAL_INPUTS)
// #define DEBUG_SERIAL_USART3 // right sensor cable debug
#endif
#endif
// ############################# END OF VARIANT_PWM SETTINGS ############################
Puis make clean au cas où
make
pour programmer :
reset halt
program /home/pat/ownCloud_pat/Projets/Divers/Tondeuse/hoverboard-firmware-hack-FOC/build/hover.elf verify reset exit
telnet localhost 4444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
> reset halt
[stm32f1x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
>program /home/pat/ownCloud_pat/Projets/Divers/Tondeuse/hoverboard-firmware-hack-FOC/build/hover.elf verify reset exit
[stm32f1x.cpu] halted due to debug-request, current mode: Thread
xPSR: 0x01000000 pc: 0xfffffffe msp: 0xfffffffc
** Programming Started **
device id = 0x13090414
flash size = 256 KiB
Adding extra erase range, 0x080078a4 .. 0x08007fff
** Programming Finished **
** Verify Started **
** Verified OK **
** Resetting Target **
shutdown command invoked
Connection closed by foreign host.
Gros bip Yep !