Examples for various
- boards ( arduino nano, stm32 )
- frameworks ( arduino, stm32duino, mbed )
- development environments ( vscode arduino, platformio )
git clone https://github.com/devel0/iot-examples
cd iot-examples
code arduino/ledblink
- arduino nano v3
- prerequisites
- troubleshoot
avrdude: stk500_getsync() attempt 1 of 10: not in sync
uploading on arduino nano ; set"configuration": "cpu=atmega328old",
on.vscode/arduino.json
- usb permission error on linux: add your user to
dialout
group and set/etc/udev/rules.d/99-arduino-usb.rules
to automodify arduino serial permission with follow ( check your idVendor:idProduct throughlsusb
)SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", MODE="0666"
- debug
- using
Serial.print
through USB cable - C-S-p
Arduino: Upload
then C-S-pArduino: Open Serial Monitor
- using
- increase build speed setting
.vscode/arduino.json
with{ "output": "./build" }
- bluepill F103C8
- nucleo-64-F446RE
- nucleo-144-F767ZI
- bluepill F103C8
- ds18b20
- prerequisites
- troubleshoot
- receive
conflicted extension arduino
go to vscode extensions and from arduino ext select from dropdownDisable (Workspace)
- receive
Error: init mode failed (unable to connect to the target)
on upload ; solve by hit RESET btn until yellowsrst_only separate srst_nogate srst_open_drain connect_deassert_srst
not appears on terminal - receive
[upload] Error
evenVerified OK
; watch at monitor C-A-s and press RESET to retry start program - receive
Warn : UNEXPECTED idcode: 0x2ba01477 ; Error: expected 1 of 1: 0x1ba01477
; can setupload_flags = -c set CPUTAPID 0x2ba01477
on platformio.ini
- receive
- debug
- using
printf
output go to monitor ( C-S-pPlatformIO: Serial Monitor
) ; it goes over usb cable used for programming to stlink connector - through C-S-p
PlatformIO: Start Debugging
( working for platformio 5.0.4 )
- using
-
do a platformio/cleanup before
-
with platformio/upload receive
xPack OpenOCD, x86_64 Open On-Chip Debugger 0.10.0+dev-00378-ge5be992df (2020-06-26-09:27)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
debug_level: 1
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
Error: init mode failed (unable to connect to the target)
in procedure 'program'
** OpenOCD init failed **
shutdown command invoked
*** [upload] Error 1
-
solve that by hitting RESET btn until
srst_only separate srst_nogate srst_open_drain connect_deassert_srst
then release and upload goes fine -
hit F5 to debug ( set a breakpoint on an instruction to check )
-
if use
DigitalOut
on alternate function pins SWDIO/SWCLK may have problem during reset just after upload ( for example, avoid to use PA13, PA14 on STM32F446RE as DigitalOut )
- bluepill F103C8
- nucleo-64-F446RE
- nucleo-144-F767ZI
- prerequisites
- vscode
- arduino ide
- vscode arduino
- https://github.com/stm32duino/Arduino_Core_STM32
- https://www.st.com/en/development-tools/stm32cubeprog.html
- arm gcc
xpm install --global @xpack-dev-tools/arm-none-eabi-gcc@latest
- openocd
xpm install --global @xpack-dev-tools/openocd@latest
- connect STLINK V2 ( 4 wires 3.3-swdio-swclk-gnd )
- debug
- using
Serial.print
- bluepill: through USB-TTL connected to serial (eg. stm32f103c8 pins A9,A10)
- nucleo64/144: through usb cable (
/dev/ttyACM0
) - then C-S-p
Arduino: Upload
then C-S-pArduino: Open Serial Monitor
- with active debugger setting
.vscode/launch.json
( see hello-world example ) then press F5
- using
- troubleshoot
- if receive
Send Event AD7MessageEvent
on debug console try to run correspondingopenocd
with arguments given from debug console to test board connection; may you gotWarn : UNEXPECTED idcode: 0x2ba01477
andError: expected 1 of 1: 0x1ba01477
that you can fix in.vscode/launch.json
by setting"debugServerArgs": "-f interface/stlink-v2.cfg -c \"set CPUTAPID 0x2ba01477\" -f target/stm32f1x.cfg",
- if debugger start but breakpoint still grayed double check
.vscode/arduino.json
and see if"configuration"
containsopt=ogstd
that is Optimize for Debug (-g) while default is Optimize for Smallest (-Os default) onopt=osstd
. - board:arduino nano
- if upload fails check on
.vscode/arduino.json
if"configuration": "cpu=atmega328old"
- if upload fails check on
- if receive
note: to open dwg qcad can be used.
- pinout
- CPU 16Mhz / SRAM 2KB / EEPROM 1KB / FLASH 32KB
- power supply types
- USB cable
VIN
pin (unregulated 7-12V) to AMS1117-5.05V
pin (regulated 5V)
- max current
- I/O pins (40mA)
3.3V
pin (50mA) from CH340
- 2 x hardware interrupt
- 8 x 10bit ADC
- 6 x PWM
- pinout
- CPU 180Mhz / SRAM 128KB / EEPROM 0KB / FLASH 512KB
- power supply types
- USB cable (300mA max)
VIN
CN6/pin8 or CN7/pin24 (unregulated 7-12V ; max 800mA)E5V
CN7/pin6 (regulated 5V ; max 500mA)3V3
CN6/pin4 or CN7/pin12 (regulated 3V3)[stlink debug unavail]
- max current
- I/O pins (25mA ; total 120mA)
3.3V
pin (240mA)
- hardware interrupt on all digital pin
- 3 x 12bit ADC
- 2 x 12bit DAC
- pinout
- CPU 216Mhz / SRAM 512KB / EEPROM 0KB / FLASH 2048KB
- power supply types
- USB cable (300mA max)
VIN
CN8/pin15 or CN11/pin24 (unregulated 7-12V ; max 800mA if VIN=7V ; max 450mA if 9>VIN>7 ; max 250mA if 12>VIN>9)E5V
CN11/pin6 (regulated 5V in 4.75-5.25V ; max 500mA)3V3
CN8/pin7 or CN11/pin6 (regulated 3V3 in 3-3.6V)[stlink debug unavail]
- max current
- I/O pins (25mA ; total 120mA)
3.3V
pin (420mA)
- hardware interrupt on all digital pin
- 3 x 12bit ADC
- 2 x 12bit DAC