搜索
bottom↓
回复: 12

[转帖]改造USBASP,用以下载atxmega

[复制链接]

出0入0汤圆

发表于 2015-8-13 17:10:56 | 显示全部楼层 |阅读模式
https://ketturi.kapsi.fi/2013/05 ... ith-usbasp-avrdude/

http://szulat.blogspot.fi/2012/08/atxmega-programmer-for-050.html


ATxmega programmer for $0.50

A simple interface enables USBASP to program ATxmega16A4 (PDI protocol)
ATxmega programmer for $0.50 or how to make your USBASP support PDI

Do you know XMEGA, the new family of AVR microcontrollers? They look really sweet, especially for someone who already mastered the AVR architecture. More speed (32MHz!), more peripherals (5 USARTs! 16 PWM channels!), modular design, and you can still use the same well known tools. And then you read about the programming interface and... what?! What happened to ISP? No way I would purchase a completely new programmer model just to play with their new MCU!


V-USB interrupt disturbing the PDI clock
- but not breaking it
Fortunately, implementing the new programming protocol in USBASP was not that hard. Initially I thought it would be almost impossible, because PDI requires a constantly clocking signal and disconnects if the clock rate drops below 10 kHz. Strict timing is a problem for V-USB (USB protocol implementation used in USBASP) as it handles all USB transmissions in software and cannot do both things at the same time (like a guy who lacks brain power to walk and talk at the same time). The tests showed that the interrupt handling a basic control transfer only steals 40-50 us, and this is short enough to allow for the reliable PDI bit banging. Sending more payload (more than a regular control message) would break the clocking but the programmer can be scheduled to work in batches, so it gathers all data from the usb and only then begins the PDI transmission (hoping that there will be no new USB transmission for a while).


Bit-banging clock (to the left)
and timer clock (to the right)
My implementation switches to the hardware timer clocking to keep the clock running during the interrupt-intense USB transmissions. It is not really necessary because the programmer could also disconnect and reconnect after each transmission, but I think the PDI might like the continuous clock better ;-)

Physical connection

If you have a regular USBASP then it is 5V, while the PDI operates at 3,3V. The simple way to reduce the voltage is just adding zener diodes and some resistors. As you can see, SCK becomes PDI DATA and MOSI becomes PDI CLK.
R1 and R2 seem redundant but I put them here after the official Atmel PDI documentation. The thing is, the DATA line is bidirectional and the physical layer should be able to detect collisions. My implementation does not do it, but it could, thanks to the MISO line (maybe someone will implement it some day...). Another weird thing is RESET connection, it looks like it should be GND instead, and yes, this is GND, that can be disconnected at will. Permenent GND connection breaks the PDI bus-keeper so it must be disabled before receiving anything from PDI.
If your USBASP is 3,3V then it would be more simple:

Power supply
If you want to power your circuit from a 5V USBASP then of course you need a 3,3V regulator - but this is not a part of the project.
Software
Obviously, you will need 2 pieces of software:

1. USBASP Firmware supporting PDI
Download USBASP source: http://www.fischl.de/usbasp/usbasp.2011-05-28.tar.gz
Patch file: http://sz.toyspring.com/usbasp-pdi-usbaspfirmware-20120816.diff

Unpack, apply the patch, compile:


tar xvzf usbasp.2011-05-28.tar.gz
cd usbasp.2011-05-28/firmware
patch <full/path/of/usbasp-pdi-usbaspfirmware-20120816.diff
make main.hex

...and install in your USBASP


Note: ATmega48 is not supported because its flash area is to small for the increased program size. I only tested it on ATmega8 because that's what in my USBASP. ATmega88 should work, too.

2. AVRDUDE supporting USBASP with PDI
Get the AVRDUDE source and apply the patch against revision 1092:
http://sz.toyspring.com/usbasp-pdi-avrdude2091-20120816.diff

svn co svn://svn.sv.gnu.org/avrdude/trunk -r 1092
cd trunk/avrdude
patch <full/path/of/usbasp-pdi-avrdude2091-20120816.diff
./bootstrap
./configure
make


./avrdude -C avrdude.conf -c usbasp -p x16a4 -U flash:w:../../../xmega/xmegatest.hex  -E noreset



avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0x1e9441
avrdude: NOTE: Programmer supports page erase for Xmega devices.
         Each page will be erased before programming it, but no chip erase is performed.
         To disable page erases, specify the -D option; for a chip-erase, use the -e option.
avrdude: reading input file "../../../xmega/xmegatest.hex"
avrdude: input file ../../../xmega/xmegatest.hex auto detected as Intel Hex
avrdude: writing flash (440 bytes):

Writing | ################################################## | 100% 0.29s

avrdude: 440 bytes of flash written
avrdude: verifying flash memory against ../../../xmega/xmegatest.hex:
avrdude: load data flash data from input file ../../../xmega/xmegatest.hex:
avrdude: input file ../../../xmega/xmegatest.hex auto detected as Intel Hex
avrdude: input file ../../../xmega/xmegatest.hex contains 440 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.27s

avrdude: verifying ...
avrdude: 440 bytes of flash verified

avrdude done.  Thank you.




And the result:

The canonical flashing LED!
What now?
It works for my ATxmega16A4 + Linux but it would be nice to know if it also works on anyone else hardware (especially that the PDI connection reliability depends on the V-USB interrupts). So... download it, test it (and maybe fix it), and if everything goes well, it could be probably included in the official USBASP and AVRDUDE releases.

Summary

Add a simple interface to USBASP and you can program ATxmega
If you already have USBASP then the interface can be made in minutes almost for free (but if you have to buy USBASP, it is still the least expensive way to program ATxmega)
Upgraded USBASP can still program old AVRs (without the interface)
There is a catch: you have to install a new firmware in USBASP using another programmer

阿莫论坛20周年了!感谢大家的支持与爱护!!

知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)

出0入0汤圆

 楼主| 发表于 2015-8-13 17:49:06 | 显示全部楼层
大致意思就是给USBASP加外围电路,让电平降到3.6V。
然后修改下载软件和USBASP固件,让它支持PDI接口

出0入0汤圆

发表于 2015-8-13 18:07:04 | 显示全部楼层
PDI下载线要能降到20元左右,XMEGA就可以迅速普及了。

出0入0汤圆

 楼主| 发表于 2015-8-13 19:51:46 | 显示全部楼层
HYLG 发表于 2015-8-13 18:07
PDI下载线要能降到20元左右,XMEGA就可以迅速普及了。

如果这种方法成功的话 只需要不超过20块就行

出0入0汤圆

发表于 2015-8-13 21:09:40 | 显示全部楼层
现在M0都普及了,Atxmega推广起来估计很难了。。。。

出0入0汤圆

 楼主| 发表于 2015-8-15 21:34:15 | 显示全部楼层
本帖最后由 dhbighead 于 2015-8-16 12:24 编辑

测试了N次 发现是电脑USB口的问题

可能是patch以后的USB驱动有问题


另外一台电脑就行。。




==================


换了电脑还是有问题。

还烧了个usbasp 蛋疼

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出0入0汤圆

发表于 2015-8-15 21:55:08 来自手机 | 显示全部楼层
HYLG 发表于 2015-8-13 18:07
PDI下载线要能降到20元左右,XMEGA就可以迅速普及了。

32位机这么便宜了。stm8也太吓人。at机会太小

出0入0汤圆

发表于 2015-8-15 22:21:56 | 显示全部楼层
PDI下载线便宜点,用的人肯定会多很多。
XMEGA就适合那些高大上又不计较几块钱成本的场合的。

出0入0汤圆

发表于 2015-8-16 13:32:22 | 显示全部楼层
dhbighead 发表于 2015-8-15 21:34
测试了N次 发现是电脑USB口的问题

可能是patch以后的USB驱动有问题

什么系统,还是好好看看人家的说明比较好

出0入0汤圆

 楼主| 发表于 2015-8-18 20:40:59 | 显示全部楼层
HYLG 发表于 2015-8-15 22:21
PDI下载线便宜点,用的人肯定会多很多。
XMEGA就适合那些高大上又不计较几块钱成本的场合的。
...

其实有类似的东西

http://tom-itx.no-ip.biz:81/~web ... Tiny_Mkii_index.php

不过貌似没看到国内有人做

出0入0汤圆

发表于 2015-8-18 21:14:48 | 显示全部楼层
那PDI协议是英文的,要是有中文资料,应该早就满大街了。

出0入0汤圆

发表于 2015-8-19 09:24:00 | 显示全部楼层
ATXMEGA确实与现有的8位机不可同日而语,外设相当给力还支持DMA和EVENT,内核果真是16位的么?是不是16位数加16位数单周期就能搞定?有16位数乘16位数的硬件乘法器吗?

如果ATMEL 把ATMEGA降到STM8的价格,把ATXMEGA降到ATMEGA的价格,那市场情况完全不同了。

出0入0汤圆

发表于 2015-9-12 23:33:34 | 显示全部楼层
xmega的确不错,比mega又先进了不少,我喜欢呵呵.
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片。注意:要连续压缩2次才能满足要求!!】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-7-23 12:29

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表