Skip to content

Commit f98c7f7

Browse files
committed
merge review
1 parent 10846d3 commit f98c7f7

File tree

6 files changed

+76
-88
lines changed

6 files changed

+76
-88
lines changed

ports/nrf/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ else
1010
endif
1111
endif
1212

13+
include boards/$(BOARD)/mpconfigboard.mk
14+
1315
SD_LOWER = $(shell echo $(SD) | tr '[:upper:]' '[:lower:]')
1416

1517
# Build directory with SD
16-
BUILD = $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD))
18+
BUILD ?= $(if $(SD),build-$(BOARD)-$(SD_LOWER),build-$(BOARD))
1719

1820
include ../../py/mkenv.mk
19-
include boards/$(BOARD)/mpconfigboard.mk
2021
-include mpconfigport.mk
2122

2223
ifneq ($(SD), )

ports/nrf/boards/feather52832/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ BOOT_FILE = boards/feather52832/bootloader/feather52_bootloader_$(SOFTDEV_VERSIO
99

1010
BOOT_SETTING_ADDR = 0x7F000
1111
NRF_DEFINES += -DNRF52832_XXAA
12-
NRF_DEFINES += -DADAFRUIT_FEATHER52

ports/nrf/boards/feather52840/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ else
1414
endif
1515

1616
NRF_DEFINES += -DNRF52840_XXAA
17-
NRF_DEFINES += -DADAFRUIT_FEATHER52840

ports/nrf/boards/pca10056/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ endif
1515

1616

1717
NRF_DEFINES += -DNRF52840_XXAA
18-
NRF_DEFINES += -DADAFRUIT_FEATHER52840

ports/nrf/internal_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ uint32_t _flash_page_addr = NO_CACHE;
5757
/* Internal Flash API
5858
*------------------------------------------------------------------*/
5959
static inline uint32_t lba2addr(uint32_t block) {
60-
return ((uint32_t)__fatfs_flash_start_addr) + block * FILESYSTEM_BLOCK_SIZE;
60+
return ((uint32_t)__fatfs_flash_start_addr) + block * FILESYSTEM_BLOCK_SIZE;
6161
}
6262

6363
void internal_flash_init(void) {

ports/nrf/usb/usb_msc_flash.c

Lines changed: 72 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
*/
3535
/**************************************************************************/
3636

37-
#ifdef NRF52840_XXAA
38-
3937
#include "tusb.h"
4038
#include "internal_flash.h"
4139

@@ -55,9 +53,6 @@
5553

5654
#define FL_PAGE_SZ 4096
5755

58-
/*------------------------------------------------------------------*/
59-
/* VARIABLES
60-
*------------------------------------------------------------------*/
6156
static scsi_sense_fixed_data_t mscd_sense_data =
6257
{
6358
.response_code = 0x70,
@@ -73,114 +68,109 @@ static scsi_mode_parameters_t const msc_dev_mode_para =
7368
.block_descriptor_length = 0
7469
};
7570

76-
/*------------------------------------------------------------------*/
77-
/*
78-
*------------------------------------------------------------------*/
79-
8071
//--------------------------------------------------------------------+
8172
// tinyusb callbacks
8273
//--------------------------------------------------------------------+
83-
int32_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
84-
{
85-
// read10 & write10 has their own callback and MUST not be handled here
86-
87-
void const* ptr = NULL;
88-
uint16_t len = 0;
89-
90-
// most scsi handled is input
91-
bool in_xfer = true;
92-
93-
switch (scsi_cmd[0])
94-
{
95-
case SCSI_CMD_REQUEST_SENSE:
96-
ptr = &mscd_sense_data;
97-
len = sizeof(scsi_sense_fixed_data_t);
98-
break;
99-
100-
case SCSI_CMD_MODE_SENSE_6:
101-
ptr = &msc_dev_mode_para;
102-
len = sizeof(msc_dev_mode_para);
103-
break;
104-
105-
case SCSI_CMD_TEST_UNIT_READY:
106-
ptr = NULL;
107-
len = 0;
108-
break;
109-
110-
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
111-
ptr = NULL;
112-
len = 0;
113-
break;
114-
115-
default:
116-
// negative is error -> Data stage is STALL, status = failed
117-
return -1;
118-
}
119-
120-
// return len must not larger than bufsize
121-
TU_ASSERT( bufsize >= len );
122-
123-
if ( ptr && len )
124-
{
125-
if(in_xfer)
126-
{
127-
memcpy(buffer, ptr, len);
128-
}else
74+
int32_t tud_msc_scsi_cb (uint8_t rhport, uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
75+
// read10 & write10 has their own callback and MUST not be handled here
76+
77+
void const* ptr = NULL;
78+
uint16_t len = 0;
79+
80+
// most scsi handled is input
81+
bool in_xfer = true;
82+
83+
switch ( scsi_cmd[0] )
12984
{
130-
// SCSI output
85+
case SCSI_CMD_REQUEST_SENSE:
86+
ptr = &mscd_sense_data;
87+
len = sizeof(scsi_sense_fixed_data_t);
88+
break;
89+
90+
case SCSI_CMD_MODE_SENSE_6:
91+
ptr = &msc_dev_mode_para;
92+
len = sizeof(msc_dev_mode_para);
93+
break;
94+
95+
case SCSI_CMD_TEST_UNIT_READY:
96+
ptr = NULL;
97+
len = 0;
98+
break;
99+
100+
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
101+
ptr = NULL;
102+
len = 0;
103+
break;
104+
105+
default:
106+
// negative is error -> Data stage is STALL, status = failed
107+
return -1;
131108
}
132-
}
133109

134-
//------------- clear sense data if it is not request sense command -------------//
135-
if ( SCSI_CMD_REQUEST_SENSE != scsi_cmd[0] )
136-
{
137-
mscd_sense_data.sense_key = SCSI_SENSEKEY_NONE;
138-
mscd_sense_data.additional_sense_code = 0;
139-
mscd_sense_data.additional_sense_qualifier = 0;
140-
}
110+
// return len must not larger than bufsize
111+
TU_ASSERT(bufsize >= len);
112+
113+
if ( ptr && len )
114+
{
115+
if ( in_xfer )
116+
{
117+
memcpy(buffer, ptr, len);
118+
} else
119+
{
120+
// SCSI output
121+
}
122+
}
123+
124+
//------------- clear sense data if it is not request sense command -------------//
125+
if ( SCSI_CMD_REQUEST_SENSE != scsi_cmd[0] )
126+
{
127+
mscd_sense_data.sense_key = SCSI_SENSEKEY_NONE;
128+
mscd_sense_data.additional_sense_code = 0;
129+
mscd_sense_data.additional_sense_qualifier = 0;
130+
}
141131

142-
return len;
132+
return len;
143133
}
144134

145135
/*------------------------------------------------------------------*/
146136
/* Tinyusb Flash READ10 & WRITE10
147137
*------------------------------------------------------------------*/
148-
int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
149-
{
150-
(void) rhport; (void) lun; (void) offset;
138+
int32_t tud_msc_read10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
139+
(void) rhport;
140+
(void) lun;
141+
(void) offset;
151142

152-
uint32_t const block_count = bufsize/MSC_FLASH_BLOCK_SIZE;
143+
uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
153144

154145
internal_flash_read_blocks(buffer, lba, block_count);
155146

156-
return block_count*MSC_FLASH_BLOCK_SIZE;
147+
return block_count * MSC_FLASH_BLOCK_SIZE;
157148
}
158149

159-
int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
160-
{
161-
(void) rhport; (void) lun; (void) offset;
150+
int32_t tud_msc_write10_cb (uint8_t rhport, uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
151+
(void) rhport;
152+
(void) lun;
153+
(void) offset;
162154

163-
uint32_t const block_count = bufsize/MSC_FLASH_BLOCK_SIZE;
155+
uint32_t const block_count = bufsize / MSC_FLASH_BLOCK_SIZE;
164156

165157
// bufsize <= CFG_TUD_MSC_BUFSIZE (4096)
166158
internal_flash_write_blocks(buffer, lba, block_count);
167159

168160
// update fatfs's cache if address matches
169161
fs_user_mount_t* vfs = MP_STATE_VM(vfs_mount_table)->obj;
170162

171-
if ( (lba <= vfs->fatfs.winsect) && (vfs->fatfs.winsect <= (lba + bufsize/MSC_FLASH_BLOCK_SIZE)) ) {
172-
memcpy(vfs->fatfs.win, buffer + MSC_FLASH_BLOCK_SIZE*(vfs->fatfs.winsect-lba), MSC_FLASH_BLOCK_SIZE);
163+
if ( (lba <= vfs->fatfs.winsect) && (vfs->fatfs.winsect <= (lba + bufsize / MSC_FLASH_BLOCK_SIZE)) ) {
164+
memcpy(vfs->fatfs.win, buffer + MSC_FLASH_BLOCK_SIZE * (vfs->fatfs.winsect - lba), MSC_FLASH_BLOCK_SIZE);
173165
}
174166

175-
return block_count*MSC_FLASH_BLOCK_SIZE;
167+
return block_count * MSC_FLASH_BLOCK_SIZE;
176168
}
177169

178-
void tud_msc_write10_complete_cb(uint8_t rhport, uint8_t lun)
179-
{
180-
(void) rhport; (void) lun;
170+
void tud_msc_write10_complete_cb (uint8_t rhport, uint8_t lun) {
171+
(void) rhport;
172+
(void) lun;
181173

182174
// flush pending cache when write10 is complete
183175
internal_flash_flush();
184176
}
185-
186-
#endif

0 commit comments

Comments
 (0)