Skip to content

Commit 26d1edc

Browse files
committed
[ext] Update TinyUSB to v0.16.0
1 parent 2381c61 commit 26d1edc

File tree

8 files changed

+67
-22
lines changed

8 files changed

+67
-22
lines changed

examples/generic/usb/msc_disk.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
#if CFG_TUD_MSC
2929

30+
// whether host does safe-eject
31+
static bool ejected = false;
32+
3033
// Some MCU doesn't have enough 8KB SRAM to store the whole disk
3134
// We will use Flash as read-only disk with board that has
3235
// CFG_EXAMPLE_MSC_READONLY defined
@@ -136,7 +139,14 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun)
136139
{
137140
(void) lun;
138141

139-
return true; // RAM disk is always ready
142+
// RAM disk is ready until ejected
143+
if (ejected) {
144+
// Additional Sense 3A-00 is NOT_FOUND
145+
tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
146+
return false;
147+
}
148+
149+
return true;
140150
}
141151

142152
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
@@ -165,6 +175,7 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, boo
165175
}else
166176
{
167177
// unload disk storage
178+
ejected = true;
168179
}
169180
}
170181

@@ -177,10 +188,24 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
177188
{
178189
(void) lun;
179190

191+
// out of ramdisk
192+
if ( lba >= DISK_BLOCK_NUM ) return -1;
193+
180194
uint8_t const* addr = msc_disk[lba] + offset;
181195
memcpy(buffer, addr, bufsize);
182196

183-
return bufsize;
197+
return (int32_t) bufsize;
198+
}
199+
200+
bool tud_msc_is_writable_cb (uint8_t lun)
201+
{
202+
(void) lun;
203+
204+
#ifdef CFG_EXAMPLE_MSC_READONLY
205+
return false;
206+
#else
207+
return true;
208+
#endif
184209
}
185210

186211
// Callback invoked when received WRITE10 command.
@@ -189,14 +214,17 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
189214
{
190215
(void) lun;
191216

217+
// out of ramdisk
218+
if ( lba >= DISK_BLOCK_NUM ) return -1;
219+
192220
#ifndef CFG_EXAMPLE_MSC_READONLY
193221
uint8_t* addr = msc_disk[lba] + offset;
194222
memcpy(addr, buffer, bufsize);
195223
#else
196224
(void) lba; (void) offset; (void) buffer;
197225
#endif
198226

199-
return bufsize;
227+
return (int32_t) bufsize;
200228
}
201229

202230
// Callback invoked when received an SCSI command not in built-in list below
@@ -207,18 +235,13 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
207235
// read10 & write10 has their own callback and MUST not be handled here
208236

209237
void const* response = NULL;
210-
uint16_t resplen = 0;
238+
int32_t resplen = 0;
211239

212240
// most scsi handled is input
213241
bool in_xfer = true;
214242

215243
switch (scsi_cmd[0])
216244
{
217-
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
218-
// Host is about to read/write etc ... better not to disconnect disk
219-
resplen = 0;
220-
break;
221-
222245
default:
223246
// Set Sense = Invalid Command Operation
224247
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
@@ -235,14 +258,14 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
235258
{
236259
if(in_xfer)
237260
{
238-
memcpy(buffer, response, resplen);
261+
memcpy(buffer, response, (size_t) resplen);
239262
}else
240263
{
241264
// SCSI output
242265
}
243266
}
244267

245-
return resplen;
268+
return (int32_t) resplen;
246269
}
247270

248271
#endif

ext/hathach/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def build(env):
9898
# PMA buffer size: 512B or 1024B
9999
env.copy("tinyusb/src/portable/st/stm32_fsdev/", "portable/st/stm32_fsdev/")
100100
else:
101-
env.copy("tinyusb/src/portable/st/synopsys", "portable/st/synopsys/")
101+
env.copy("tinyusb/src/portable/synopsys/dwc2/", "portable/synopsys/dwc2/")
102102

103103
elif target.platform == "sam":
104104
if target.family == "g5x":

ext/hathach/tinyusb

Submodule tinyusb updated 123 files

ext/hathach/tusb_config.h.in

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@
3434

3535
// Redirect TinyUSB asserts to use modm_assert
3636
#define MODM_ASSERT_1ARGS(_cond) \
37-
TU_VERIFY_DEFINE(_cond, modm_assert(0, "tu", \
38-
__FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #_cond "\""), false)
37+
do { \
38+
modm_assert(_cond, "tu", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #_cond "\""); \
39+
} while(0)
3940

4041
#define MODM_ASSERT_2ARGS(_cond, _ret) \
41-
TU_VERIFY_DEFINE(_cond, modm_assert_continue_fail(0, "tu", \
42-
__FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #_cond "\""), _ret)
42+
do { \
43+
if (!modm_assert_continue_fail(_cond, "tu", __FILE__ ":" MODM_STRINGIFY(__LINE__) " -> \"" #_cond "\"")) \
44+
{ return _ret; } \
45+
} while(0)
4346

4447
#define TU_ASSERT(...) _GET_3RD_ARG(__VA_ARGS__, MODM_ASSERT_2ARGS, MODM_ASSERT_1ARGS,UNUSED)(__VA_ARGS__)

ext/hathach/uart.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
#pragma once
1414

15+
#if defined(CFG_TUD_CDC) && CFG_TUD_CDC
16+
1517
#include <modm/architecture/interface/uart.hpp>
1618
#include "tusb.h"
1719

@@ -118,3 +120,5 @@ using UsbUart2 = UsbUart<2>;
118120
using UsbUart3 = UsbUart<3>;
119121

120122
} // namespace modm::platform
123+
124+
#endif

ext/rp/irq.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ irq_set_enabled(int irqn, bool enable)
2424
}
2525

2626
static inline void
27-
irq_set_exclusive_handler(int irqn, void (*handler)())
27+
irq_set_exclusive_handler(int irqn, void (*handler)(void))
2828
{
2929
(void) irqn;
3030
(void) handler;
3131
// do nothing, irq implemented at modm
3232
}
3333

3434
static inline void
35-
irq_add_shared_handler(unsigned int irqn, void (*handler)(), uint8_t order_priority)
35+
irq_add_shared_handler(unsigned int irqn, void (*handler)(void), uint8_t order_priority)
3636
{
37-
(void) irqn;
38-
(void) handler;
39-
(void) order_priority;
37+
(void) irqn;
38+
(void) handler;
39+
(void) order_priority;
4040
}
4141

4242
#define PICO_SHARED_IRQ_HANDLER_HIGHEST_ORDER_PRIORITY 0xff

ext/rp/module.lb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def build(env):
4747
env.copy("irq.h", "hardware/irq.h")
4848
env.copy("timer.h", "hardware/timer.h")
4949
env.copy("resets.h", "hardware/resets.h")
50+
env.copy("sync.h", "hardware/sync.h")
5051

5152
env.substitutions = {
5253
"headers": headers,

ext/rp/sync.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) 2024, Niklas Hauser
3+
*
4+
* This file is part of the modm project.
5+
*
6+
* This Source Code Form is subject to the terms of the Mozilla Public
7+
* License, v. 2.0. If a copy of the MPL was not distributed with this
8+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
9+
*/
10+
// ----------------------------------------------------------------------------
11+
12+
// Stripped down header "hardware/sync.h" for tinyusb
13+
14+
#define remove_volatile_cast(t, x) ({ __asm volatile ("dmb" ::: "memory"); (t)(x); })

0 commit comments

Comments
 (0)