tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Rp2040 freertos

Open rppicomidi opened this issue 1 year ago • 9 comments

Describe the PR This draft pull request shows a possible way to implement FreeRTOS support for RP2040. To use FreeRTOS with RP2040, you must install the FreeRTOS-Kernel source in a way that family.cmake can find it. Easiest place to put it is

    ${PICO_SDK_PATH}/../FreeRTOS-Kernel

Make sure to use the smp branch. That is:

    cd ${PICO_SDK_PATH}/../FreeRTOS-Kernel
    git checkout smp

In your project's CMakeFiles.txt, use libraries

    tinyusb_board_freertos, tinyusb_device_freertos,
    tinyusb_host_freertos

instead of the libraries without the '_freertos' suffix

At some point, the FreeRTOS-Kernel smp branch will merge with the main branch. Hopefully, the large number of compiler warnings will be cleared by then.

Additional context See discussion #1951.

Edit: I meant to make this a draft pull request. Anyone know how to change it?

rppicomidi avatar Mar 29 '23 21:03 rppicomidi

@hathach The build pre-comit is failing. I do not understand why file FreeRTOS_Kernel_import.cmake requires a blank line at the end of the file. The file pico_sdk_import.cmake does not have one.

rppicomidi avatar Apr 04 '23 17:04 rppicomidi

@hathach The build pre-comit is failing. I do not understand why file FreeRTOS_Kernel_import.cmake requires a blank line at the end of the file. The file pico_sdk_import.cmake does not have one.

You need to leave an empty line at the end of the file to make ci check happy. On my editor the pico_sdk_import.cmake does have one.

image

hathach avatar Apr 05 '23 03:04 hathach

I am making some chagnes to the cmake as well to better support both esp32 and rp2040 as well as others later on. https://github.com/hathach/tinyusb/tree/cmake . I am currently busy, but once I get that merged first, I will hep to sync up this branch

hathach avatar Apr 05 '23 07:04 hathach

still haven't decided which is best way to do this, but I may follow the approach using by FreeRTOS-kernel https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/CMakeLists.txt which also requires an external file config I.e adding CMakelists.txt that define tinyusb as a lib but requires an target that expose tusb_config.h in the include path. Pico-sdk can define both no os and freertos config, and one that does not speciy the freertos config in the library link will use the no os one. Let me know what you think about this approach.

hathach avatar Apr 21 '23 10:04 hathach

@hathach That works for a single, stand-alone project but I think it does not work if you build the project from the pico-examples project? The top level CMakeLists.txt contains include(pico_sdk_import.cmake) which includes tinyusb build which prevents using the proper CMake variables later.

rppicomidi avatar Apr 24 '23 22:04 rppicomidi

yeah, you are right, I think I will need to add _freertos to the library in the cmakelists.txt target. Another way to solve this is don't inline osal_ function, that allows to link to osal implementation later. However, I don't feel to go that approach since it requires too much changes for existing projects that use tinyusb. _freertos suffix target then, I am also slowly adding cmake target for tinyusb. Will continue to do that and make changes as needed regarding this PR.

hathach avatar May 04 '23 09:05 hathach

fyi, i have been crazy busy, and will be for a bit longer, so apologies for not getting to this yet.

kilograham avatar May 07 '23 15:05 kilograham

fyi, i have been crazy busy, and will be for a bit longer, so apologies for not getting to this yet.

No problems, we are all busy, I am actually working to add cmake build to tinyusb repo as well (for src/ and all other mcu families). Also latest freertos-kernel is adding support for CMake as well https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/CMakeLists.txt

hathach avatar May 09 '23 01:05 hathach

Thank you for making PR, after doing quite a bit of works to support cmake for other mcus, I am getting better with it. I agree that adding tinyusb_device_freertos and tinyusb_host_freertos is best approach. Though I think we should do it in pico-sdk, I also think the freertos-kernel lib should be also added there rather than within tinyusb. That will help pico user by just simply link with freertos-kernel and or tinyusb_device_freertos. Check out my PR to pico-sdk here https://github.com/raspberrypi/pico-sdk/pull/1438 . @kilograham @rppicomidi would you mind review/comment and move our discussion to that.

hathach avatar Jun 27 '23 09:06 hathach