sabato 17 agosto 2019

STM32F103C8T6 Blue Pill Blink

La scheda si basa su un Cortex M3 a 72 MHz e 32 bit con 20Kb di ram statica, 64 Kb di flash memory. Tensione di riferimento e' a 3.3 V ma alcuni pin permettono anche tensioni massime di 5 V



Nonostante disponga di una porta USB la programmazione avviene tramite ST Link esterno che deve essere collegato ai 4 pin sul lato corto (oppure usando un seriale TTL TX su A10 e RX su A9). In realta' e' possibile flashare un boot loader che permette la programmazione via USB e la compatilibita' con Arduino IDE perdendo pero' spazio di memoria (circa 20 Kb)






Proviamo adesso a programmmare il classisvo blink

Da questo schema si vede che il led integrato e' collegato alla porta GPIO C13. Attenzione ...rispetto ad una Arduino la numerazione dei Pin e' diffetente...ci sono piu' pin 13 per esempio PB13, PC13 perche' ci sono piu' porte GPIO


Si apre CubeMX e i crea un progetto selezionando selezionando STM32F103C8Tx ed attivando il il clock su HCE Crystal reconator e PC13 come GPIO Output e denominandolo  LED





Si genera il codice e si apre SW4STM32 e si modifica main.c come indicato

-------------------------------------------------
 while (1)
  {
    /* USER CODE END WHILE */
  HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
  HAL_Delay(5000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
-------------------------------------------------

Qui arriva la parte un po' complicata....se si effettua un semplice build and run si ottiene il seguente errore

Open On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-04-12-08:48)
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 : clock speed 8000 kHz
Info : STLINK v2 JTAG v34 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.142412
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : STM32F103C8Tx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Error: timed out while waiting for target halted
TARGET: STM32F103C8Tx.cpu - Not halted
in procedure 'program'
in procedure 'reset' called at file "embedded:startup.tcl", line 500
in procedure 'ocd_bouncer'

embedded:startup.tcl:476: Error: ** Unable to reset target **
in procedure 'program'
in procedure 'program_error' called at file "embedded:startup.tcl", line 501
at file "embedded:startup.tcl", line 476


il trucco  sta nel premere il pulsante di reset della scheda, lanciare Run e circa un seconda dopo che inizia a lampeggiare STLink si deve rilasciare  il tasto di reset

il messaggio di corretto carivamente e;' il segiente

Open On-Chip Debugger 0.10.0+dev-00021-g524e8c8 (2019-04-12-08:48)
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 : clock speed 8000 kHz
Info : STLINK v2 JTAG v34 API v2 SWIM v7 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 3.129153
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : STM32F103C8Tx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x08000c50 msp: 0x20005000
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
Info : Stlink adapter speed set to 4000 kHz
Info : Unable to match requested speed 8000 kHz, using 4000 kHz
adapter speed: 4000 kHz
** Programming Started **
auto erase enabled
Info : device id = 0x20036410
Info : flash size = 64kbytes
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20005000
wrote 4096 bytes from file Debug/blue_piull.elf in 0.264664s (15.114 KiB/s)
** Programming Finished **
** Verify Started **
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20005000
verified 3404 bytes in 0.072038s (46.145 KiB/s)
** Verified OK **
** Resetting Target **
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000002e msp: 0x20005000
shutdown command invoked

A questo punto si preme nuovamente il tasto reset per mandare in esecuzione il programma

Nessun commento:

Posta un commento

Eth0 su LuckFox Pico Mini A

 Le schede Luckfox Pico Mini A (a differenza delle sorelle maggiori) non hanno un connettore RJ45 e nonostante i pin da saldare non sembrano...