-
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.
- Loading branch information
Showing
35 changed files
with
1,129 additions
and
170 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
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
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...s/stm32f3_discovery/usbserial/project.xml → examples/stm32f3_discovery/usb/project.xml
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
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,74 @@ | ||
/* | ||
* Copyright (c) 2020, Erik Henriksson | ||
* | ||
* 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/io.hpp> | ||
#include <modm/processing.hpp> | ||
|
||
using namespace Board; | ||
|
||
modm::PeriodicTimer tmr{1s}; | ||
|
||
// Invoked when device is mounted | ||
void tud_mount_cb() { tmr.restart(1s); } | ||
// Invoked when device is unmounted | ||
void tud_umount_cb() { tmr.restart(250ms); } | ||
// Invoked when usb bus is suspended | ||
// remote_wakeup_en : if host allow us to perform remote wakeup | ||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus | ||
void tud_suspend_cb(bool) { tmr.restart(2.5s); } | ||
// Invoked when usb bus is resumed | ||
void tud_resume_cb() { tmr.restart(1s); } | ||
|
||
modm_noinit uint64_t dfu_mode; | ||
constexpr uint64_t DFU_MAGIC{0xf318ea89313f2be8}; | ||
|
||
int main() | ||
{ | ||
if (dfu_mode == DFU_MAGIC) | ||
{ | ||
dfu_mode = 0; __DSB(); | ||
// Jump to SystemFlash *before* initializing any peripherals! | ||
asm volatile | ||
( | ||
// Address of SystemFlash differs between devices!!! | ||
"ldr r0, =0x1FFFD800" "\n\t" | ||
"ldr sp,[r0, #0]" "\n\t" | ||
"ldr r0,[r0, #4]" "\n\t" | ||
"bx r0" | ||
); | ||
} | ||
Board::initialize(); | ||
Board::initializeUsb(); | ||
tusb_init(); | ||
|
||
while (true) | ||
{ | ||
tud_task(); | ||
|
||
if (tmr.execute()) | ||
{ | ||
if (dfu_mode == DFU_MAGIC) NVIC_SystemReset(); | ||
LedNorth::toggle(); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
// Invoked on DFU_DETACH request to reboot to the bootloader | ||
void tud_dfu_rt_reboot_to_dfu(void) | ||
{ | ||
dfu_mode = DFU_MAGIC; | ||
// You must delay SystemReset so that TinyUSB can finish!!! | ||
tmr.restart(100ms); | ||
} |
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,13 @@ | ||
<library> | ||
<extends>modm:disco-f303vc</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/stm32f3_discovery/usb_dfu</option> | ||
<option name="modm:tinyusb:config">device.dfu</option> | ||
</options> | ||
<modules> | ||
<module>modm:build:scons</module> | ||
<module>modm:tinyusb</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:io</module> | ||
</modules> | ||
</library> |
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,102 @@ | ||
/* | ||
* Copyright (c) 2020, Erik Henriksson | ||
* | ||
* 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/io.hpp> | ||
#include <modm/processing.hpp> | ||
|
||
using namespace Board; | ||
|
||
#if CFG_TUD_CDC | ||
modm::IODeviceWrapper<UsbUart0, modm::IOBuffer::DiscardIfFull> usb_io_device0; | ||
modm::IOStream usb_stream0(usb_io_device0); | ||
#endif | ||
|
||
modm::PeriodicTimer tmr{1s}; | ||
|
||
// Invoked when device is mounted | ||
void tud_mount_cb() { tmr.restart(1s); } | ||
// Invoked when device is unmounted | ||
void tud_umount_cb() { tmr.restart(250ms); } | ||
// Invoked when usb bus is suspended | ||
// remote_wakeup_en : if host allow us to perform remote wakeup | ||
// Within 7ms, device must draw an average of current less than 2.5 mA from bus | ||
void tud_suspend_cb(bool) { tmr.restart(2.5s); } | ||
// Invoked when usb bus is resumed | ||
void tud_resume_cb() { tmr.restart(1s); } | ||
void midi_task(); | ||
|
||
int main() | ||
{ | ||
Board::initialize(); | ||
Board::initializeUsbFs(); | ||
Leds::setOutput(); | ||
tusb_init(); | ||
|
||
while (true) | ||
{ | ||
tud_task(); | ||
midi_task(); | ||
|
||
if (tmr.execute()) | ||
{ | ||
Leds::toggle(); | ||
#if CFG_TUD_CDC | ||
static uint8_t counter{0}; | ||
usb_stream0 << "Hello World from USB0: " << (counter++) << modm::endl; | ||
#endif | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
void midi_task() | ||
{ | ||
#if CFG_TUD_MIDI | ||
static modm::PeriodicTimer tmr{286ms}; | ||
|
||
if (tmr.execute()) | ||
{ | ||
// Store example melody as an array of note values | ||
static uint8_t note_sequence[] = | ||
{ | ||
74,78,81,86,90,93,98,102,57,61,66,69,73,78,81,85,88,92,97,100,97,92,88,85,81,78, | ||
74,69,66,62,57,62,66,69,74,78,81,86,90,93,97,102,97,93,90,85,81,78,73,68,64,61, | ||
56,61,64,68,74,78,81,86,90,93,98,102 | ||
}; | ||
// Variable that holds the current position in the sequence. | ||
static uint32_t note_pos = 0; | ||
|
||
// Previous positions in the note sequence. | ||
int previous = note_pos - 1; | ||
|
||
// If we currently are at position 0, set the | ||
// previous position to the last note in the sequence. | ||
if (previous < 0) previous = sizeof(note_sequence) - 1; | ||
|
||
// Send Note On for current position at full velocity (127) on channel 1. | ||
tudi_midi_write24(0, 0x90, note_sequence[note_pos], 127); | ||
|
||
// Send Note Off for previous note. | ||
tudi_midi_write24(0, 0x80, note_sequence[previous], 0); | ||
|
||
// Increment position | ||
note_pos++; | ||
|
||
// If we are at the end of the sequence, start over. | ||
if (note_pos >= sizeof(note_sequence)) note_pos = 0; | ||
} | ||
#endif | ||
} |
Oops, something went wrong.