Unlike the many other AVR and ARM processors I have used, I have been unable to get atmega4809 to work after 10 hours of trying, now with a simple pared-down program that simply toggles a PORTB pin as a test. The symptoms are that I can read the chip 3 byte signature just fine (0x1e9651), and can program, verify, and even read back from flash my object code with Amel Studio 7, but when run, the chip produces nothing on the i/o pins at all. I have tried everything I can think of to debug this given the non-ICE hardware I have.
Can you help? Help might take one of these three forms, among, perhaps, others:
1. Spot a mistake.
2. Recommend any ideas for further debugging.
3. Try my simple example code on your atmega4809 setup, or some variant of that code.
I have the code running on a board I made that allows general qfp48 chips to be installed in my clamshell socket (pictured, below) with then access to all 48 pins in a simple form factor (patch bay for all pins). All I have hooked up to the 4809 is the 5 or 6 power supply pins, the updi pin to allow programming via atmel studio 7 and stk600, and my oscilloscope on the output pin(s). Other than these 6 or 7 connections, all other 4809 pins are not connected hence are floating. When I program it, the chip just sits there after programming exhibiting no output, and if I disconnect the stk600 ISP connections (really just the updi pin), and power cycle, the chip still produces no output. I am powering with an agilent supply supplying 3v3, thus, power external to the stk600. I have checked the power, and in any case, as I said I can successfully program the flash and read it back, only, my code produces no output.
As far as program code (psg.c, below), I have only the crt (C runtime) for the 4809, some code to desperately ensure that the port is active and not occupied by a USART, to set the direction and initial output, (to get the clk output from the prescalar on an output pin, too) and then to loop and toggle the output pin (at high speed with no delay desperately to ensure the delay code isn't somehow malfunctioning and to avoid introducing complication on the simplest possible code - so one has to look with a scope really to see the toggling output pin, if it would ever toggle).
I have objdumped (psg_elf_objdump.txt, below) the elf file corresponding to the hex file (psg.hex, below) I pushed to the 4809, and I have used atmel studio 7 to read the flash and thus ensure the machine code I read back matches the obdumped vector table and program text for 4809 crt and my main shown in my objdump. I have tried variants of my code, e.g. to use .OUT rather than .OUTTGL. I have tried hooking up oscillators, using an external reset pin after power up, carefully checking fuses and trying different things there, and more. I have verified the peripheral module addresses and other parts of the assembly code match what I expect for 4809.
I also added to the code, as I said, an attempt to output the clock output of the prescaler on one of the pins to avoid relying solely on PORTx setup or weirdness of alternate pin function messing me up (and the clock doesn't show up on that port F pin, so still no output of any kind).
As far as things that still might be wrong, thinking creatively, chip is defective (but I tried another I bought too), internal oscillator isn't starting, but as I understand it simply starts from POR at 20 mhz/6 = 3.33 mhz, so s/b OK at 3v3, chip inundated with interrupts hence code stopped in tracks (but none should be enabled). Perhaps I have a simple mistake somewhere but I don't see it.
I would welcome any recommendations for anything else to try, or anyone else who would push my small binary (or similar code of their own devising) to their atmega4809 to see if it works for them.
I have other questions and oddities I have noted about this new chip, but that is unnecessary complication right now in this plea for help.
Critical part of source code:
int main(void) { PORTMUX.USARTROUTEA = 0xff; // try and disable USARTs in favor of GPIO. PORTMUX.TCAROUTEA = 0x2; PORTB.OUT = 0; PORTB.DIR = 0xff; CCP = 0xd8; CLKCTRL.MCLKCTRLA = 0x80; // see if can get clock out // delay_ms(500); while (1) { PORTB.OUTTGL = 0xff; // delay_ms(1000); } return 0; }
Critical part of objdump:
__trampolines_start(): ../../../../crt1/gcrt1.S:226 a0: 11 24 eor r1, r1 ../../../../crt1/gcrt1.S:227 a2: 1f be out 0x3f, r1 ; 63 ../../../../crt1/gcrt1.S:228 a4: cf ef ldi r28, 0xFF ; 255 ../../../../crt1/gcrt1.S:230 a6: cd bf out 0x3d, r28 ; 61 ../../../../crt1/gcrt1.S:232 a8: df e3 ldi r29, 0x3F ; 63 ../../../../crt1/gcrt1.S:233 aa: de bf out 0x3e, r29 ; 62 ../../../../crt1/gcrt1.S:310 ac: 0e 94 5c 00 call 0xb8 ; 0xb8 <main> ../../../../crt1/gcrt1.S:311 b0: 0c 94 6f 00 jmp 0xde ; 0xde <_exit> 000000b4 <__bad_interrupt>: __vector_38(): ../../../../crt1/gcrt1.S:205 b4: 0c 94 00 00 jmp 0 ; 0x0 <__vectors> 000000b8 <main>: main(): /home/todd/Dev/AVR/test_4809/psg.c:13 static inline void delay_us(uint16_t count); int main(void) { PORTMUX.USARTROUTEA = 0xff; // try and disable USARTs in favor of GPIO. b8: 8f ef ldi r24, 0xFF ; 255 ba: 80 93 e2 05 sts 0x05E2, r24 ; 0x8005e2 <__TEXT_REGION_LENGTH__+0x7005e2> /home/todd/Dev/AVR/test_4809/psg.c:14 PORTMUX.TCAROUTEA = 0x2; be: 92 e0 ldi r25, 0x02 ; 2 c0: 90 93 e4 05 sts 0x05E4, r25 ; 0x8005e4 <__TEXT_REGION_LENGTH__+0x7005e4> /home/todd/Dev/AVR/test_4809/psg.c:15 PORTB.OUT = 0; c4: 10 92 24 04 sts 0x0424, r1 ; 0x800424 <__TEXT_REGION_LENGTH__+0x700424> /home/todd/Dev/AVR/test_4809/psg.c:16 PORTB.DIR = 0xff; c8: 80 93 20 04 sts 0x0420, r24 ; 0x800420 <__TEXT_REGION_LENGTH__+0x700420> /home/todd/Dev/AVR/test_4809/psg.c:18 CCP = 0xd8; cc: 88 ed ldi r24, 0xD8 ; 216 ce: 84 bf out 0x34, r24 ; 52 /home/todd/Dev/AVR/test_4809/psg.c:19 CLKCTRL.MCLKCTRLA = 0x80; // see if can get clock out d0: 80 e8 ldi r24, 0x80 ; 128 d2: 80 93 60 00 sts 0x0060, r24 ; 0x800060 <__TEXT_REGION_LENGTH__+0x700060> /home/todd/Dev/AVR/test_4809/psg.c:24 // delay_ms(500); while (1) { PORTB.OUTTGL = 0xff; d6: 8f ef ldi r24, 0xFF ; 255 /home/todd/Dev/AVR/test_4809/psg.c:24 (discriminator 1) d8: 80 93 27 04 sts 0x0427, r24 ; 0x800427 <__TEXT_REGION_LENGTH__+0x700427> dc: fd cf rjmp .-6 ; 0xd8 <main+0x20> 000000de <_exit>: exit(): /home/todd/tmp_avr_gcc_8.1/gcc-8.1.0/obj-avr/avr/avrxmega3/libgcc/../../../../libgcc/config/avr/lib1funcs.S:2278 de: f8 94 cli 000000e0 <__stop_program>: