use LUFA as either serial or HID interface

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, i would like to use an AVR Atmega32U4 with LUFA as an HID device, and would also like to make it programmable with any computer. For that, i figured the easiest way would be to have a button on the board the Atmega is located in, linked to one of the digital inputs. If that button is pressed when the board is powered up, it enters a "writing mode". In this mode, the board won't start as an HID device, but as a serial receiver. How can i dynamically switch interfaces after compilation ?

 

Thanks

This topic has a solution.
Last Edited: Sat. Oct 9, 2021 - 09:34 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is kind of what HWB is intended for. If it's asserted at power on it enters a USB bootloader. Dean has loads of examples in LUFA, I always think (from a user perspective) the MSD one is "cleverest". Then just reset. If HWB is not asserted it enters the app and that just enumerates as HID. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, thanks for the answer, however, i am still a beginner with USB and AVRs, so, what does HWB, and MSD stands for ? Is it Mass Storage Device, since the demos are just called MassStorage ?

ALso, how can i exploit the fact that it enters the USB bootloader ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HWB and HWBE are features of Atmel's USB AVR's. HWBE is hardware boot enable. It switches on a system by which the AVR senses the state of the HWB pin at power on and boots to either bootloader or application. Search PDF fow "HWB". 

MSD = Mass Storage Device. Its one of the USB device classes. Dean's bootloader pretends that it is a USB memory stick when plugged into PC, you drag/drop new firmware.bin file to it and the MSD bootloader reprograms the AVR. It's a clever idea. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi !

Sorry for the late reply, but i just can't manage to get the bootloader of the MSD example on my arduino leonard

How can i burn a custom bootloader on an avr chip / development board ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bootloaders can not write to the bootloader area of flash, you will need an isp programmer to do that, one of the cheap USBasp's, or another Arduino acting like an ISP programmer, see any of the many examples of how to do that on the Arduino site, i.e. there is a sketch that does that in the examples folder, then you burn bootloader.

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, i know that, i have a usb uart and another arduino (i am usually using the other arduino), but how to flash the custom bootloader ?

What is the avrdude command to do it ?

 

when selecting burn bootloader in the IDE, the command issued looks like this :

```

[arduino path]/hardware/tools/avr/bin/avrdude -C[arduino path]/hardware/tools/avr/etc/avrdude.conf -v -patmega32u4 -cstk500v1 -PCOM9 -e -Ulock:w:0x3F:m -Uefuse:w:0xFD:m -Uhfuse:w:0xD8:m -Ulfuse:w:0xFF:m

```

but i don't see where i should add the hex file of the bootloader

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

elvyn wrote:
What is the avrdude command to do it ?
Exactly the same as you would program any other program into the AVR - the only thing that makes it a "bootloader" is that the address encoded in the HEX place the code up at the top of flash rather than down at location 0 as for a normal program - avrdude does not know or care.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh my, this is absolutely amazing

Thanks a lot for that, just that bootloader basically solves all of my problems at once, it is just incredible.

I was just wondering 2 things about it :

1: i noticed that all file names were fully capitalised, and after editing the bootloader to make the name of the eeprom lowercase, it seems to be breaking the file, so i assume it is a limitation of the fat format used, but is there a way around that ?

2: would it be possible to have the bootloader recognize any file with the right extention to be the bin for the eeprom ?

I would like to allow the users to have names files, that they don't have to rename to EEPROM.BIN. if it is possible, how would I do that ?

Thanks !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1) there are two levels to FAT16/32. The first is simple and only allowed 8.3 filenames always in upper case only. Then Microsoft added (and patented!) Long File Names (LFN). That allowed for filenames in mixed case and with non-ASCII characters up to 256 characters in length. But the latter violates patents (though maybe expired by now?) and adds a whole new level of complexity if the names contain Unicode characters like Cyrillic, Kanji and so on. It is FAR easier to implement FAT that only does 8.3

 

2) and sure you could program the bootloader to recognise extensions. The two obvious ones being HEX and EEP