Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds TinyUsb based CDC virtual Com port driver with an STM32 port. #748

Merged
merged 14 commits into from
Dec 3, 2023

Conversation

balazsracz
Copy link
Collaborator

  • Adds TinyUsb to path.mk
  • Adds a target directory to compile it for the stm32f072xb MCU
  • Adds a common base class for a TinyUsb based USB stack with CDC device driver
  • Instantiates this for STM32
  • Adds a CAN-USB application target for the STM32F072xB.

The TinyUSBCdc driver is select-enabled. It does not use a Serial base class, because the read and write fifo's are provided by the TinyUsb codebase. We are exercising the application reads and writes directly from those fifos; this saves one unnecessary copy of the data in memory. (There are still two memcpy's; one in the interrupt to the fifo, one in the application code to the application buffer.)

dcd_int_handler(0);
}

}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an "extern "C"" comment here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#include "os/OS.hxx"
#include "utils/Singleton.hxx"

class TinyUsbCdc : public Node, public Singleton<TinyUsbCdc> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This singleton architecture seems to preclude the possibility of multiple CDC endpoints to the same USB peripheral instance. Is that intentional? I suspect this was done so that there is only one USB thread instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not super easy to create multiple CDC endpoints. For reference, the TivaUsbCdc driver doesn't support it either. These are the steps that need to be taken before we can instantiate a second object:

  • change the tinyusbconfig.h (which will have a memory footprint effect)
  • change the USB descriptors
  • update how the thread is started / running
  • update all callbacks to be routed to the right instance
  • figure out what happens on the host OS if there is no second object but the descriptor says there should be

Ultimately I think having two CDCs is a feature request that's not high priority, and at this point it's more important to prevent accidentally creating two instances, which the singleton will do fine.

#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )

#define USB_VID 0xCafe
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mixing upper and lower case hex characters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
uint8_t const *tud_descriptor_device_cb(void) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect open brace style, here and below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed all whitespace

src/freertos_drivers/tinyusb/TinyUsbCdcImpl.hxx Outdated Show resolved Hide resolved
The canusb application could not run in 16kbyte MCU's because it was running out of heap. This PR optimizes it, and handles some long standing work items in the buffering capabilities of openmrn.

- switches can-usb app to use select() based implementation.
- Removes five tasks:
  - CAN-bus read/write threads
  - Serial port read/write tasks
  - merges the main thread and the main executor thread
- Fixes traffic throttling on HubDeviceSelect. It was not on par with HubDevice, as the input data was consumed at an infinite rate. Adds support for the linker option config_gridconnect_port_max_incoming_packets().

===

* Add support for LimitedPool to HubDeviceSelect.
This brings it on par with HubDevice in ensuring that we don't allow too much
data into the memory of the embedded device, and push back on the traffic stream
on the source (USB or TCP should both work).
The limit will be based on the linker option config_gridconnect_port_max_incoming_packets().

* Switches the USB-CAN application to use select()-based implementation.
This dramatically reduces the RAM requirements.

Removes five tasks:
- CAN-bus read/write threads
- Serial port read/write tasks
- merges the main thread and the main executor thread
@balazsracz balazsracz merged commit 4c28fe3 into master Dec 3, 2023
4 checks passed
@balazsracz balazsracz deleted the bracz-stm32-usbcdc branch December 3, 2023 10:38
balazsracz added a commit that referenced this pull request Dec 3, 2023
* master:
  Ensures that 'make clean' empties lib directory of symlinks. (#753)
  Add an input/output GPIO type. This helps support bit banged I2C. (#752)
  Adds TinyUsb based CDC virtual Com port driver with an STM32 port. (#748)
  Limit the amount of input we read into memory in arduino sketches. (#746)
  Updates to send_datagram cmdline utility (#740)
balazsracz added a commit that referenced this pull request Dec 3, 2023
* bracz-lib-clean:
  Ensures that 'make clean' empties lib directory of symlinks. (#753)
  Add an input/output GPIO type. This helps support bit banged I2C. (#752)
  Adds TinyUsb based CDC virtual Com port driver with an STM32 port. (#748)
  Limit the amount of input we read into memory in arduino sketches. (#746)
  Updates to send_datagram cmdline utility (#740)
balazsracz added a commit that referenced this pull request Dec 23, 2023
…t-hub-router

* 'master' of github.com:bakerstu/openmrn: (152 commits)
  Switches over make tests at toplevel to use the tests target instead of the cov target.
  Ensures that openmrn and application directory builds can run in parallel. (#754)
  Ensures that 'make clean' empties lib directory of symlinks. (#753)
  Add an input/output GPIO type. This helps support bit banged I2C. (#752)
  Adds TinyUsb based CDC virtual Com port driver with an STM32 port. (#748)
  Limit the amount of input we read into memory in arduino sketches. (#746)
  Updates to send_datagram cmdline utility (#740)
  Adds lflash command to the bracz-railcom board support makefile.
  Do not crash on an incoming message with 0 alias. (#751)
  Add common app test coverage rules. (#750)
  Fix symlinking of library files to the lib directory. (#747)
  Refactors the SPIFFS flash driver for the F7 into a generic stm32 flash driver. (#742)
  Unaligned read/write support in TivaEEPROM storage (#741)
  Adds support for producer/consumer identified message in the CallbackEventHandler. (#743)
  Improve error handling in BroadcastTimeDefs::string_to_date() (#745)
  Fix test makefiles and test target (#736)
  Moves the bootloader hook so that the hook implementation gets a chance to look at incoming frames.
  Fixes missing includes.
  Fixes missing symbol error.
  Adds stm32f072 HAL drivers to bare.armv6m compilation target.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants