Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Updated README.md
Updated build scripts
Remove old binary
  • Loading branch information
feer9 committed Sep 30, 2023
1 parent eb9bbfa commit 4c85467
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 60 deletions.
109 changes: 64 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
---------- | -------
Expand All @@ -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`

Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 0 additions & 6 deletions build_.sh

This file was deleted.

2 changes: 2 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
meson . builddir --cross-file cross-file.txt --buildtype=minsize "$@"
Binary file removed firmware/fastusbasp.hex
Binary file not shown.
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
#include <libopencm3/stm32/desig.h>

#if USBDPLUS_WRONG_PULLUP == 1

#include "usb/util.h"

#include "usb/util.h"
#endif

extern "C"
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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[] =
{
Expand Down

0 comments on commit 4c85467

Please sign in to comment.