avrdudes / avrdude

AVRDUDE is a utility to program AVR microcontrollers
GNU General Public License v2.0
759 stars 139 forks source link

AT89S51 and AT89S52 support for avrdude #1304

Closed orbanp closed 1 year ago

orbanp commented 1 year ago

Hello Everyone,

I am new here, so please advise if this is the wrong place to ask the following question.

I am trying to program an AT89S52 chip. I am using avrdude 6.3 and an ebay programmer which is a version of the usbasp programmer. The OS is Kubuntu 20.04 LTS. I am getting the following error message:

$ avrdude -p usbasp -c 5082 -U flash:r:"test.bin":r
avrdude: error at /etc/avrdude.conf:336: programmer type must be written as "id_type"
avrdude: error reading system wide configuration file "/etc/avrdude.conf"

I updated the configuration file that has an entry for the AT89S52 chip, the programmer description is the same that came with the installation. The suggestion that the programmer type should be written in the configuration file with double quotes did not make any difference.

Previously I installed avrdude 7.0 and got the same error. avrdude 6.3 came from the Software Center of the OS.

Any help would be appreciated! Thanks, Peter

stefanrueger commented 1 year ago

I agree with @llinjupt: this is probably nothing AVRDUDE can do about it if the programmer cannot cope with different reset polarity. I suggest closing the issue again.

mcuee commented 1 year ago

Okay, close for now.

dioannidis commented 1 year ago

@mcuee, @llinjupt

The AT89S51 and AT89S52 ICs just arrived :) . Do I need a patched avrdude and conf file or the version from here https://github.com/mcuee/avrdude/releases/tag/v7.1 supports them ?

I'll try to find time next week to test the llinjupt's code and if all is ok then I'll release the 1.11 version .

mcuee commented 1 year ago

@dioannidis

I think the idea is not to patch avrdude, but rather patch usbasp FW.

You can use the latest github action mingw-64 build of avrdude main. https://github.com/avrdudes/avrdude/suites/12376320894/artifacts/657514449

mcuee commented 1 year ago

@dioannidis

You can also use my mingw64 build if you prefer. https://github.com/mcuee/avrdude/releases/tag/snapshot_21Apr2023

dioannidis commented 1 year ago

@mcuee

I'll try both ;) ... Thx !

dioannidis commented 1 year ago

@mcuee

Both avrdude mingw64 builds ( yours and avrdude main ) are working fine with the composite firmware ! Thx !

mcuee commented 1 year ago

@mcuee

Both avrdude mingw64 builds ( yours and avrdude main ) are working fine with the composite firmware ! Thx !

Wondeful.

I will try your modified FW once I get the AT89S52 chip.

dioannidis commented 1 year ago

@llinjupt

@mcuee IMHO, if the programmer doesn't support setting reset polarity, that's impossible to do so. And there are more other strange chips like S2051/AT89S8252/AT89S8253 that behave pretty differently,

< snip >

Fortunately for the USBasp improved firmware to support the AT89S51/2 ICs only the following lines has to be added to ispEnterProgrammingMode() :

           ...
           ...

            /* AT89* Probe */

            ISP_OUT |= (1 << ISP_RST);      /* RST high */
            clockWait(5);                   /* 1.6 ms */

            spiTx(0xAC);
            spiTx(0x53);
            spiTx(0);
            check = spiTx(0);

            if (check == 0x69) 
                return 0;

        } while (--tries);

       ...
       ...
dioannidis commented 1 year ago

@llinjupt, @orbanp

@mcuee

< snip >

I will try your modified FW once I get the AT89S52 chip.

As I don't use MCS-51 MCUs, I adapted a basic blink assembly program and used the Microchip's c51asm assembler to produce a 27 bytes binary .

Please if it's possible test it with a bigger binary to see if there is a problem .

dioannidis commented 1 year ago

@mcuee

I will try your modified FW once I get the AT89S52 chip.

That file will be deleted . Please use the firmware binaries from the 1.11 pre release from today !

I re uploaded them, because they were corrupted :( See Corrupted firmware binaries in 1.11 pre Release assets

mcuee commented 1 year ago

@dioannidis

Thanks. I just got AT89S51 chip. The first test shows it works well.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c usbasp -p at89s51
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5106 (probably 89S51)

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c usbasp -p at89s51 -U .\entest.hex
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5106 (probably 89S51)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file .\entest.hex for flash
         with 512 bytes in 1 section within [0, 0x1ff]
avrdude: writing 512 bytes flash ...
Writing | ################################################## | 100% 1.32 s
avrdude: 512 bytes of flash written
avrdude: verifying flash memory against .\entest.hex
Reading | ################################################## | 100% 0.61 s
avrdude: 512 bytes of flash verified

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c usbasp -p at89s51 -t
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5106 (probably 89S51)
avrdude> dump flash
Reading | ################################################## | 100% 0.45 s
0000  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0010  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0020  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0030  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
0040  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|
0050  61 7a 79 20 64 6f 67 0a  54 68 65 20 71 75 69 63  |azy dog The quic|
0060  6b 20 62 72 6f 77 6e 20  66 6f 78 20 6a 75 6d 70  |k brown fox jump|
0070  73 20 6f 76 65 72 20 74  68 65 20 6c 61 7a 79 20  |s over the lazy |
0080  64 6f 67 0a 54 68 65 20  71 75 69 63 6b 20 62 72  |dog The quick br|
0090  6f 77 6e 20 66 6f 78 20  6a 75 6d 70 73 20 6f 76  |own fox jumps ov|
00a0  65 72 20 74 68 65 20 6c  61 7a 79 20 64 6f 67 0a  |er the lazy dog |
00b0  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
00c0  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
00d0  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
00e0  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
00f0  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|
avrdude> dump flash
Reading | ################################################## | 100% 0.45 s
0100  61 7a 79 20 64 6f 67 0a  54 68 65 20 71 75 69 63  |azy dog The quic|
0110  6b 20 62 72 6f 77 6e 20  66 6f 78 20 6a 75 6d 70  |k brown fox jump|
0120  73 20 6f 76 65 72 20 74  68 65 20 6c 61 7a 79 20  |s over the lazy |
0130  64 6f 67 0a 54 68 65 20  71 75 69 63 6b 20 62 72  |dog The quick br|
0140  6f 77 6e 20 66 6f 78 20  6a 75 6d 70 73 20 6f 76  |own fox jumps ov|
0150  65 72 20 74 68 65 20 6c  61 7a 79 20 64 6f 67 0a  |er the lazy dog |
0160  54 68 65 20 71 75 69 63  6b 20 62 72 6f 77 6e 20  |The quick brown |
0170  66 6f 78 20 6a 75 6d 70  73 20 6f 76 65 72 20 74  |fox jumps over t|
0180  68 65 20 6c 61 7a 79 20  64 6f 67 0a 54 68 65 20  |he lazy dog The |
0190  71 75 69 63 6b 20 62 72  6f 77 6e 20 66 6f 78 20  |quick brown fox |
01a0  6a 75 6d 70 73 20 6f 76  65 72 20 74 68 65 20 6c  |jumps over the l|
01b0  61 7a 79 20 64 6f 67 0a  54 68 65 20 71 75 69 63  |azy dog The quic|
01c0  6b 20 62 72 6f 77 6e 20  66 6f 78 20 6a 75 6d 70  |k brown fox jump|
01d0  73 20 6f 76 65 72 20 74  68 65 20 6c 61 7a 79 20  |s over the lazy |
01e0  64 6f 67 0a 54 68 65 20  71 75 69 63 6b 20 62 72  |dog The quick br|
01f0  6f 77 6e 20 66 6f 78 20  6a 75 6d 70 73 20 6f 76  |own fox jumps ov|
avrdude> quit

avrdude done.  Thank you.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c usbasp -p at89s51 -t
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5106 (probably 89S51)
avrdude> part
AVR Part                      : AT89S51
Chip Erase delay              : 250000 us
RESET disposition             : dedicated
RETRY pulse                   : SCK
Serial program mode           : yes
Parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
PollIndex                     : 4
PollValue                     : 0x69
Memory Detail                 :

                                  Block Poll               Page                       Polled
  Memory Type Alias    Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
  ----------- -------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
  flash                   2    10   256    0 no       4096    1      0  4500  4500 0xff 0xff
  lock                    0     0     0    0 no          1    1      0     0     0 0x00 0x00
  signature               0     0     0    0 no          3    1      0     0     0 0x00 0x00
avrdude> dump lock
Reading | ################################################## | 100% 0.00 s
0000  00                                                |.               |
avrdude> dump signature
Reading | ################################################## | 100% 0.01 s
0000  1e 51 06                                          |.Q.             |
avrdude> quit

avrdude done.  Thank you.
mcuee commented 1 year ago

@orbanp

Please give the FW from @dioannidis a try. It seems to work pretty well. I am using latest avrdude git main (built using MSYS2 mingw64).

mcuee commented 1 year ago

No issues with AT89S52 as well.

PS C:\work\avr\avrdude_test\avrdude_bin> .\avrdude -c usbasp -p at89s52 -U .\entest.hex
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5206 (probably 89S52)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file .\entest.hex for flash
         with 512 bytes in 1 section within [0, 0x1ff]
avrdude: writing 512 bytes flash ...
Writing | ################################################## | 100% 1.30 s
avrdude: 512 bytes of flash written
avrdude: verifying flash memory against .\entest.hex
Reading | ################################################## | 100% 0.64 s
avrdude: 512 bytes of flash verified

avrdude done.  Thank you.
orbanp commented 1 year ago

Sorry for the late reply, I was away travelling. Also thanks for the continuing efforts regarding AT89S52 programming!

Writing the AT89S52 chip is working now, however, reading back the code from the chip I get something different! I updated my usbasp programmer with the "usbasp improved" firmware from dioannidis. I used avrdude version 7.1-20230306 (6c8f7e1) on ubuntu 22.04.

As mentioned reading back the written code from the chip results in something different, writing it back again the processor does not work as it is supposed. The code that works was produced by the MCU 8051 IDE programming environment. I am wondering if the hex file formats are different, ihx vs. hex, I have not really looked into this yet.

Thanks, Peter

dioannidis commented 1 year ago

@orbanp

Could you please test with the -B x option ( i.e. -B9 or -B11 ) ?

1      /* 500 Hz */
2      /*   1 kHz */
3      /*   2 kHz */
4      /*   4 kHz */
5      /*   8 kHz */
6      /*  16 kHz */
7      /*  32 kHz */
8      /*  93.75 kHz */
9      /* 187.5  kHz */
10    /* 375 kHz   */
11    /* 750 kHz   */
12    /* 1.5 MHz   */

There is a bug that I couldn't find time to tackle yet .... Error in read after entering PE with slow clocks

orbanp commented 1 year ago

The chip runs at 12MHz.Reading the chip with the -B9 or -B11 option the read files are identical, though they are different from the one read without the -B option.Writing back the "-B11" read file the code works. (Did not test with the "-B9" file.) So it looks like for the correct reading the speed option is required. Thanks, Peter

On Saturday, June 3, 2023 at 04:06:33 p.m. EDT, dioannidis ***@***.***> wrote:  

@orbanp

Could you please test with the -B x option ( i.e. -B9 or -B11 ) ? 1 / 500 Hz / 2 / 1 kHz / 3 / 2 kHz / 4 / 4 kHz / 5 / 8 kHz / 6 / 16 kHz / 7 / 32 kHz / 8 / 93.75 kHz / 9 / 187.5 kHz / 10 / 375 kHz / 11 / 750 kHz / 12 / 1.5 MHz /

There is a bug that I couldn't find time to tackle yet .... Error in read after entering PE with slow clocks

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

dioannidis commented 1 year ago

@orbanp, @mcuee

Can you test with this fw https://github.com/dioannidis/usbasp/releases/download/v1.11/Firmware_ATMega8_12MHz_TPI_HIDUART_SNWRITE_FIX_LOW_SPEED.zip ?

( Tested with an atmega8 with hfuse 0xD9 and lfuse 0xE1 )

regards

dioannidis commented 1 year ago

@orbanp , @mcuee

The v1.11 is released

regards,

orbanp commented 1 year ago

It is working!

I installed v1.11 into the usbasp.I changed in the Makefile the line from "ISP=snap_isp" to "ISP=usbasp". The read function initiates the SCK frequency to 32kHz.The read of the flash and writing it back works OK. Interestingly, the verification (read) part of the flash writing is a lot faster than the single flash read function.

I would like to thank everyone to make the AT89S52 programming with avrdude and usbasp working!

Regards, Peter

dioannidis commented 1 year ago

@orbanp, @mcuee

The read function initiates the SCK frequency to 32kHz.

How do you know that it starts with a 32kHz sck frequency ? You used the avrdude's -B option ? If you did please test without it .

The USBasp's probe function should start with a SCK frequency of 1.5 MHz, trying 3 times ( for both AVR and AT89S* , so it's a little bit slower ), going lower if it didn't get a valid response .

It is working!

I'm glad that it worked !

PS: ( If your USBasp device exposes the RxD/TxD signals to the connector, you can test the HID UART functionality of the firmware using the USBaspHIDUART utility. See also UART HID protocol ) .

regards,

orbanp commented 1 year ago

Leaving out the speed option the reading and writing still works OK!You are correct, I accidentally left in the speed option from yesterday, I have saved the avrdude commands for testing in a text file. According to the documentation usbasp does have the RXD/TXD signals at the ISP connector, however the board (a kit) with the AT89S52 chip does not have those signals connected. I guess I could put those in if I wanted... The kit originally came with a Chinese STC clone processor, that uses a different programming protocol from Atmel's using the RXD/TXD signals. I replaced the STC chip with the Atmel processor. I guess I could test the USBaspHIDUART utility with that STC chip too.Programming the STC chips there is also the stcgal tool for that (I have not used it).

Regards, Peter

On Monday, June 5, 2023 at 07:40:38 a.m. EDT, dioannidis ***@***.***> wrote:  

@orbanp, @mcuee

The read function initiates the SCK frequency to 32kHz.

How do you know that it starts with a 32kHz sck frequency ? You used the avrdude's -B option ? If you did please test without it .

The USBasp's probe function should start with a SCK frequency of 1.5 MHz, trying 3 times ( for both AVR and AT89S* , so it's a little bit slower ), going lower if it didn't get a valid response .

It is working!

I'm glad that it worked !

PS: ( If your USBasp device exposes the RxD/TxD signals to the connector, you can test the HID UART functionality of the firmware using the USBaspHIDUART utility. See also UART HID protocol .

regards,

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>