Skip to content

Commit bcbcf43

Browse files
committed
Merge branch 'main' of github.com:bcmi-labs/ArduinoCore-renesas
2 parents 125504e + b4ed6c7 commit bcbcf43

File tree

20 files changed

+1295
-325
lines changed

20 files changed

+1295
-325
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
cores/arduino/mydebug.cpp
33
libraries/Storage/.development
4+
cores/arduino/mydebug.cpp.donotuse

cores/arduino/IRQManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#define ETHERNET_REQ_NUM 1
2121
#define SDCARD_REQ_NUM 3
2222
#define ETHERNET_PRIORITY 12
23-
#define SDCARD_ACCESS_PRIORITY 12
24-
#define SDCARD_DMA_REQ_PRIORITY 12
23+
#define SDCARD_ACCESS_PRIORITY 10
24+
#define SDCARD_DMA_REQ_PRIORITY 10
2525
#define SDCARD_CARD_PRIORITY 12
2626
#define EXTERNAL_PIN_PRIORITY 12
2727
#define UART_SCI_PRIORITY 12

cores/arduino/usb/USB.cpp

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ extern "C" {
5151
#define USBD_HID_EP (0x83)
5252
#endif
5353

54+
#ifndef USBD_MSD_EP_OUT
55+
#define USBD_MSD_EP_OUT (0x04)
56+
#endif
57+
58+
#ifndef USBD_MSD_EP_IN
59+
#define USBD_MSD_EP_IN (0x84)
60+
#endif
61+
62+
#define USBD_MSD_IN_OUT_SIZE (512)
63+
64+
5465
#define USBD_CDC_CMD_MAX_SIZE (8)
5566
#if (CFG_TUSB_RHPORT1_MODE & OPT_MODE_DEVICE)
5667
#define USBD_CDC_IN_OUT_MAX_SIZE (512)
@@ -112,14 +123,18 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
112123
void __SetupUSBDescriptor() {
113124
if (!usbd_desc_cfg) {
114125

115-
uint8_t interface_count = (__USBInstallSerial ? 3 : 0) + (__USBGetHIDReport ? 1 : 0);
126+
uint8_t interface_count = (__USBInstallSerial ? 3 : 0) + (__USBGetHIDReport ? 1 : 0) + (__USBInstallMSD ? 1 : 0);
116127

117128
uint8_t cdc_desc[TUD_CDC_DESC_LEN + TUD_DFU_RT_DESC_LEN] = {
118129
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
119130
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
120131
TUD_DFU_RT_DESCRIPTOR(USBD_ITF_CDC+2, USBD_STR_DFU_RT, 0x0d, 1000, 4096),
121132
};
122133

134+
/*
135+
* ----- HID
136+
*/
137+
123138
size_t hid_report_len = 0;
124139
if (__USBGetHIDReport) {
125140
__USBGetHIDReport(&hid_report_len);
@@ -130,7 +145,19 @@ void __SetupUSBDescriptor() {
130145
TUD_HID_DESCRIPTOR(hid_itf, 0, HID_ITF_PROTOCOL_NONE, hid_report_len, USBD_HID_EP, CFG_TUD_HID_EP_BUFSIZE, 10)
131146
};
132147

133-
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (__USBGetHIDReport ? sizeof(hid_desc) : 0);
148+
/*
149+
* ----- MASS STORAGE DEVICE
150+
*/
151+
152+
uint8_t msd_itf = (__USBInstallSerial ? 3 : 0) + (__USBGetHIDReport ? 1 : 0);
153+
uint8_t msd_desc[TUD_MSC_DESC_LEN] = {
154+
// Interface number, string index, EP Out & EP In address, EP size
155+
TUD_MSC_DESCRIPTOR(msd_itf, 0, USBD_MSD_EP_OUT, USBD_MSD_EP_IN, USBD_MSD_IN_OUT_SIZE)
156+
};
157+
158+
159+
160+
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (__USBGetHIDReport ? sizeof(hid_desc) : 0) + (__USBInstallMSD ? sizeof(msd_desc) : 0);
134161

135162
uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
136163
// Config number, interface count, string index, total length, attribute, power in mA
@@ -152,6 +179,10 @@ void __SetupUSBDescriptor() {
152179
memcpy(ptr, hid_desc, sizeof(hid_desc));
153180
ptr += sizeof(hid_desc);
154181
}
182+
if (__USBInstallMSD) {
183+
memcpy(ptr, msd_desc, sizeof(msd_desc));
184+
ptr += sizeof(msd_desc);
185+
}
155186
}
156187
}
157188
}
@@ -331,7 +362,7 @@ void __USBStart() {
331362
// Invoked when received GET_REPORT control request
332363
// Application must fill buffer report's content and return its length.
333364
// Return zero will cause the stack to STALL request
334-
extern "C" uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
365+
extern "C" __attribute((weak)) uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) {
335366
// TODO not implemented
336367
(void) instance;
337368
(void) report_id;
@@ -344,7 +375,7 @@ extern "C" uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, h
344375

345376
// Invoked when received SET_REPORT control request or
346377
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
347-
extern "C" void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
378+
extern "C" __attribute((weak)) void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) {
348379
// TODO set LED based on CAPLOCK, NUMLOCK etc...
349380
(void) instance;
350381
(void) report_id;
@@ -353,4 +384,40 @@ extern "C" void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_r
353384
(void) bufsize;
354385
}
355386

387+
388+
extern "C" __attribute((weak)) int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
389+
390+
return 0;
391+
}
392+
393+
394+
extern "C" __attribute((weak)) int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) {
395+
396+
return 0;
397+
}
398+
399+
400+
extern "C" __attribute((weak)) void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) {
401+
402+
}
403+
404+
405+
extern "C" __attribute((weak)) bool tud_msc_test_unit_ready_cb(uint8_t lun) {
406+
407+
return false;
408+
}
409+
410+
411+
extern "C" __attribute((weak)) void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size) {
412+
413+
}
414+
415+
416+
extern "C" __attribute((weak)) int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
417+
418+
return -1;
419+
}
420+
421+
422+
356423
#endif

cores/arduino/usb/USB.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern void __USBInstallSerial() __attribute__((weak));
2020
extern void __USBInstallKeyboard() __attribute__((weak));
2121
extern void __USBInstallMouse() __attribute__((weak));
2222
extern void __USBInstallMIDI() __attribute__((weak));
23+
extern void __USBInstallMSD() __attribute__((weak));
2324

2425
// HID report ID inquiry (report ID will vary depending on the number/type of other HID)
2526
extern uint8_t* __USBGetHIDReport(size_t* len) __attribute__((weak));

libraries/BlockDevices/MBRBlockDevice.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include <algorithm>
2121
#include <string.h>
2222

23+
//#define DEBUG_MSD
24+
extern "C" int mylogadd(const char *fmt, ...) ;
2325
//namespace mbed {
2426

2527
// On disk structures, all entries are little endian
@@ -287,10 +289,23 @@ int MBRBlockDevice::init()
287289

288290
// Get partition attributes
289291
sector = std::max<uint32_t>(_bd->get_erase_size(), 512);
292+
#ifdef DEBUG_MSD
293+
mylogadd("MBR sectort %i", sector);
294+
#endif
295+
290296
_type = table->entries[_part - 1].type;
291297
_offset = fromle32(table->entries[_part - 1].lba_offset) * sector;
298+
#ifdef DEBUG_MSD
299+
mylogadd("MBR _offset %i", _offset);
300+
#endif
301+
292302
_size = fromle32(table->entries[_part - 1].lba_size) * sector;
293303

304+
#ifdef DEBUG_MSD
305+
mylogadd("MBR _size %i", _size);
306+
#endif
307+
308+
294309
// Check that block addresses are valid
295310
if (!_bd->is_valid_erase(_offset, _size)) {
296311
err = BD_ERROR_INVALID_PARTITION;
@@ -342,7 +357,9 @@ int MBRBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
342357
if (!is_valid_read(addr, size)) {
343358
return BD_ERROR_DEVICE_ERROR;
344359
}
345-
360+
#ifdef DEBUG_MSD
361+
mylogadd("MBR READ %i, %i", addr + _offset, size);
362+
#endif
346363
return _bd->read(b, addr + _offset, size);
347364
}
348365

@@ -355,7 +372,9 @@ int MBRBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
355372
if (!is_valid_program(addr, size)) {
356373
return BD_ERROR_DEVICE_ERROR;
357374
}
358-
375+
#ifdef DEBUG_MSD
376+
mylogadd("MBR WRITE %i, %i", addr + _offset, size);
377+
#endif
359378
return _bd->program(b, addr + _offset, size);
360379
}
361380

0 commit comments

Comments
 (0)