1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

trezorhal: enable write to sdcard

This commit is contained in:
Pavol Rusnak 2017-03-13 11:36:31 +01:00
parent a66e5e4ad8
commit f6f3765a3e
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 16 additions and 5 deletions

View File

@ -121,14 +121,24 @@ uint32_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_bloc
return SD_ERROR; return SD_ERROR;
} }
HAL_SD_ErrorTypedef err = SD_OK;
// check that dest pointer is aligned on a 4-byte boundary // check that dest pointer is aligned on a 4-byte boundary
if (((uint32_t)dest & 3) != 0) { if (((uint32_t)dest & 3) != 0) {
return SD_ERROR; return SD_ERROR;
} }
err = HAL_SD_ReadBlocks_BlockNumber(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks); return HAL_SD_ReadBlocks_BlockNumber(&sd_handle, (uint32_t*)dest, block_num, SDCARD_BLOCK_SIZE, num_blocks);
}
return err;
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);
} }

View File

@ -12,5 +12,6 @@ bool sdcard_power_on(void);
void sdcard_power_off(void); void sdcard_power_off(void);
uint64_t sdcard_get_capacity_in_bytes(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_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 #endif