add freertos version of tinyusb tinyusb_device_freertos and tinyusb_host_freertos #1438

Open
hathach wants to merge 1 commit from hathach/add-tinyusb-freertos into develop
hathach commented 2023-06-27 04:15:30 -05:00 (Migrated from github.com)

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

  • As https://github.com/hathach/tinyusb/discussions/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

This PR intends to add freertos version of tinyusb to make it easier for user application to use tinyusb with freertos. - As https://github.com/hathach/tinyusb/discussions/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
hathach (Migrated from github.com) reviewed 2023-06-27 04:16:04 -05:00
hathach (Migrated from github.com) commented 2023-06-27 04:16:04 -05:00

need to link with freeRTOS kernel lib for osal API.

need to link with freeRTOS kernel lib for osal API.
kilograham commented 2023-06-28 17:24:56 -05:00 (Migrated from github.com)

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.

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 commented 2023-06-28 21:34:46 -05:00 (Migrated from github.com)

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).

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 - https://github.com/hathach/tinyusb/blob/master/src/osal/osal_freertos.h - https://github.com/hathach/tinyusb/blob/master/src/osal/osal_none.h 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).
rppicomidi (Migrated from github.com) reviewed 2023-07-01 18:52:14 -05:00
rppicomidi (Migrated from github.com) commented 2023-07-01 18:52:13 -05:00

@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.

@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.
hathach (Migrated from github.com) reviewed 2023-07-02 00:40:34 -05:00
hathach (Migrated from github.com) commented 2023-07-02 00:40:33 -05:00

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.

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.
warcow105 commented 2024-12-19 08:51:13 -06:00 (Migrated from github.com)

What is the status of this? I updated my sdk a month ago to match this commit while refactoring the code for one of our products to use freertos. Today I was going to update my sdk to 2.1.0 but it doesn't look like this change has made it in yet.

Michael

What is the status of this? I updated my sdk a month ago to match this commit while refactoring the code for one of our products to use freertos. Today I was going to update my sdk to 2.1.0 but it doesn't look like this change has made it in yet. Michael
This pull request has changes conflicting with the target branch.
  • src/rp2_common/tinyusb/CMakeLists.txt
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'hathach/add-tinyusb-freertos:hathach/add-tinyusb-freertos'
git switch 'hathach/add-tinyusb-freertos'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'develop'
git merge --no-ff 'hathach/add-tinyusb-freertos'
git switch 'hathach/add-tinyusb-freertos'
git rebase 'develop'
git switch 'develop'
git merge --ff-only 'hathach/add-tinyusb-freertos'
git switch 'hathach/add-tinyusb-freertos'
git rebase 'develop'
git switch 'develop'
git merge --no-ff 'hathach/add-tinyusb-freertos'
git switch 'develop'
git merge --squash 'hathach/add-tinyusb-freertos'
git switch 'develop'
git merge --ff-only 'hathach/add-tinyusb-freertos'
git switch 'develop'
git merge 'hathach/add-tinyusb-freertos'
git push origin 'develop'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!1438
No description provided.