Skip to content

Commit 3228ccc

Browse files
committed
Some updates
1 parent 684bffc commit 3228ccc

31 files changed

+1780
-1113
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ The CH55x-based picoISP is a simple and cheap USB-based in-system programmer (IS
2020

2121
![picoISP_pic1.jpg](https://raw.githubusercontent.com/wagiminator/AVR-Programmer/master/picoISP_Programmer/documentation/picoISP_pic1.jpg)
2222

23-
## [picoAVR ISP + UPDI Programmer - CH552G](https://github.com/wagiminator/AVR-Programmer/tree/master/picoAVR_Programmer)
24-
The CH55x-based picoAVR is an ISP and UPDI combo programmer for AVR microcontrollers compatible with the USBtinyISP and SerialUPDI. It works fine with the Arduino IDE (Tools -> Programmer -> USBtinyISP / Tools -> Programmer -> SerialUPDI). This combo programmer includes a target voltage selection switch that allows users to choose between 5V and 3.3V for their project needs.
23+
## [picoAVR ISP + TPI + UPDI Programmer - CH552G](https://github.com/wagiminator/AVR-Programmer/tree/master/picoAVR_Programmer)
24+
The CH55x-based picoAVR is an ISP, TPI, and UPDI combo programmer for AVR microcontrollers compatible with the USBasp and SerialUPDI. It works fine with the Arduino IDE (Tools -> Programmer -> USBasp / Tools -> Programmer -> SerialUPDI). This combo programmer includes a target voltage selection switch that allows users to choose between 5V and 3.3V for their project needs.
2525

2626
![picoAVR_pic1.jpg](https://raw.githubusercontent.com/wagiminator/AVR-Programmer/master/picoAVR_Programmer/documentation/picoAVR_pic1.jpg)
2727

picoAVR_Programmer/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# picoAVR ISP and UPDI Combo Programmer for AVR MCU based on CH552G
2-
The CH55x-based picoAVR is an ISP and UPDI combo programmer for AVR microcontrollers compatible with the USBtinyISP and SerialUPDI. It works fine with the Arduino IDE (Tools -> Programmer -> USBtinyISP / Tools -> Programmer -> SerialUPDI). This combo programmer includes a target voltage selection switch that allows users to choose between 5V and 3.3V for their project needs. The USBtinyISP part of the firmware is based on Dick Streefland's and Ladyada's original implementation and DeqingSun's CH55x conversion.
1+
# picoAVR - ISP / TPI / UPDI Combo Programmer for AVR MCU based on CH552G
2+
The CH55x-based picoAVR is an ISP, TPI, and UPDI combo programmer for AVR microcontrollers compatible with the USBasp and SerialUPDI. It works fine with the Arduino IDE (Tools -> Programmer -> USBasp / Tools -> Programmer -> SerialUPDI). This combo programmer includes a target voltage selection switch that allows users to choose between 5V and 3.3V for their project needs.
33

44
![picoAVR_pic1.jpg](https://raw.githubusercontent.com/wagiminator/AVR-Programmer/master/picoAVR_Programmer/documentation/picoAVR_pic1.jpg)
55

@@ -49,32 +49,33 @@ sudo pip install pyusb
4949
Install the [Arduino IDE](https://www.arduino.cc/en/software) if you haven't already. Install the [CH55xduino](https://github.com/DeqingSun/ch55xduino) package by following the instructions on the website.
5050

5151
### Compiling and Uploading Firmware
52+
- Adjust the firmware parameters in src/config.h if necessary.
5253
- Copy the .ino and .c files as well as the /src folder together into one folder and name it picoavr.
5354
- Open the .ino file in the Arduino IDE.
5455
- Go to **Tools -> Board -> CH55x Boards** and select **CH552 Board**.
5556
- Go to **Tools** and choose the following board options:
5657
- **Clock Source:** 16 MHz (internal)
5758
- **Upload Method:** USB
58-
- **USB Settings:** USER CODE /w 266B USB RAM
59+
- **USB Settings:** USER CODE /w 0B USB RAM
5960
- Connect the board and make sure the CH55x is in bootloader mode.
6061
- Click **Upload**.
6162

6263
## Installing Drivers for the picoAVR
63-
On Linux, you don't need to install a driver. Windows users may need to install the [usbtiny driver](https://learn.adafruit.com/usbtinyisp). For Windows 10/11, you can also use the [Zadig Tool](https://zadig.akeo.ie/) to install the correct driver. Click on "Options" -> "List all devices" and select the USBtiny. Then install the libusb-win32 driver. To do this, the picoAVR must be connected to your PC. You can also use the Zadig Tool to install the CDC driver for the CDC Serial Interface.
64+
On Linux, you don't need to install a driver. The implementation includes Windows Compatible ID (WCID) code for automated driver installation on Windows. If this doesn't work, Windows users may need to install a driver manually using the Zadig tool (https://zadig.akeo.ie/). Click on "Options" -> "List all devices" and select the USBasp. Then install the libusb-win32 driver. Now select the SerialUPDI and install the CDC driver. To do this, the picoAVR must be connected to your PC.
6465

6566
# Operating Instructions
6667
- Select the programming voltage (3.3V or 5V) with the voltage selection switch.
67-
- Plug the picoAVR into a USB port on your PC, it should be identified as a USBtinyISP with an additional CDC serial interface.
68+
- Plug the picoAVR into a USB port on your PC, it should be identified as a USBasp with an additional CDC COM port.
6869
- Connect the picoAVR to the target board via the 6-pin ICSP connector or the 3-pin UPDI connector.
69-
- The picoAVR should work with any IDE or programming software that supports the USBtinyISP and/or SerialUPDI programmer.
70+
- The picoAVR should work with any IDE or programming software that supports the USBasp and/or SerialUPDI programmer.
7071

7172
# References, Links and Notes
7273
1. [EasyEDA Design Files](https://oshwlab.com/wagiminator)
7374
2. [WCH: CH552 Datasheet](http://www.wch-ic.com/downloads/CH552DS1_PDF.html)
7475
3. [SDCC Compiler](https://sdcc.sourceforge.net/)
7576
4. [Blinkinlabs: CH55x SDK for SDCC](https://github.com/Blinkinlabs/ch554_sdcc)
76-
5. [Dick Streefland: USBtiny](https://dicks.home.xs4all.nl/avr/usbtiny/)
77-
6. [Ladyada: USBtinyISP](https://learn.adafruit.com/usbtinyisp)
77+
5. [Thomas Fischl: USBasp](https://www.fischl.de/usbasp/)
78+
6. [Ralph Doncaster: USBasp](https://github.com/nerdralph/usbasp)
7879
7. [Deqing Sun: CH55xduino](https://github.com/DeqingSun/ch55xduino)
7980

8081
![picoAVR_pic4.jpg](https://raw.githubusercontent.com/wagiminator/AVR-Programmer/master/picoAVR_Programmer/documentation/picoAVR_pic4.jpg)

picoAVR_Programmer/software/makefile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77
# Type "make help" in the command line.
88
# ===================================================================================
99

10-
# Input and Output File Names
11-
SKETCH = picoavr.c
10+
# Files and Folders
11+
MAINFILE = picoavr.c
1212
TARGET = picoavr
1313
INCLUDE = src
14+
TOOLS = tools
1415

1516
# Microcontroller Settings
1617
FREQ_SYS = 16000000
17-
XRAM_LOC = 0x0100
18-
XRAM_SIZE = 0x0300
18+
XRAM_LOC = 0x0000
19+
XRAM_SIZE = 0x0400
1920
CODE_SIZE = 0x3800
2021

2122
# Toolchain
2223
CC = sdcc
2324
OBJCOPY = objcopy
2425
PACK_HEX = packihx
25-
WCHISP ?= python3 tools/chprog.py
26+
ISPTOOL ?= python3 $(TOOLS)/chprog.py
2627

2728
# Compiler Flags
28-
CFLAGS = -mmcs51 --model-small --no-xinit-opt
29+
CFLAGS = -mmcs51 --model-small --no-xinit-opt -DF_CPU=$(FREQ_SYS) -I$(INCLUDE) -I.
2930
CFLAGS += --xram-size $(XRAM_SIZE) --xram-loc $(XRAM_LOC) --code-size $(CODE_SIZE)
30-
CFLAGS += -I$(INCLUDE) -DF_CPU=$(FREQ_SYS)
31-
CFILES = $(SKETCH) $(wildcard $(INCLUDE)/*.c)
31+
CFILES = $(MAINFILE) $(wildcard $(INCLUDE)/*.c)
3232
RFILES = $(CFILES:.c=.rel)
3333
CLEAN = rm -f *.ihx *.lk *.map *.mem *.lst *.rel *.rst *.sym *.asm *.adb
3434

@@ -59,7 +59,7 @@ $(TARGET).bin: $(TARGET).ihx
5959

6060
flash: $(TARGET).bin size removetemp
6161
@echo "Uploading to CH55x ..."
62-
@$(WCHISP) $(TARGET).bin
62+
@$(ISPTOOL) $(TARGET).bin
6363

6464
all: $(TARGET).bin $(TARGET).hex size
6565

1.76 KB
Binary file not shown.

picoAVR_Programmer/software/picoavr.c

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
// ===================================================================================
2-
// Project: picoAVR ISP + UPDI Programmer based on CH551, CH552, CH554
3-
// Version: v1.3
2+
// Project: picoAVR ISP + TPI + UPDI Programmer based on CH551, CH552, CH554
3+
// Version: v1.4
44
// Year: 2023
55
// Author: Stefan Wagner
66
// Github: https://github.com/wagiminator
77
// EasyEDA: https://easyeda.com/wagiminator
88
// License: http://creativecommons.org/licenses/by-sa/3.0/
99
// ===================================================================================
1010
//
11+
// !!! THIS FIRMWARE IS STILL IN DEVELOPMENT !!!
12+
//
1113
// Description:
1214
// ------------
13-
// The CH55x-based picoAVR is an ISP and UPDI programmer for AVR microcontrollers
14-
// compatible with the USBtinyISP and SerialUPDI. It works fine with the Arduino IDE
15-
// (Tools -> Programmer -> USBtinyISP / Tools -> Programmer -> SerialUPDI). The
16-
// USBtinyISP part of the firmware is based on Dick Streefland's and Ladyada's
17-
// original implementation and DeqingSun's CH55x conversion.
15+
// The CH55x-based picoAVR is an ISP, TPI and UPDI programmer for AVR microcontrollers
16+
// compatible with the USBasp and SerialUPDI. It works fine with the Arduino IDE
17+
// (Tools -> Programmer -> USBasp / Tools -> Programmer -> SerialUPDI). The USBasp part
18+
// of the firmware is based on Thomas Fischl's original implementation for the ATmega8
19+
// and Ralph Doncaster's auto-clock extension.
1820
//
1921
// References:
2022
// -----------
21-
// - Dick Streefland: https://dicks.home.xs4all.nl/avr/usbtiny/
22-
// - Ladyada: https://learn.adafruit.com/usbtinyisp
23-
// - Deqing Sun: https://github.com/DeqingSun/ch55xduino
23+
// - Thomas Fischl: https://www.fischl.de/usbasp/
24+
// - Ralph Doncaster: https://github.com/nerdralph/usbasp
2425
// - Blinkinlabs: https://github.com/Blinkinlabs/ch554_sdcc
25-
// - Ralph Doncaster: https://github.com/nerdralph/ch554_sdcc
2626
// - WCH Nanjing Qinheng Microelectronics: http://wch.cn
2727
//
2828
// Compilation Instructions:
@@ -41,22 +41,21 @@
4141
// -----------------------
4242
// Select the programming voltage (3.3V or 5V) with the voltage selection switch.
4343
// Plug the picoAVR into a USB port on your PC, it should be identified as a
44-
// USBtinyISP with an additional CDC serial interface. Connect the picoAVR to the
45-
// target board via the 6-pin ICSP connector or the 3-pin UPDI connector.
46-
// Windows users may need to install a driver for USBtinyISP
47-
// (https://learn.adafruit.com/usbtinyisp) and for CDC (https://zadig.akeo.ie/).
48-
// The picoAVR should work with any IDE or programming software that supports the
49-
// USBtinyISP and/or SerialUPDI programmer.
44+
// USBasp with an additional CDC serial interface. Connect the picoAVR to the
45+
// target board via the 6-pin ICSP connector or the 3-pin UPDI connector.
46+
//
47+
// The implementation includes Windows Compatible ID (WCID) code for automated driver
48+
// installation on Windows. If this doesn't work, Windows users may need to install a
49+
// driver manually using the Zadig tool (https://zadig.akeo.ie/).
50+
// However, functionality, especially with newer Windows versions, is not guaranteed.
5051

5152

5253
// ===================================================================================
5354
// Libraries, Definitions and Macros
5455
// ===================================================================================
5556

5657
// Libraries
57-
#include "src/system.h" // system functions
58-
#include "src/delay.h" // delay functions
59-
#include "src/usb_avr.h" // AVR ISP and UPDI functions
58+
#include "src/avr.h" // AVR ISP and UPDI functions
6059

6160
// Prototypes for used interrupts
6261
void USB_interrupt(void);
@@ -74,45 +73,52 @@ void UART_ISR(void) __interrupt(INT_NO_UART0) {
7473
// ===================================================================================
7574
void main(void) {
7675
// Variables
77-
uint8_t databyte;
76+
uint8_t databyte;
77+
uint8_t rtsstate = 0;
78+
uint32_t baudrate = 115200;
7879

7980
// Setup
8081
CLK_config(); // configure system clock
81-
DLY_ms(10); // wait for clock to settle
82-
AVR_init(); // init AVR ISP and UPDI
83-
WDT_start(); // start watchdog
82+
DLY_us(10000); // wait for clock to settle
83+
AVR_init(); // init programming interfaces
8484

8585
// Loop
8686
while(1) {
8787
// ISP stuff is handled via USB interrupts.
8888
// We only need to take care of USB-CDC to UPDI here.
89+
90+
// Transfer data from USB to UPDI
8991
if(CDC_available()) { // something coming in via USB-CDC?
90-
PIN_low(PIN_LED); // turn on LED (active low)
91-
if(TH1 == 0) { // slow speed? -> must be UPDI BREAK
92-
UPDI_break(); // send UPDI break frame
93-
CDC_write(CDC_read()); // return BREAK frame
94-
CDC_flush(); // flush OUT buffer
95-
}
96-
else { // normal data bytes?
97-
// Send data bytes via UPDI and write echo to USB OUT buffer
98-
while(CDC_available()) { // repeat for all incoming bytes
99-
databyte = CDC_read(); // get data byte
100-
UPDI_write(databyte); // send byte via UPDI
101-
CDC_write(databyte); // send back echo
102-
}
103-
CDC_flush(); // flush OUT buffer
92+
while(CDC_available()) { // repeat for all incoming bytes
93+
databyte = CDC_read(); // get data byte
94+
UPDI_write(databyte); // send byte via UPDI
95+
CDC_write(databyte); // send back echo
10496
}
105-
PIN_high(PIN_LED); // turn off LED (active low)
97+
CDC_flush(); // flush OUT buffer
10698
}
10799

108-
if(UPDI_available()) { // something coming in via UPDI?
109-
PIN_low(PIN_LED); // turn on LED (active low)
100+
// Transfer data from UPDI to USB
101+
if(UPDI_available() && CDC_getDTR()) { // something coming in via UPDI?
110102
while(UPDI_available()) // repeat for all incoming bytes
111103
CDC_write(UPDI_read()); // write received bytes to USB OUT buffer
112104
CDC_flush(); // flush USB OUT buffer
113-
PIN_high(PIN_LED); // turn off LED (active low)
114105
}
115106

116-
WDT_reset(); // reset watchdog
107+
// Handle BAUD rate
108+
if(CDC_getBAUD() != baudrate) {
109+
baudrate = CDC_getBAUD();
110+
UPDI_setBAUD(baudrate);
111+
}
112+
113+
// Handle status LEDs
114+
#ifdef PIN_LED_USB
115+
PIN_write(PIN_LED_USB, !USB_ENUM_OK); // control USB GOOD status LED
116+
#endif
117+
#ifdef PIN_LED_PRG
118+
if(CDC_getRTS() != rtsstate) {
119+
rtsstate = CDC_getRTS();
120+
PIN_write(PIN_LED_PRG, !rtsstate); // control PROG status LED
121+
}
122+
#endif
117123
}
118124
}

picoAVR_Programmer/software/picoavr.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// following board options:
1212
// - Clock Source: 16 MHz (internal)
1313
// - Upload Method: USB
14-
// - USB Settings: USER CODE /w 266B USB RAM
14+
// - USB Settings: USER CODE /w 0B USB RAM
1515
// - Press BOOT button on the board and keep it pressed while connecting it via USB
1616
// with your PC.
1717
// - Click on "Upload" immediatly afterwards.

picoAVR_Programmer/software/src/avr.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ===================================================================================
2+
// picoAVR Functions for CH551, CH552 and CH554 * v1.0 *
3+
// ===================================================================================
4+
5+
#pragma once
6+
#include <stdint.h>
7+
#include "config.h"
8+
#include "system.h"
9+
#include "delay.h"
10+
#include "gpio.h"
11+
#include "updi.h"
12+
#include "usb_asp.h"
13+
#include "usb_cdc.h"
14+
15+
inline void AVR_init(void) {
16+
ISP_disconnect(); // disconnect ISP/TPI bus
17+
UPDI_init(); // setup UPDI
18+
USB_init(); // setup USB
19+
}

picoAVR_Programmer/software/src/ch554.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
/*--------------------------------------------------------------------------
2-
CH554.H
3-
Header file for CH554 microcontrollers.
4-
****************************************
1+
// ===================================================================================
2+
// Header File for CH551, CH552 and CH554 Microcontrollers * v1.0 *
3+
// ===================================================================================
4+
// This contains a copy of CH554.H
5+
/***************************************
56
** Copyright (C) W.ch 1999-2014 **
67
** Web: http://wch.cn **
7-
****************************************
8-
--------------------------------------------------------------------------*/
8+
***************************************/
99

10-
#ifndef __CH554_H__
11-
#define __CH554_H__
10+
#pragma once
11+
#include <stdint.h>
12+
13+
typedef unsigned char volatile __xdata UINT8XV;
14+
typedef unsigned char volatile __pdata UINT8PV;
1215

1316
#define SBIT(name, addr, bit) __sbit __at(addr+bit) name
1417
#define SFR(name, addr) __sfr __at(addr) name
@@ -754,5 +757,3 @@ ASM example:
754757
.DB 0xA5 ;MOVX @DPTR1,A & INC DPTR1
755758
DJNZ R7,LOOP
756759
*/
757-
758-
#endif // __CH554_H__
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ===================================================================================
2-
// User Configurations for CH55x AVR ISP/UPDI Programmer
2+
// User Configurations for CH55x AVR ISP/TPI/UPDI Programmer
33
// ===================================================================================
44

55
#pragma once
@@ -11,19 +11,24 @@
1111
#define PIN_SCK P17 // pin connected to ISCP SCK (do not change)
1212
#define PIN_RXD P30 // pin connected to UPDI (do not change)
1313
#define PIN_TXD P31 // pin connected to UPDI via resistor (do not change)
14-
#define PIN_LED P32 // pin connected to BUSY LED (active LOW)
14+
#define PIN_LED_PRG P32 // pin connected to BUSY LED (active LOW)
15+
//#define PIN_LED_USB P33 // pin connected to USB LED (active LOW)
1516

1617
// USB device descriptor
17-
#define USB_VENDOR_ID 0x1781 // VID (private use only)
18-
#define USB_PRODUCT_ID 0x0C9F // PID (private use only)
19-
#define USB_DEVICE_VERSION 0x0107 // v1.07 (BCD-format)
18+
#define USB_VENDOR_ID 0x16C0 // VID (shared www.voti.nl)
19+
#define USB_PRODUCT_ID 0x05DC // PID (shared vendor class with libusb)
20+
#define USB_DEVICE_VERSION 0x0108 // v1.08 (BCD-format)
2021

2122
// USB configuration descriptor
2223
#define USB_MAX_POWER_mA 500 // max power in mA (also to power target board)
2324

2425
// USB descriptor strings
25-
#define MANUFACTURER_STR 'w','a','g','i','m','i','n','a','t','o','r'
26-
#define PRODUCT_STR 'p','i','c','o','A','V','R',' ','I','S','P','/','U','P','D','I'
27-
#define SERIAL_STR 'C','H','5','5','x','I','S','P','/','U','P','D','I'
28-
#define INTERFACE0_STR 'T','i','n','y','S','P','I'
26+
#define MANUFACTURER_STR 'w','w','w','.','f', 'i', 's', 'c', 'h', 'l', '.', 'd', 'e'
27+
#define PRODUCT_STR 'U', 'S', 'B', 'a', 's', 'p'
28+
#define SERIAL_STR 'w','a','g','i','m','i','n','a','t','o','r'
29+
#define INTERFACE0_STR 'p','i','c','o','A','S','P'
2930
#define INTERFACE1_STR 'S','e','r','i','a','l','U','P','D','I'
31+
32+
// Windows Compatible ID (WCID) code for automated driver installation.
33+
// Uncomment this define to enable experimental WCID feature.
34+
#define WCID_VENDOR_CODE 0x5D

picoAVR_Programmer/software/src/delay.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,3 @@ void DLY_us(uint16_t n) { // delay in us
5757
--n;
5858
}
5959
}
60-
61-
// ===================================================================================
62-
// Delay in Units of ms
63-
// ===================================================================================
64-
void DLY_ms(uint16_t n) { // delay in ms
65-
while(n) {
66-
while(!(TKEY_CTRL & bTKC_IF));
67-
while(TKEY_CTRL & bTKC_IF);
68-
--n;
69-
}
70-
}

picoAVR_Programmer/software/src/delay.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
#include "ch554.h"
88

99
void DLY_us(uint16_t n); // delay in units of us
10-
void DLY_ms(uint16_t n); // delay in units of ms

0 commit comments

Comments
 (0)