8000 Experimental dual MSC. · micropython/micropython@c9519df · GitHub
[go: up one dir, main page]

Skip to content

Commit c9519df

Browse files
committed
Experimental dual MSC.
1 parent 5131dbd commit c9519df

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
// Board and hardware specific configuration
22
#define MICROPY_HW_BOARD_NAME "Raspberry Pi Pico"
33
#define MICROPY_HW_FLASH_STORAGE_BYTES (1408 * 1024)
4+
5+
#define MICROPY_HW_USB_MSC (1)
6+
#define MICROPY_HW_USB_VID (0x1FFB)
7+
#define MICROPY_HW_USB_PID (0x2043)
8+
#define MICROPY_HW_USB_DESC_STR_MAX (40)
9+
#define MICROPY_HW_USB_MANUFACTURER_STRING "Pimoroni"
10+
#define MICROPY_HW_USB_PRODUCT_FS_STRING MICROPY_HW_BOARD_NAME " MicroPython"
11+
12+
#define MICROPY_BANNER_MACHINE MICROPY_HW_BOARD_NAME

ports/rp2/modules/_boot_fat.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
import os
22
import machine, rp2
33

4+
# 1441792
5+
bdev_root = rp2.Flash(start=0, len=4096 * 100)
6+
bdev_storage = rp2.Flash(start=4096 * 100, len=4096 * 250)
47

5-
# Try to mount the filesystem, and format the flash if it doesn't exist.
6-
bdev = rp2.Flash()
78
try:
8-
vfs = os.VfsFat(bdev)
9-
os.mount(vfs, "/")
9+
vfs_root = os.VfsFat(bdev_root)
10+
os.mount(vfs_root, "/", readonly=True)
1011
except:
11-
os.VfsFat.mkfs(bdev)
12-
vfs = os.VfsFat(bdev)
13-
vfs.label("RP2_MSC")
14-
os.mount(vfs, "/")
12+
os.VfsFat.mkfs(bdev_root)
13+
vfs_root = os.VfsFat(bdev_root)
14+
vfs_root.label("Root")
1515

16-
del os, bdev, vfs
16+
os.mount(vfs_root, "/", readonly=True)
17+
18+
try:
19+
vfs_storage = os.VfsFat(bdev_storage)
20+
os.mount(vfs_storage, "/storage")
21+
except:
22+
os.VfsFat.mkfs(bdev_storage)
23+
vfs_storage = os.VfsFat(bdev_storage)
24+
vfs_storage.label("Storage")
25+
26+
os.mount(vfs_storage, "/storage")
27+
28+
del os, bdev_root, bdev_storage, vfs_storage, vfs_root

ports/rp2/msc_disk.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@
4141

4242
static bool ejected = false;
4343

44+
// Invoked to determine max LUN
45+
uint8_t tud_msc_get_maxlun_cb(void)
46+
{
47+
return 2; // dual LUN
48+
}
49+
50+
bool tud_msc_is_writable_cb (uint8_t lun)
51+
{
52+
return lun == 0; // Only BOOT is writable from host, storage is not
53+
}
54+
4455
// Invoked when received SCSI_CMD_INQUIRY
4556
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
4657
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]) {
@@ -63,7 +74,8 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
6374
// Application update block count and block size
6475
void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) {
6576
*block_size = BLOCK_SIZE;
66-
*block_count = BLOCK_COUNT;
77+
//*block_count = BLOCK_COUNT;
78+
*block_count = (lun == 1) ? 250 : 100;
6779
}
6880

6981
// Invoked when received Start Stop Unit command
@@ -86,17 +98,19 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, boo
8698
// Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
8799
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) {
88100
uint32_t count = bufsize / BLOCK_SIZE;
89-
memcpy(buffer, (void *)(FLASH_MMAP_ADDR + lba * BLOCK_SIZE), count * BLOCK_SIZE);
101+
uint32_t lun_offset = lun == 1 ? 100 : 0;
102+
memcpy(buffer, (void *)(FLASH_MMAP_ADDR + (lun_offset + lba) * BLOCK_SIZE), count * BLOCK_SIZE);
90103
return count * BLOCK_SIZE;
91104
}
92105

93106
// Callback invoked when received WRITE10 command.
94107
// Process data in buffer to disk's storage and return number of written bytes
95108
int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) {
96109
uint32_t count = bufsize / BLOCK_SIZE;
110+
uint32_t lun_offset = lun == 1 ? 100 : 0;
97111
uint32_t ints = save_and_disable_interrupts();
98-
flash_range_erase(FLASH_BASE_ADDR + lba * BLOCK_SIZE, count * BLOCK_SIZE);
99-
flash_range_program(FLASH_BASE_ADDR + lba * BLOCK_SIZE, buffer, count * BLOCK_SIZE);
112+
flash_range_erase(FLASH_BASE_ADDR + (lun_offset + lba) * BLOCK_SIZE, count * BLOCK_SIZE);
113+
flash_range_program(FLASH_BASE_ADDR + (lun_offset + lba) * BLOCK_SIZE, buffer, count * BLOCK_SIZE);
100114
restore_interrupts(ints);
101115
return count * BLOCK_SIZE;
102116
}

0 commit comments

Comments
 (0)
0