32u4 - LUFA - MAX3421e

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

Hi guys,

 

During my personal development (honestly, I started with AVRs two months ago) I came to the point I would like to resolve following issues. I've tried already to search for answers but no luck, so I will ask here if I can.

Currently I'm using Nano but would like to switch to 32u4 (Leonardo) for added direct USB_DEVICE through LUFA and USB Shield as USB_HOST.

Target application would/should accept device from USB_HOST, filter/add messages and send it via USB_DEVICE.

 

1. Is it possible / does someone did it before / do you know of some project which successfully implemented/ported/drivered LUFA to MAX3421e USB Shield?

- doing so would reduce code space due to duplicate implementation of USB stacks

- I haven't tried this so far, but duplicate USB.h from USBHostShieldLibrary makes me suspicious of a lot of problems, and it will add Arduino framework dependence which is something I would like to avoid at the final stage of development (yes, I'm using part of it as for now, but trying to eliminate code dependent on it) 

- could be possible to add 3421e comm module and incorporate build switch for LUFA use it as USB_HOST together with 32u4 as USB_DEVICE?

- any directions?

 

- ported on HOST side of LUFA. Now 32u4 is device, MAX is host.

 

2. Smaller bootloader for 32u4

- 4kB for bootloader is quite too much as I see progress and code size of my project

- do exists some smaller bootloaders? I've so far haven't found any smaller for 32u4

- ideal would be to have very small bootloader which can be used solely for main program upload via serial (as usually) through Atmel Studio

- here comes the idea

 

3. Unified program/upload code

- as most probably bootloader and main program use the same code, would it be possible to incorporate upload/reflash code into main program to have needed routines/functions to reside only once in a flash?

- some kind of upload code with needed functions relocated to upper(?) bound of flash which would be then not erased while flashing main program and shared with main program

- this is just an idea worth of ~3kB of flash and honestly, I'm not able to do it, but maybe someone can/got experience/got this idea further

 

- gave up on this, figured how to use another arduino asi isp programmer. Bootloader on Leonardo is gone anyway.

- finally USBasp ISP programmer works with avrdude, so no need for another Arduino for ISP programming. Don't know why, but this DOESN'T WORK WITHOUT erase flash option in avrdude. Be prepared to loose bootloader.

 

4. Advice how to use ISP programmer with USB Host Shield attached to Leonardo

- in case of a need of additional 4kB of bootloader to be used for main program, there isn't much more chance to reflash than using ISP

- ISP header is occupied with shield

- removing shield/attach ISP/upload/attach shield procedure is a complete no-go

- any ideas?

 

- resoldered another 'pass-through' ICSP header - gonna try this if ISP will passthrough

- seems thato connecting USB Shield SS to active HIGH (5V) before first upload will make it work for avrdude to flash program.

 

5. How to upload code to Leonardo using Atmel Studio

- by clicking just Run-without-Debugging as it is (for me) standard procedure

- I was using Nano with VisualMicro for Arduino an this worked this way

- When I've tried LUFA example, this way was not working, only when I've tried new Arduino sketch from File-New it was working

 

- added custom external tools buttons with avrdude commands. I don't know why, but upload didn't work from Atmel studio when -D parameter has been set. Arduino IDE with same avrdude command haven't touched bootloader, but Atmel Studio did. So I'm finally without bootloader on Lenoardo so I gave up on bootloader issues (one problem solved ;) ) 

 

Thanks a lot for any help.

 

Regards

T.

 

- it's been a long day. Afterall make MAX3421e chip on USB host shield to work with LUFA is the greatest challenge of all of these.

 

- It was.

 

 

 

 

 

Last Edited: Wed. Mar 4, 2015 - 10:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want an AVR that can do both host and device wouldn't you be better off simply looking at AT90USB647 and AT90USB1287 which have "On The Go" (OTG) which is a limited (though usually enough) version of host mode. It would save trying to add an external host controller.

 

What's more you can buy the AT90USBKEY for $29 which is a very nice little board based around the 1287.

 

Also, as I read your post I sort of assumed the MAX3241e you mentioned in point (1) must be a USB host controller but having now looked it up I see that it's nothing more than an updated MAX232 - an inverter and level driver to boost TTL UART to RS232 levels. Exacly what has this got to do with USB Host mode?!?

 

As for smaller bootloaders. There's a product called "Teensy" https://www.pjrc.com/teensy/ that has a USB bootloader in 512 bytes which proves it can be done but I'd just start with LUFA, set it for your 32U4 and see how small each of Dean's bootloaders builds for. I guess there might be a 2K one. The 32U4 boot sizes are 4K, 2K, 1K and 512bytes. But in 32K why does the odd 1K or two make that much difference?

 

While you could make a bootloader share its routines with the app the fact is that usually this does not make a lot of sense as you want the bootloader to enumerate as some class of device (like DFU or MSD or whatever) and you want the app to enumerate at something completely different (like CDC or MIDI or Printer or whatever) so the actual data channel in each case is likely to be different (in part this is what HWB is all about).

 

All your post seems to be about saving flash. If you are just starting out and selecting a chip then if you think space will be tight in 32K why not simply select a 64K or 128K device instead? There's no point picking something that's "a bit too small" then spending your life engineering ways to try an shoe-horn everything you want into it. (unless you are talking about making 10,000+ of whatever this is?)

 

As for programming - just set up an toolbar icon or menu entry to launch the external programming tool (Flip or avrdude or whatever).

 

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

dawson, thank for your reply.

 

as to your comments

- I have several 32u4 boards around and trying to design some 'framework' usable with, or without usb host. Those AT90USB seems to be bit pricy, hard to get and doesn't it have just one physical port?

- I have choosen 32u4 due to pricing and (you can laugh, but) to challenge myself to be able to put what I want into these restrictions. And want it to have as simple as it gets.

- 3241e is of course typo, it should be 3421e. I've updated  my first post.

- Yes, I know about Teensy, but until I will really hit the limits for avr8 platform, I don't want to give up. There is a lot of code dependent on architecture already written (for now I think I'm using only Serial class from Arduino), and I don't see myself to port it to different platform. 

- OK, I will try to compile Dean's bootloaders to see what size it will fit, but my main program is hitting 23kB already without LUFA (ok, I can maybe strip some 1kB of debug from it) and this is just hw framework with the main functionality to be added after resolving whole design picture. 1kB maybe won't make that difference, but 4kB can. It would be nice to have some bootloader during development phase as I haven't found the way how to program it with shield attached. 

- Sharing routines with bootloader easily can strip down a big portion of bootloader, thus retaining needed routines for reuse. Unneeded comm for final application can be then just disabled in release build wasting really only small part of flash, or can be omitted altogether.

- to memory size, as I said, this challenge is part of the road for me. Believe it not, it is quite rewarding when I find a way how to implement something with smaller footprint as I would be on first shot. This is my personal project, and since I haven't been programming professionally ever (though laid my first code some 30 years ago and been sporadically programming just for fun through the years), I take it as good brain training. And I honor given resources as best I can ;)  And believe me, I have learned a lot during last month and that feeling when you hit the limit, thinks about getting 'bigger' platform and then after spending time for optimize the code you can eliminate that showstopper and can progress forward... When I hit it, I will hit it with knowledge.

 

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

Modify the usb shield by lifting pin 1 of ic3 and connecting it to pin2 of ic8. This should solve the isp problem.

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

Kartman wrote:

Modify the usb shield by lifting pin 1 of ic3 and connecting it to pin2 of ic8. This should solve the isp problem.

Hi Kartman, 

 

could You please give me more info? what is ic3/ic8 on USB Host shield? Thanks a lot.

T.

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

I just Googled for the shield schematic. That's all i know! There's probably a overlay drawing that tells you where ic3 and 8 are.