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
Mais j'ai bataillé un moment avant de comprendre que le :
#define CONTROL_PWM_LEFT 0 // use RC PWM as input on the LEFT cable. Number indicates priority for dual-input. Disable DEBUG_SERIAL_USART2!
définissait le connecteur gauche et non pas le fils gauche du connecteur !
Il faut donc décommenter le LEFT et commenter le :
//#define CONTROL_PWM_RIGHT
Cela m'a fait essayé plusieurs firmware, au final j'ai terminé avec celui ci mais le premier doit fonctionner :
https://github.com/jebc/hoverboard-firmware-hack-FOC-pwmLR
Il faut décommenter :
#define VARIANT_PWM // Variant for RC-Remote with PWM Signal
1. Vitesse maximale — N_MOT_MAX
// Ligne 156 — actuellement :
#define N_MOT_MAX 1000 // [rpm]
// Exemple pour réduire de moitié :
#define N_MOT_MAX 500 // [rpm]
2. Rampe d'accélération — DEFAULT_RATE
C'est le paramètre principal pour un démarrage doux. Plus la valeur est basse, plus la montée en vitesse est lente.
// Ligne 189 — actuellement :
#define DEFAULT_RATE 480 // = 30.0 * 2^4
// Plus doux (exemples) :
#define DEFAULT_RATE 160 // ~10.0 → très progressif
#define DEFAULT_RATE 240 // ~15.0 → bon compromis
#define DEFAULT_RATE 320 // ~20.0 → légèrement adouci
3. Filtre d'entrée — DEFAULT_FILTER
Lisse les variations brusques du signal PWM de ta RC. Plus la valeur est basse, plus c'est mou.
// Ligne 190 — actuellement :
#define DEFAULT_FILTER 6553 // = 0.1
// Plus lissé :
#define DEFAULT_FILTER 3276 // = 0.05 → répond plus lentement aux coups de stick
4. Deadband (zone morte au neutre)
Si les moteurs démarrent légèrement sans que tu touches les sticks, augmente la deadband dans PRI_INPUT1/2 :
// Actuellement (dernier chiffre = deadband) :
#define PRI_INPUT1 3, -1000, 0, 1000, 100
#define PRI_INPUT2 3, -1000, 0, 1000, 100
// Deadband plus large :
#define PRI_INPUT1 3, -1000, 0, 1000, 150
#define PRI_INPUT2 3, -1000, 0, 1000, 150
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 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 0x1006 // 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 3270 // 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 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 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 !