41
41
42
42
static bool ejected = false;
43
43
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
+
44
55
// Invoked when received SCSI_CMD_INQUIRY
45
56
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
46
57
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) {
63
74
// Application update block count and block size
64
75
void tud_msc_capacity_cb (uint8_t lun , uint32_t * block_count , uint16_t * block_size ) {
65
76
* block_size = BLOCK_SIZE ;
66
- * block_count = BLOCK_COUNT ;
77
+ //*block_count = BLOCK_COUNT;
78
+ * block_count = (lun == 1 ) ? 250 : 100 ;
67
79
}
68
80
69
81
// 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
86
98
// Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
87
99
int32_t tud_msc_read10_cb (uint8_t lun , uint32_t lba , uint32_t offset , void * buffer , uint32_t bufsize ) {
88
100
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 );
90
103
return count * BLOCK_SIZE ;
91
104
}
92
105
93
106
// Callback invoked when received WRITE10 command.
94
107
// Process data in buffer to disk's storage and return number of written bytes
95
108
int32_t tud_msc_write10_cb (uint8_t lun , uint32_t lba , uint32_t offset , uint8_t * buffer , uint32_t bufsize ) {
96
109
uint32_t count = bufsize / BLOCK_SIZE ;
110
+ uint32_t lun_offset = lun == 1 ? 100 : 0 ;
97
111
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 );
100
114
restore_interrupts (ints );
101
115
return count * BLOCK_SIZE ;
102
116
}
0 commit comments