Skip to content

Commit b697a80

Browse files
committed
debug logs added
Former-commit-id: 29022d6
1 parent 0b057ed commit b697a80

File tree

3 files changed

+50
-22
lines changed

3 files changed

+50
-22
lines changed

cores/arduino/usb/USB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ extern "C" __attribute((weak)) void tud_hid_set_report_cb(uint8_t instance, uint
380380
(void) buffer;
381381
(void) bufsize;
382382
}
383-
extern "C" int mylogadd(const char *fmt, ...) ;
383+
384384

385385
extern "C" __attribute((weak)) int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
386386

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

libraries/BlockDevices/QSPIFlashBlockDevice.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#ifdef HAS_QSPI
2323

24+
25+
extern "C" int mylogadd(const char *fmt, ...) ;
2426
/* -------------------------------------------------------------------------- */
2527
/* CONSTRUCTOR */
2628
/* -------------------------------------------------------------------------- */
@@ -91,16 +93,20 @@ int QSPIFlashBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t
9193
return write(buffer, addr, _size);
9294
}
9395

96+
#ifdef DEBUG_MSD
97+
extern "C" int mylogadd(const char *fmt, ...) ;
98+
#endif
99+
94100
/* -------------------------------------------------------------------------- */
95101
/* OPEN */
96102
/* -------------------------------------------------------------------------- */
97103
int QSPIFlashBlockDevice::open() {
98104
fsp_err_t rv = (fsp_err_t)BLOCK_DEVICE_OK;
99-
static bool opened = false;
100-
105+
101106
if(!opened) {
102-
107+
103108
opened = true;
109+
104110
R_IOPORT_PinCfg(NULL, g_pin_cfg[ck].pin, (uint32_t) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_QSPI));
105111
R_IOPORT_PinCfg(NULL, g_pin_cfg[cs].pin, (uint32_t) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_QSPI));
106112
R_IOPORT_PinCfg(NULL, g_pin_cfg[io0].pin, (uint32_t) (IOPORT_CFG_PERIPHERAL_PIN | IOPORT_PERIPHERAL_QSPI));
@@ -191,17 +197,19 @@ int QSPIFlashBlockDevice::read(void *buffer, bd_addr_t add, bd_size_t _size) {
191197

192198
if(!opened) {
193199
rv = (fsp_err_t)open();
194-
}
195-
196-
if(rv != BLOCK_DEVICE_OK) {
197-
return rv;
200+
if(rv != BLOCK_DEVICE_OK) {
201+
return rv;
202+
}
198203
}
199204

200205
if(buffer == nullptr) {
201206
rv = FSP_ERR_INVALID_ARGUMENT;
202207
}
203208
else {
204209
if(is_address_correct(add+_size-1)) {
210+
#ifdef DEBUG_MSD
211+
mylogadd("QSPI READ %i, %i", add, _size);
212+
#endif
205213
rv = (fsp_err_t)BLOCK_DEVICE_OK;
206214
int64_t internal_size = _size;
207215
uint32_t byte_left_in_bank = read_block_size - read_block_size % add;
@@ -231,6 +239,8 @@ int QSPIFlashBlockDevice::read(void *buffer, bd_addr_t add, bd_size_t _size) {
231239
return (int)rv;
232240
}
233241

242+
#define INTERNAL_BLOCK_SIZE 256
243+
234244
/* -------------------------------------------------------------------------- */
235245
/* WRITE 'size' byte form buffer to the "logical" address specified by 'addr'
236246
NOTE: buffer MUST be equal or greater than 'size' */
@@ -240,20 +250,21 @@ int QSPIFlashBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _si
240250

241251
if(!opened) {
242252
rv = (fsp_err_t)open();
253+
if(rv != BLOCK_DEVICE_OK) {
254+
return rv;
255+
}
243256
}
244257

245-
if(rv != BLOCK_DEVICE_OK) {
246-
return rv;
247-
}
248-
249-
250258
if(buffer == nullptr) {
251259
rv = FSP_ERR_INVALID_ARGUMENT;
252260
}
253261
else {
254262
if(is_address_correct(add+_size-1)) {
263+
#ifdef DEBUG_MSD
264+
mylogadd("QSPI WRITE %i, %i", add, _size);
265+
#endif
255266
int64_t internal_size = _size;
256-
uint32_t bytes_left_in_page = write_block_size - (add % write_block_size);
267+
uint32_t bytes_left_in_page = INTERNAL_BLOCK_SIZE - (add % INTERNAL_BLOCK_SIZE);
257268
uint8_t *source = (uint8_t *)buffer;
258269
rv = FSP_SUCCESS;
259270
while(internal_size > 0 && rv == FSP_SUCCESS) {
@@ -277,7 +288,7 @@ int QSPIFlashBlockDevice::write(const void *buffer, bd_addr_t add, bd_size_t _si
277288
internal_size -= bytes_to_write;
278289
source += bytes_to_write;
279290
add += bytes_to_write;
280-
bytes_left_in_page = write_block_size;
291+
bytes_left_in_page = INTERNAL_BLOCK_SIZE;
281292
if(rv == FSP_SUCCESS)
282293
rv = get_flash_status();
283294
}
@@ -302,13 +313,11 @@ int QSPIFlashBlockDevice::erase(bd_addr_t add, bd_size_t _size) {
302313

303314
if(!opened) {
304315
rv = (fsp_err_t)open();
316+
if(rv != BLOCK_DEVICE_OK) {
317+
return rv;
318+
}
305319
}
306320

307-
if(rv != BLOCK_DEVICE_OK) {
308-
return rv;
309-
}
310-
311-
312321
if(is_address_correct(add+_size-1)) {
313322
int64_t internal_size = _size;
314323
/* get the starting address of the block */

0 commit comments

Comments
 (0)