From 4c854671f4ff7f94b9c81359b60236fb95968474 Mon Sep 17 00:00:00 2001 From: feer9 Date: Fri, 29 Sep 2023 21:03:04 -0300 Subject: [PATCH] Code cleanup Updated README.md Updated build scripts Remove old binary --- README.md | 109 +++++++++++++++++++++++----------------- build.sh | 7 ++- build_.sh | 6 --- configure | 2 + firmware/fastusbasp.hex | Bin 11008 -> 0 bytes meson.build | 3 +- src/main.cpp | 14 +++--- 7 files changed, 81 insertions(+), 60 deletions(-) delete mode 100755 build_.sh create mode 100755 configure delete mode 100755 firmware/fastusbasp.hex diff --git a/README.md b/README.md index df8e886..b1cb17a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### FASTUSBasp programmer for AVR Microcontrollers +# FASTUSBasp programmer for AVR Microcontrollers [![Join the chat at https://gitter.im/FASTUSBasp/Lobby](https://badges.gitter.im/FASTUSBasp/Lobby.svg)](https://gitter.im/FASTUSBasp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) This is the fast ISP programmer for AVR MCUs based on stm32f407vet6 board with usb-to-serial support. @@ -8,18 +8,75 @@ This is the fast ISP programmer for AVR MCUs based on stm32f407vet6 board with u This project is a fork to amitesh-singh Blue Pill's FASTUSBasp Thanks to him for the original [project](https://github.com/amitesh-singh/FASTUSBasp) -### how to upload firmware +## How to flash the firmware +First, you need to download the binary file from the Releases page. +Then you will have to flash it following one of the next options: + + +### Using [STLINK](https://www.st.com/en/development-tools/st-link-v2.html) +Connect `st-link` programmer to `stm32` and upload the firmware +Once you connect the hardware you can use one of the next utilities + +#### stlink (open-source) +You can download this tool from the github repo: [link](https://github.com/texane/stlink) + +If you're in Arch Linux you can install the utility from the official repositories: +```shell +$ sudo pacman -Syu stlink +``` + +And flash the firmware with the `st-flash` CLI, or the GUI from the same project + +```shell +$ st-flash write fastusbaspv2.bin 0x08000000 +``` +or just +```shell +$ make fastusbasp-upload +``` + +#### STM32CubeProgrammer +This is the official tool from STMicroelectronics, you can download it from their [official page](https://www.st.com/en/development-tools/stm32cubeprog.html) + +### Using serial port + +Install `stm32flash` utility on linux. +To program `stm32f407` via USART, you need to set `BOOT0` as `1` +and leave `BOOT1` as `0`. + +Connect any usb to uart converter device and connect PA9 to RXD and PA10 to TXD +and connect GND. + +```shell +$ make fastusbasp-serialupload +``` + + +## Compile from source +Refer amitesh-singh's post on how to setup stm32 devlopment environment on Arch linux. +http://amitesh-singh.github.io/stm32/2017/04/09/setting-stm32-dev-environment-arch-linux.html + +Make sure you have compiled `libopencm3` library. ```shell $ git clone https://github.com/feer9/FASTUSBasp -$ st-flash write firmware/fastusbasp.hex 0x08000000 +$ nano config.cmake # set the libopencm3 path here +$ cmake . +$ make ``` -### How to use +You can also use `meson` and `ninja` + +```shell +$ meson . builddir --cross-file cross-file.txt --buildtype=minsize "$@" +$ ninja -C builddir bin +``` + +## How to use #### ISP connections -It uses SPI1 to communicate to AVR. +You'll use SPI1 to communicate to AVR. STM32F407 | AVR ---------- | ------- @@ -45,7 +102,7 @@ All pins SPI2(PB5, PB4, PB3), Serial(PA10, PA9) and RST(PB8) used are 5V toleran Refer to [udev/README.md](udev/README.md) -### On plugging to PC +### Plugging to PC #### Linux When you plug this device to PC, you should get following message on`dmesg -wH` @@ -176,45 +233,7 @@ in case target MCU `F_CPU` is bit low < 12MHz - 187.5 KHz -### how to compile from source and upload the firmware -To build fastusbasp firmware from source code, follow below guidelines. - -#### compile -Refer amitesh-singh's post on how to setup stm32 devlopment environment on Arch linux. -http://amitesh-singh.github.io/stm32/2017/04/09/setting-stm32-dev-environment-arch-linux.html - -Make sure you have compiled `libopencm3` library. - -```shell -$ git clone https://github.com/feer9/FASTUSBasp -$ vi config.cmake # set the libopencm3 path here -$ cmake . -$ make -``` -#### Upload the firmware -##### using STLINK -connect `st-link` programmer to `stm32` and upload the firmware - -```shell -$ make fastusbasp-upload - -``` - -##### using serial port - -Install `stm32flash` utility on linux. -To program `stm32f407` via USART, you need to set `BOOT0` as `1` -and leave `BOOT1` as `0`. - -Connect any usb to uart converter device and connect PA9 to RXD and PA10 to TXD -and connect GND. - -```shell -$ make fastusbasp-serialupload - -``` - -### Links +### Useful Links - http://amitesh-singh.github.io/stm32/2017/05/21/FASTUSBasp-programmer-avr.html - https://hackaday.io/project/21189-fastusbasp-programmer-for-avr diff --git a/build.sh b/build.sh index 14a8e32..7abc01e 100755 --- a/build.sh +++ b/build.sh @@ -1 +1,6 @@ -meson . builddir --cross-file cross-file.txt --buildtype=minsize +#!/bin/sh + +arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DSTM32F4 -Ilib -I/home/feer/stm32/libopencm3/include -c lib/*.cpp && mv ./*.o obj +arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DSTM32F4 -Ilib -I/home/feer/stm32/libopencm3/include -Isrc -c src/main.cpp && mv main.o obj +arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard --specs=nosys.specs -DSTM32F4 -L/home/feer/stm32/libopencm3/lib/ obj/*.o obj/stm32f407.ld -o FASTUSBasp.elf -lopencm3_stm32f4 -Tlibopencm3.ld +arm-none-eabi-objcopy -O binary FASTUSBasp.elf FASTUSBasp.bin diff --git a/build_.sh b/build_.sh deleted file mode 100755 index 7abc01e..0000000 --- a/build_.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DSTM32F4 -Ilib -I/home/feer/stm32/libopencm3/include -c lib/*.cpp && mv ./*.o obj -arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DSTM32F4 -Ilib -I/home/feer/stm32/libopencm3/include -Isrc -c src/main.cpp && mv main.o obj -arm-none-eabi-g++ -g -Wall -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard --specs=nosys.specs -DSTM32F4 -L/home/feer/stm32/libopencm3/lib/ obj/*.o obj/stm32f407.ld -o FASTUSBasp.elf -lopencm3_stm32f4 -Tlibopencm3.ld -arm-none-eabi-objcopy -O binary FASTUSBasp.elf FASTUSBasp.bin diff --git a/configure b/configure new file mode 100755 index 0000000..d418e31 --- /dev/null +++ b/configure @@ -0,0 +1,2 @@ +#!/bin/sh +meson . builddir --cross-file cross-file.txt --buildtype=minsize "$@" diff --git a/firmware/fastusbasp.hex b/firmware/fastusbasp.hex deleted file mode 100755 index b69ae7526ebafc00083da6a4c81691935fd52752..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 11008 zcmc(FeSB2awdmgGoS8ZKKFI_~CXt+(6Ch+F3<=c;^z~#WOhP7@VAMvq_DvGBC$W{W zpf9QRG7u|+_<;uckk}SM+j`aeNN{eA8YYTWZ0+kzfHn}Sxkc}RP}>ton3KuJd263Z zBDMCuKi==XH^1NBd+oK>UVH7Ywbx!}5Tf{7c*Nce>1$s~=u1DsLlQxg@}<`29v_Pt-Kbz?IJf$+Bs3p%E{LbX zVX4WBiw}Ek%^l7cLr7@ys=X*wNFn|t=&=_P@=_uf%&N|+w1Sp<$D7(-XrsIE3g}Du z>A28_?Wtk*6a{$`z?tC`fHT8fFR~^B$A2HcD%XsP8&t^AhA|mgjg`F@Ihc{XJvF0! z4N<`R8%AXmYJolxhs7jMj&#t-1=G(YR?vH@oR+5#w(bP1UN;VH5zwW`^ZQJLL}1l)l-EN-m4pmLs$ zam1me^x%ixNx<`@ngIDDDhv5e)mTX%y<252W2Ny8#84v9{f+DNPeF)JhQtLkt23)$ z#U3DIK0b-yR1l~Sp!kgSO={7AMsUBLOahHQn5226l<9Nywhph>;kPCk53*T&TrZg` z(kGd#Tcwv44U_Q{c7mP({9l zk0;4!u11JH2GDu`fY(7-z*^`B;>*6X9aL(__w2x;-iB;reZ9=rMb@GbZA>=Zh|eQI@D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AE*G=?-)1bj(Bg_%E z`7bSp?!qfXg%J;JNT4&_Svg!eD!}Kn;EuT10w?yq)LQb|fO{u+R8__2o!DIf_a5gK zEar0BZaJT?(16h1cQUydVKNE{-ONl|&+zlE$q)8Jh>blGW2c=u{z24#Oy zRrz}&tN`~HMZRun(RJGEs>&f@kF#kI2|#xg8`v{K3*9w48kmj7jSXlSd#>qvtb&{y z8%iK%c;q@PYungx8206P2P$-h&$V>Gd!3~_8i<~zF|MgrrH5`+(ETEmCtJ`pcH!~z zk5$x{tB7f_a87+^N?7Ik-iEga8sSpabDbEz%xoq9cA*=71FN0hg!q9CziHu0vZdX| z$y#7-wRBAO3 z>0y~!b@miqH7jMjAHE*?JgqL@p4N7sE)6c#y(&_^dx=`hD<-@}LCKtAVxCcXMO4<2 zuZzqU#e^c4kO1F<6*R)4ow4dGFUFp@(jKe6dN}sPRnJ?IOO!ycgnB*YLQmup^Ocl` zfdbz&MtJ;H?U4QbFe+q1jKkv2c(XgU^UBmkYAw3l4-q1w38T=4_eKz^8UB?aQ(@AG zX2}p8ZyYvIxuK?E1KsE*n!ha1V-Ug=h0$a1VOoG>h5^rGFrpFx*dPCD4G=+62x&U_ zMaCu}inKQ5Lx9YXj}d0_Daw#Rt&BN`)rarvwe4DE8Da=rjOCisy$`Hg(3ZUmkT z&;Uqc-~96i24jlGX@+*1`$B;<1E$0|5h%^D^ZKf^ZJTe^^5qTRZQgdzR_VsA&G&y> zTK4VcZPJ5{%bK^KdmFZHdvI%G!&VBKMENf;QupzVJ%QGDrNDSy@7h9`64 za{vTUs2+nk?}zk9NE$e?D1US={V%fp*x3L8 diff --git a/meson.build b/meson.build index 6380e64..86c20ba 100644 --- a/meson.build +++ b/meson.build @@ -10,6 +10,7 @@ stm32flash = find_program('stm32flash') #define libopencm3 path here +#todo: use relative path libocm3Path = '/home/feer/coding/stm32/libopencm3' #define cpu types here @@ -95,7 +96,7 @@ exe = executable(p[0], p[1], link_with: [foolib], build_by_default: true) -run_target('hex', command: [objcopy, ['-Obinary', exe.full_path(), +run_target('hex', command: [objcopy, ['-Oihex', exe.full_path(), exe.full_path() + '.hex']], depends: exe) run_target('bin', command: [objcopy, ['-Obinary', exe.full_path(), exe.full_path() + '.bin']], depends: exe) diff --git a/src/main.cpp b/src/main.cpp index 9bef00c..ebf88af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -28,9 +28,7 @@ #include #if USBDPLUS_WRONG_PULLUP == 1 - -#include "usb/util.h" - + #include "usb/util.h" #endif extern "C" @@ -39,9 +37,13 @@ extern "C" } #ifdef DEBUG -#include "serial.h" + #include "serial.h" #endif +#include "isp.h" +#include "config.h" + + //avrdude commands on control ep #define USBASP_FUNC_CONNECT 1 #define USBASP_FUNC_DISCONNECT 2 @@ -66,6 +68,7 @@ extern "C" #define PROG_BLOCKFLAG_FIRST 1 #define PROG_BLOCKFLAG_LAST 2 + static uint8_t prog_new_mode = 0; static uint32_t prog_address; static uint16_t prog_nbytes = 0; @@ -74,9 +77,6 @@ static uint16_t prog_pagesize; static uint8_t prog_blockflags; static uint8_t prog_pagecounter; -#include "isp.h" -#include "config.h" - static char serial_n[] = "0123456789AB"; static const char *usb_strings[] = {