error while uploading : open ocd child process termination reason:unplugged target or stlink already in use or stlink usbdriver not installed
On terminal, when running “lsusb”, do you see :
Bus 002 Device 046: ID 0483:3748 STMicroelectronics ST-LINK/V2
I did just test your code and it worked well.
My OpenOCD output console :
Open On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-04-12-08:33)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
srst_only separate srst_nogate srst_open_drain connect_assert_srst
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
adapter speed: 8000 kHz
adapter_nsrst_delay: 100
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 8000 kHz
Info : STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.894991
Info : STM32F303VCTx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting ‘gdb’ connection on tcp/3333
Maybe there is an issue on your board, or maybe you should update the ST-Link firmware (https://www.st.com/en/development-tools/stsw-link007.html).