-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Add example with TinyUSB and FreeRTOS (for Nucleo-F429ZI)
- Loading branch information
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2022, Raphael Lehmann | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <tusb.h> | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/processing/rtos.hpp> | ||
#include <modm/processing/timer/periodic_timer.hpp> | ||
|
||
using namespace Board; | ||
|
||
class SomeTask : modm::rtos::Thread | ||
{ | ||
public: | ||
SomeTask() : Thread(configMAX_PRIORITIES - 1, 2048, "some_task") {} | ||
|
||
void | ||
run() | ||
{ | ||
modm::PeriodicTimer tmr{2.5s}; | ||
uint8_t counter{0}; | ||
|
||
while (1) | ||
{ | ||
if (tmr.execute()) | ||
{ | ||
MODM_LOG_INFO << "Hello World from USB: " << (counter++) << modm::endl; | ||
} | ||
} | ||
|
||
vTaskDelete(0); | ||
} | ||
}; | ||
|
||
class UsbTask : modm::rtos::Thread | ||
{ | ||
public: | ||
UsbTask() | ||
: Thread(configMAX_PRIORITIES - 1, 2048, "usb_task"), | ||
usb_io_device0{}, | ||
usb_stream0{usb_io_device0} | ||
{} | ||
|
||
void | ||
run() | ||
{ | ||
Board::initializeUsbFs(); | ||
tusb_init(); | ||
|
||
modm::PeriodicTimer tmr{2.5s}; | ||
uint8_t counter{0}; | ||
|
||
while (1) | ||
{ | ||
tud_task(); | ||
if (tmr.execute()) | ||
{ | ||
usb_stream0 << "Hello World from USB: " << (counter++) << modm::endl; | ||
} | ||
} | ||
|
||
vTaskDelete(0); | ||
} | ||
|
||
private: | ||
modm::IODeviceWrapper<UsbUart0, modm::IOBuffer::DiscardIfFull> usb_io_device0; | ||
modm::IOStream usb_stream0; | ||
}; | ||
|
||
SomeTask someTask; | ||
UsbTask usbTask; | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
Leds::setOutput(); | ||
MODM_LOG_INFO << "Nucleo-F429ZI: TinyUSB & FreeRTOS example" << modm::endl; | ||
|
||
modm::rtos::Scheduler::schedule(); | ||
|
||
// we should never get here | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<library> | ||
<extends>modm:nucleo-f429zi</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/nucleo_f429zi/usb_freetros</option> | ||
<option name="modm:tinyusb:config">device.cdc</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:freertos</module> | ||
<module>modm:processing:rtos</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:tinyusb</module> | ||
</modules> | ||
</library> |