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

add freertos version of tinyusb tinyusb_device_freertos and tinyusb_host_freertos #1438

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

hathach
Copy link
Contributor

@hathach hathach commented Jun 27, 2023

This PR intends to add freertos version of tinyusb to make it easier for user application to use tinyusb with freertos.

  • As RP2040 + FreeRTOS + TinyUSB: Possible? Sensible? hathach/tinyusb#1951, an tinyusb_device/host_freertos lib should be added in addition to the noos version. Application that use freertos should linked with there _freertos lib. This allow pico-sdk/examples to continue to build all examples without using introcuding another global cmake variable for RTOS.
  • PR baiscally just make existing lib addition more generic, add CFG_TUSB_OS=OPT_OS_FREERTOS to tinyusb_common_freertos and should have no impact on existing user code

Howver, this PR is not complete since tinyusb make use of freeRTOS API and should be linked with freeRTOS-kernel. However, current pico-sdk does not define freertos lib. I don't know if RPI team plan to add rp2_common/freertos but I think this is a good chance to do so. Considering the popular of freeRTOS, adding a CMakelists.txt to pico-sdk make sense since kernel is pretty static. There is only 1 gotcha, like tinyusb freertos need to find path to FreeRTOSConfig.h and port source. Though with latest FreeRTOS, user can simply define freertos-config with include path to config file https://github.com/FreeRTOS/FreeRTOS-Kernel#to-consume-freertos-kernel

If you think adding freertos kernel to pico-sdk makes sense, I can help to make an PR for it (have been adding that for other mcus in the tinyusb repo). Afterwards we can start to add some basic blinky_freertos and hid_composite_freertos to the pico-examples repo.

PS: preping changes in rp2040/family.cmake in tinyusb already done https://github.com/hathach/tinyusb/pull/2128/files#diff-f54d038db87a30de40119b5a78952d17b8464c6de753d37d3b180ce82fa59ad3

target_link_libraries(tinyusb_board INTERFACE tinyusb_bsp)
# FreeRTOS: tinyusb_device_freertos, tinyusb_host_freertos
add_tinyusb_library(freertos)
#target_link_libraries(tinyusb_common_freertos INTERFACE freertos_kernel)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to link with freeRTOS kernel lib for osal API.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hathach function add_tinyusb_library as written has default freertos and exception noos. I think line 27 should be if (RTOS STREQUAL freertos) and the logic that follows should be reversed. Reason is that until now, FreeRTOS has not really been supported for the RP2040.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is for adding other rtos if pico intend to do that in the future, just upper and add the OPT_OS_RTOS to common.

@kilograham kilograham added this to the 1.6.0 milestone Jun 28, 2023
@kilograham
Copy link
Contributor

Lets try to get this in in the 1.6.0 release (we won't be picking up a TinyUSB before that anyway)...

Note that in the pico-sdk, we include libraries that will work with FreeRTOS (e.g. WiFi/BT stuff) but we don't actually include FreeRTOS itself; so we'd do the same for TinyUSB.

In pico-examples, we include examples using FreeRTOS, but again you have to set FREERTOS_KERNEL_PATH to include them.

I will need to understand a little more about FreeRTOS/TinyUSB - e.g. how/if the threading model is changed.

@hathach
Copy link
Contributor Author

hathach commented Jun 29, 2023

oh, sorry, I wasn't paying attention much to wifi/b and didn't know freeRTOS is meant to be used with FREERTOS_KERNEL_PATH, was thinking about the lib approach. I will checkout those example real quick and update PR if needed.

I will need to understand a little more about FreeRTOS/TinyUSB - e.g. how/if the threading model is changed.

TinyUSB will use freeRTOS API (semaphore/queue) for its internal usage instead of spinlock provided by pico-sdk

However, stdio_usb may need some changes, e.g instead of usign svc interrupt to call tud_task() and cdc_flush() you should put it in an dedicated thread with decent priority. Since freeRTOS API is different in thread and ISR context (could cause kernel panic if not right).

@kilograham kilograham self-assigned this May 19, 2024
@kilograham kilograham modified the milestones: 1.6.1, 1.7.0 Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants