Recent

Author Topic: New project, FPC code for USB on a AVR ?  (Read 1682 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 271
New project, FPC code for USB on a AVR ?
« on: October 19, 2023, 12:58:35 pm »
Does anybody know if there is example code to USB on a AVR with freepascal example code? Including freepascal example code for the WIN32 driver ?

Here is a diagram for my next project, weeks from now...

The idea is to build a new enclosure with 6 UARTs on it to connect to your WIN32 machine without using a old UART serial port.

Just use 6 AVR's inside and connect them with I2C to my RPI MOD

Solutions:

RPI MOD ZERO: takes booting.
USB for AVR: Is there a FPC library ?
Raspberry pico: Is there USB or WIFI with freepascal?

Can anybody answer if the USB solution is going to work out?

Greets, Wouter van Wegen, PascalByThree

d.ioannidis

  • Full Member
  • ***
  • Posts: 229
    • Nephelae
Re: New project, FPC code for USB on a AVR ?
« Reply #1 on: October 19, 2023, 02:57:19 pm »
Hi,

  AFAIU, you'll connect the RPI Zero's USB to Host and talk to AVRs via I2C from the RPI Zero correct ? In that case, you don't need any AVR USB code.

  Also, can I suggest to replace the RPI Zero with a MCP2221A to make your life easier ? ( it comes in DIP package also.... ;)  )

  If you want to connect the AVR "directly" to USB, then you'll need an AVR with USB peripheral ( i.e. ATMega32U2/4 ) or use the very old V-USB library which unfortunately is in C .

regards,

 

avra

  • Hero Member
  • *****
  • Posts: 2539
    • Additional info
Re: New project, FPC code for USB on a AVR ?
« Reply #2 on: October 19, 2023, 03:12:14 pm »
Does anybody know if there is example code to USB on a AVR with freepascal example code? Including freepascal example code for the WIN32 driver ?
You have to be more specific, since this contradicts to your drawing where you use 328P AVRs which do not have USB hardware on them and direct USB connection to Pi or pc. If they do not talk USB, why you need AVR freepascal code on AVR?
In general, there are many ways to skin a cat. Some are easy, some are complex, and some might not be available for your favorite hardware or language. We might be talking about USB capable MCU which we might access via USB CDC as a virtual serial port without need for a custom driver, or access directly via libusb and some custom code. Or we might be talking about USB uncapable MCU which we might access using some USB<>TTL bridge chip like CH340 or FT232R and use manufacturer USB driver to use it as a virtual serial port or bitbang GPIO. It is not 100% clear what are you trying to achieve. We might even be talking about AVRs where we would like to emulate USB CDC or USB HID in software and use them as if they are real USB devices. See how much possibilities are there?

The idea is to build a new enclosure with 6 UARTs on it to connect to your WIN32 machine without using a old UART serial port.
If I understood well, the idea would be to have 6 bidirectional UARTS connected to Windows pc without using classic RS232 DB9 ports, and implementation details would be to have Raspberry Pi Zero connected via i2c to 6 AVRs and read/write their UART streams, and having Pi deliver all that data to Windows pc over USB, and having a way to physically switch on/off each channel and display it's status over leds and display? Is that right?
If I had to do it, I would make it with a much lower complexity, by simply using out of the shelf components like CH348 which supports up to 8 ports and even has enough GPIO to control leds, switches, and even a display, using provided virtual serial port for communication and DLL for GPIO. You can test it for cheap (https://www.aliexpress.com/item/1005005677493754.html), find more info (https://www.cnx-software.com/2022/03/04/wch-ch348-8-port-usb-to-serial-chip-with-up-to-48-gpios/), or read datasheet directly. Going more closer to your route, I would choose AVR with many UARTS (ATxmega128A1U has 8 UARTS and no USB HW, ATxmega32A4U has only 5 UARTS but has USB HW) and avoid using Pi at all. You could also use some USB FTDI chip to access your 6 AVRs over I2C, but without simple virtual serial port access you would have to deal your self with quite a lot manually.
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

MarkMLl

  • Hero Member
  • *****
  • Posts: 8364
Re: New project, FPC code for USB on a AVR ?
« Reply #3 on: October 20, 2023, 08:17:14 am »
https://www.obdev.at/products/vusb/index.html

Nobody in his right mind would try to recode this in a different language. Either learn enough C to do the job properly, budget for USB converter chips, or use a different microcontroller.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

avra

  • Hero Member
  • *****
  • Posts: 2539
    • Additional info
Re: New project, FPC code for USB on a AVR ?
« Reply #4 on: October 21, 2023, 01:40:23 pm »
Nobody in his right mind would try to recode this in a different language.
Soft USB is indeed a special kind of a beast. However, AvrCo Pascal (freeware at the moment) has AVR HW USB support with libusb on the pc side, and XMEGA USB CDC support with virtual serial port on the pc side. I also used custom made HW USB AvrCo CDC lib (closed source unfortunately) many moons ago when AvrCo didn't yet support USB, and even had to use C++ on STM32 when I needed composite USB device (HID JOY+KEYB+MOUSE).
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

 

TinyPortal © 2005-2018