Author Topic: ATmegaa32U4 USB with internal RC clock  (Read 8968 times)

0 Members and 1 Guest are viewing this topic.

Offline pburger

  • Contributor
  • Posts: 12
ATmegaa32U4 USB with internal RC clock
« on: November 04, 2014, 04:54:48 pm »
Does anyone have any experience using USB on the ATmega32U4 configured with the internal 8MHz oscillator clock source?

I am unable to communicate with the ATmega32U4 via USB.  |O

My computer (Mac with OS X) does indicate that my board is connected.
I am using an Arduino Uno as a programmer via the ISP interface.
I can successfully burn a boot loader into the chip whilst setting the fuses as required.
My board seems to operate ok and simple test code can be uploaded to it (via the Arduino ISP) and it works as expected.
If the chip is programmed with the fuses set to output the clock on Port C pin 7, then a waveform extremely close to 8MHz is seen.
I have tried setting the LSM bit in UDCON to force low speed USB and this is reported as 1.5MHz by the Computer.
If I try and upload code via the USB connection then the programming fails saying it can't find the device on the port.

Do I have to use a special/modified boot loader to use the internal RC?
Is there anything specific that I have to do in order to get the USB working?
Is there something really basic that I have missed?
Any other suggestions most welcome.
Many thanks in advance...
« Last Edit: November 04, 2014, 07:36:47 pm by pburger »
 

Offline bobcat

  • Regular Contributor
  • *
  • Posts: 94
  • Country: us
Re: ATmegaa32U4 USB with internal RC clock
« Reply #1 on: November 04, 2014, 07:24:54 pm »
I believe the Atmel USB micros use a 12MHz clock for USB.
You should use a crystal or accurate resonator.
Did you burn the Arduino bootloader?
Is the Arduino system compatible with ATMega8?
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #2 on: November 04, 2014, 07:41:47 pm »
Thanks for your reply... however, 8MHz is correct

also, from data sheet....
 
21.4  Crystal-less operation
To reduce external components count and BOM cost, the USB module can be configured to operate in low-speed mode with internal RC oscillator as input source clock for the PLL. The internal RC oscillator is factory calibrated to satisfy the USB low speed frequency accuracy within the 0°C and +40°C temperature range.
For USB full-speed operation only external crystal oscillator or external source clock can be used.

Yes it was the Arduino boot loader for the Arduino Micro.

Sorry - my mistype - its not Mega8... its Mega32U4.... Corrected now!
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #3 on: November 04, 2014, 08:13:26 pm »
What fuses do you set when you burn the boot loader? Can you plug it into a linux computer and run dmesg to see any usb detection messages?

Why do you need to burn a boot loader when there is already one there?
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #4 on: November 05, 2014, 01:55:56 am »
Low Fuse = F2  (or C2 to output clock on PorT C,Pin 7)
High Fuse = D8
Ext Fuse = CB

The chips don't have a boot loader when new (well not one that I can use with an Arduino as ISP programmer as far as I can tell)
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 7357
  • Country: nz
Re: ATmegaa32U4 USB with internal RC clock
« Reply #5 on: November 05, 2014, 02:18:57 am »
This is usually when the OP posts a pic of a messy breadboard with wires everywhere and horrible grounding and we all go Ah ha!
Hehe  ;D
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #6 on: November 05, 2014, 11:21:30 am »

Its only a prototype.... will this do?  ;)
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #7 on: November 05, 2014, 12:06:36 pm »
The chips don't have a boot loader when new (well not one that I can use with an Arduino as ISP programmer as far as I can tell)

If you have the ATMEGA32U4 and not the ATMEGA32U4RC, then I 150% guarantee they come with a usb bootloader from the factory. I have built production devices that rely on that ;) Look up AVR FLIP on google. But if you have ISP programmed the device, then you have already wiped it as it is stored at the start of flash. You can get the hex file from somewhere on Atmel's website if you want to put it back.

You have also disabled the AVR FLIP bootloader from being activated in the fuse settings, see the HWBE fuse bit.

According to http://www.engbedded.com/fusecalc/ your fuses are incorrect. Try: LOW=E2, HIGH=D8, EXT=FB. According to that calculator, you currently have it set to external clock.

hope this helps

Edit: It just occurred to me that either the arduino bootloader or the FLIP bootloader may try to work in full speed mode, in which case you are out of luck.
« Last Edit: November 05, 2014, 12:11:02 pm by jeremy »
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #8 on: November 05, 2014, 12:59:25 pm »
Thanks for your reply Jeremy.
Like an idiot, I mistakenly ordered the non-RC chips  :-[
Unfortunately I'm using a Mac and the Flip and AVR studio run on PCs :-(
I'm checking the fuses suggestion you gave... Not sure what makes it think external clock s in use though.

Re your last edit, this thought had occurred to me, hence my thoughts that a specific/special boot loader hex file may be required?




« Last Edit: November 05, 2014, 01:02:21 pm by pburger »
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #9 on: November 05, 2014, 01:04:04 pm »
Hi pburger,

I'm a mac user too. You can program with them via dfu-programmer. Works on linux as well.

It's easy to install with homebrew: brew install dfu-programmer

then just add this at the top of your makefile:
Code: [Select]
MCU = atmega32u4
TARGET = thingie

and at the bottom
Code: [Select]
flash:
dfu-programmer $(MCU) erase
dfu-programmer $(MCU) flash $(TARGET).hex
dfu-programmer $(MCU) reset

and then 'make flash' will automatically find, program and reset your device. Just make sure there is only one plugged in.
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #10 on: November 05, 2014, 01:06:22 pm »
Like an idiot, I mistakenly ordered the non-RC chips  :-[

The non-RC ones are the ones with the bootloader preinstalled. Sorry if this wasn't clear.
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #11 on: November 05, 2014, 01:31:37 pm »
Thanks again Jeremy... I'll let you know how I get on.
Re preinstalled boot loader: I've re-read what you wrote and it is perfectly clear... I got it wrong!
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #12 on: November 06, 2014, 11:35:22 am »
Quote
According to http://www.engbedded.com/fusecalc/ your fuses are incorrect. Try: LOW=E2, HIGH=D8, EXT=FB. According to that calculator, you currently have it set to external clock.
I have tried this and.... 
1stly: programming the ext fuse to FB fails.... read back gives CB (the original value I used) so looks like the4 bits may not be changeable?
2ndly: Writing FB or CB to the Ext fuse disables the HWBE since 0 is the programmed state.... I tried clearing that bit (sending C3) but not help.
3rdly:  Lo fuse E2 only changes the start up delay... the 2 nibble is the same as I was using and indeed selects internal clock.

Trying to get the DFU-Programer working... can't see any reference to setting the fuses though??
« Last Edit: November 06, 2014, 11:41:38 am by pburger »
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #13 on: November 06, 2014, 12:33:37 pm »
Well I am unsure about for the internal clock, but for external 8MHz crystal I have used this exact command to burn the atmel bootloader to a ton of 32U4RC chips and they all worked:

Code: [Select]
avrdude -p m32u4 -c avrispmkii -U flash:w:ATMega32U4-usbdevice_dfu-1_0_0.hex -U lfuse:w:0x5e:m -U hfuse:w:0x99:m -U efuse:w:0xc3:m
Perhaps you could try this?
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #14 on: November 06, 2014, 01:31:22 pm »
I'll try... although looking at the data sheet this will work for 8MHz external divided by 8 for 1MHz operation so does your USB then still work?


 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #15 on: November 06, 2014, 02:07:04 pm »
It definitely does for me. I pulled this command out of a production script. IIRC I based it on directly reading the fuses from a brand new part.
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #16 on: November 06, 2014, 05:28:50 pm »
Nope - Board is uploadable via ISP and works but no USB... but then my Leonardo board has a 16MHz crystal so the divide my 8 gives 2MHz and the USB requires an 8MHz source.
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #17 on: November 07, 2014, 08:45:31 am »
Is there any way you could swap out the 16 for an 8? I don't think Atmel provides the source for their bootloader. I suppose you could try to modify Caterina though.
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #18 on: November 07, 2014, 10:52:29 am »
Thanks for your continued thoughts, Jeremy.
I see what you're saying.... Effectively duplicating the setup you have used previously... however, I want to use ONLY the internal RC oscillator and have no external clock components at all - and use USB for uploading code.

I am looking into the possibility of modifying Caterina... I think I can see what has to be done, its just I'm not a hardcore programmer and am not sure how to set up and compile/build from the source code.  There is a 'make' file supplied with the Arduino app software, but I think this is for windows machines not a Mac  |O
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #19 on: November 07, 2014, 12:18:19 pm »
I'll take a look. Hang tight
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #20 on: November 07, 2014, 12:40:41 pm »
8MHz version. Compiled on a mac ;) Completely untested as I am overseas. See if it works!

Edit: by the way, I'm pretty sure that these bootloaders disable the effect of the clkdiv8 fuse at runtime. So if you use a 8MHz clock, the bootloader should run at that speed. From caterina:

Code: [Select]
clock_prescale_set(clock_div_1);
« Last Edit: November 07, 2014, 12:47:44 pm by jeremy »
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #21 on: November 07, 2014, 10:30:45 pm »
Jeremy, you are a star  :-+  I can't thank you enough.   

The file you have created works perfectly on both my standard Leonardo board, and my custom PCB which has no external crystal.

(FWIW, I did try enabling the CKDIV8 fuse, but the USB was not recognised by my computer.  Also enabling CKOUT to check gave a 1MHz signal)

As a matter of interest, what did you change in the source/make files to create this?
 

Offline jeremy

  • Frequent Contributor
  • **
  • Posts: 909
  • Country: au
Re: ATmegaa32U4 USB with internal RC clock
« Reply #22 on: November 07, 2014, 10:52:42 pm »
No worries mate, I know what it is like to play usb boot loader games on these chips and it can be frustrating at times ;)

I just changed F_CPU in the makefile to 8000000 and configured the PID/VID, as well as checking that the code did not rely on any fuses related to the clocks.

You can get all of the build tools you need from homebrew and Xcode. I think it's just install Xcode, brew install avr-gcc and you're good to go!
 

Offline pburger

  • Contributor
  • Posts: 12
Re: ATmegaa32U4 USB with internal RC clock
« Reply #23 on: November 07, 2014, 11:13:46 pm »
Well, thanks again, it was very kind of you to take the trouble :) :) :)

I'll take a look at the brew install ave-gcc and see if I can recreate it incase there is a next time  ;)
 

Offline elysion

  • Newbie
  • Posts: 2
  • Country: fi
Re: ATmegaa32U4 USB with internal RC clock
« Reply #24 on: August 26, 2017, 08:36:24 pm »
I am trying to achieve the exact same thing as the OP, but even with the provided bootloader, am unable to get the board show up as a USB device. Burning the bootloader using Arduino IDE works and after the process has completed, the LED_BUILTIN starts to blink, which afaik should indicate that the bootloader is running. Any ideas what might be the issue? Any tips on how to debug this?

Here is the entry from boards.txt I'm using:

micro_int.name=Standalone Micro
micro_int.vid.0=0x03eb
micro_int.pid.0=0x204a

micro_int.upload.tool=avrdude
micro_int.upload.protocol=avr109
micro_int.upload.maximum_size=28672
micro_int.upload.maximum_data_size=2560
micro_int.upload.speed=57600
micro_int.upload.disable_flushing=true
micro_int.upload.use_1200bps_touch=true
micro_int.upload.wait_for_upload_port=true

micro_int.bootloader.tool=avrdude
micro_int.bootloader.low_fuses=0xe2
micro_int.bootloader.high_fuses=0xd8
micro_int.bootloader.extended_fuses=0xfb
micro_int.bootloader.file=caterina-internal/Caterina-eevblog2.hex
micro_int.bootloader.unlock_bits=0x3F
micro_int.bootloader.lock_bits=0x2F

micro_int.build.mcu=atmega32u4
micro_int.build.f_cpu=8000000L
micro_int.build.vid=0x03eb
micro_int.build.pid=0x204a
micro_int.build.usb_product="Standalone Micro"
micro_int.build.board=AVR_LILYPAD_USB
micro_int.build.core=arduino
micro_int.build.variant=leonardo
micro_int.build.extra_flags={build.usb_flags}
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf