From f6f3765a3e53af306385e6a0c1c281ad2a52dea4 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 13 Mar 2017 11:36:31 +0100 Subject: [PATCH] trezorhal: enable write to sdcard --- micropython/trezorhal/sdcard.c | 20 +++++++++++++++----- micropython/trezorhal/sdcard.h | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/micropython/trezorhal/sdcard.c b/micropython/trezorhal/sdcard.c index f38d10653..23929c962 100644 --- a/micropython/trezorhal/sdcard.c +++ b/micropython/trezorhal/sdcard.c @@ -121,14 +121,24 @@ uint32_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_bloc return SD_ERROR; } - HAL_SD_ErrorTypedef err = SD_OK; - // check that dest pointer is aligned on a 4-byte boundary if (((uint32_t)dest & 3) != 0) { return SD_ERROR; } - err = HAL_SD_ReadBlocks_BlockNumber(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks); - - return err; + return HAL_SD_ReadBlocks_BlockNumber(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks); +} + +uint32_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks) { + // check that SD card is initialised + if (sd_handle.Instance == NULL) { + return SD_ERROR; + } + + // check that src pointer is aligned on a 4-byte boundary + if (((uint32_t)src & 3) != 0) { + return SD_ERROR; + } + + return HAL_SD_WriteBlocks_BlockNumber(&sd_handle, (uint32_t*)src, block_num, SDCARD_BLOCK_SIZE, num_blocks); } diff --git a/micropython/trezorhal/sdcard.h b/micropython/trezorhal/sdcard.h index 071dcf293..ae981c4dc 100644 --- a/micropython/trezorhal/sdcard.h +++ b/micropython/trezorhal/sdcard.h @@ -12,5 +12,6 @@ bool sdcard_power_on(void); void sdcard_power_off(void); uint64_t sdcard_get_capacity_in_bytes(void); uint32_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blocks); +uint32_t sdcard_write_blocks(const uint8_t *src, uint32_t block_num, uint32_t num_blocks); #endif