Skip to content

Commit

Permalink
[wip] Update
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Sep 25, 2020
1 parent 5433cdb commit cb7b807
Show file tree
Hide file tree
Showing 35 changed files with 1,129 additions and 170 deletions.
4 changes: 2 additions & 2 deletions examples/stm32f103c8t6_blue_pill/usbserial/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<options>
<option name="modm:build:build.path">../../../build/blue_pill/usbserial</option>
<option name="modm:build:openocd.cfg">openocd.cfg</option>
<option name="modm:tinyusb:config">device.msc,device.midi</option>
<!-- <option name="modm:tinyusb:config">device.cdc,device.msc</option> -->
<!-- <option name="modm:tinyusb:config">device.msc,device.midi</option> -->
<option name="modm:tinyusb:config">device.cdc,device.msc</option>
</options>
<modules>
<module>modm:build:scons</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@

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
Expand All @@ -34,33 +27,9 @@ void tud_umount_cb() { tmr.restart(250ms); }
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::initializeUsb();
tusb_init();

while (true)
{
tud_task();
midi_task();

if (tmr.execute())
{
LedNorth::toggle();
#if CFG_TUD_CDC
static uint8_t counter{0};
usb_stream0 << "Hello World from USB: " << (counter++) << modm::endl;
#endif
}
}

return 0;
}


modm::IODeviceWrapper<UsbUart0, modm::IOBuffer::DiscardIfFull> usb_io_device0;
modm::IOStream usb_stream0(usb_io_device0);

void midi_task()
{
Expand Down Expand Up @@ -100,3 +69,25 @@ void midi_task()
}
#endif
}

int main()
{
Board::initialize();
Board::initializeUsb();
tusb_init();

while (true)
{
tud_task();
midi_task();

if (tmr.execute())
{
LedNorth::toggle();
static uint8_t counter{0};
usb_stream0 << "Hello World from USB: " << (counter++) << modm::endl;
}
}

return 0;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<library>
<extends>modm:disco-f303vc</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f3_discovery/usbserial</option>
<option name="modm:tinyusb:config">device.msc,device.midi</option>
<!-- <option name="modm:tinyusb:config">device.cdc,device.msc</option> -->
<option name="modm:build:build.path">../../../build/stm32f3_discovery/usb</option>
<option name="modm:tinyusb:config">device.cdc,device.msc</option>
<!-- <option name="modm:tinyusb:config">device.cdc,device.midi</option> -->
</options>
<modules>
<module>modm:build:scons</module>
Expand Down
74 changes: 74 additions & 0 deletions examples/stm32f3_discovery/usb_dfu/main.cpp
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);
}
13 changes: 13 additions & 0 deletions examples/stm32f3_discovery/usb_dfu/project.xml
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>
102 changes: 102 additions & 0 deletions examples/stm32f746g_discovery/usb_fs/main.cpp
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
}
Loading

0 comments on commit cb7b807

Please sign in to comment.