From 9e0478a902d311bd3f3b7c22468cf464723e0375 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 14 Feb 2016 20:34:30 +0200 Subject: [PATCH] stmhal/diskio: Add provision for default returns for ioctl INIT/SEC_SIZE. If None was returned for such requests (which likely means that user simply didn't handle them), it means successful init and default sector size of 512 bytes respectively. This makes only BP_IOCTL_SEC_COUNT a mandatory request, and thus re-establishes parity with old interface, where only .count() is mandatory(). --- stmhal/diskio.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/stmhal/diskio.c b/stmhal/diskio.c index fd40a6f8e7..03be24188e 100644 --- a/stmhal/diskio.c +++ b/stmhal/diskio.c @@ -63,7 +63,7 @@ DSTATUS disk_initialize ( vfs->u.ioctl[2] = MP_OBJ_NEW_SMALL_INT(BP_IOCTL_INIT); vfs->u.ioctl[3] = MP_OBJ_NEW_SMALL_INT(0); // unused mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->u.ioctl); - if (MP_OBJ_SMALL_INT_VALUE(ret) != 0) { + if (ret != mp_const_none && MP_OBJ_SMALL_INT_VALUE(ret) != 0) { // error initialising return STA_NOINIT; } @@ -203,7 +203,12 @@ DRESULT disk_ioctl ( vfs->u.ioctl[2] = MP_OBJ_NEW_SMALL_INT(BP_IOCTL_SEC_SIZE); vfs->u.ioctl[3] = MP_OBJ_NEW_SMALL_INT(0); // unused mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->u.ioctl); - *((WORD*)buff) = mp_obj_get_int(ret); + if (ret == mp_const_none) { + // Default sector size + *((WORD*)buff) = 512; + } else { + *((WORD*)buff) = mp_obj_get_int(ret); + } return RES_OK; }