mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-04 20:01:18 +00:00
trezorhal: turn sdcard/cpt circuitry on/off using PC0/PB10 pin
This commit is contained in:
parent
dca61a4c7f
commit
6ce106b544
Binary file not shown.
Before Width: | Height: | Size: 486 KiB After Width: | Height: | Size: 518 KiB |
@ -51,6 +51,16 @@
|
|||||||
|
|
||||||
static SD_HandleTypeDef sd_handle;
|
static SD_HandleTypeDef sd_handle;
|
||||||
|
|
||||||
|
static void sdcard_default_pin_state(void) {
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); // SD_ON/PC0
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); // SD_DAT0/PC8
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET); // SD_DAT1/PC9
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_10, GPIO_PIN_RESET); // SD_DAT2/PC10
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11, GPIO_PIN_RESET); // SD_DAT3/PC11
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); // SD_CLK/PC12
|
||||||
|
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); // SD_CMD/PD2
|
||||||
|
}
|
||||||
|
|
||||||
void sdcard_init(void) {
|
void sdcard_init(void) {
|
||||||
// invalidate the sd_handle
|
// invalidate the sd_handle
|
||||||
sd_handle.Instance = NULL;
|
sd_handle.Instance = NULL;
|
||||||
@ -68,11 +78,20 @@ void sdcard_init(void) {
|
|||||||
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||||
|
|
||||||
// configure the SD card detect pin
|
// configure the SD card detect pin
|
||||||
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
|
||||||
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
GPIO_InitStructure.Pull = GPIO_PULLUP;
|
||||||
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
GPIO_InitStructure.Pin = GPIO_PIN_13;
|
GPIO_InitStructure.Pin = GPIO_PIN_13;
|
||||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
// configure the SD card circuitry on/off pin
|
||||||
|
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStructure.Pin = GPIO_PIN_0;
|
||||||
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
sdcard_default_pin_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {
|
void HAL_SD_MspInit(SD_HandleTypeDef *hsd) {
|
||||||
@ -90,6 +109,10 @@ secbool sdcard_is_present(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
secbool sdcard_power_on(void) {
|
secbool sdcard_power_on(void) {
|
||||||
|
// turn on SD card circuitry
|
||||||
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); // SD_ON/PC0
|
||||||
|
HAL_Delay(50);
|
||||||
|
|
||||||
if (sectrue != sdcard_is_present()) {
|
if (sectrue != sdcard_is_present()) {
|
||||||
return secfalse;
|
return secfalse;
|
||||||
}
|
}
|
||||||
@ -133,6 +156,10 @@ void sdcard_power_off(void) {
|
|||||||
}
|
}
|
||||||
HAL_SD_DeInit(&sd_handle);
|
HAL_SD_DeInit(&sd_handle);
|
||||||
sd_handle.Instance = NULL;
|
sd_handle.Instance = NULL;
|
||||||
|
|
||||||
|
// turn off SD card circuitry
|
||||||
|
HAL_Delay(50);
|
||||||
|
sdcard_default_pin_state();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t sdcard_get_capacity_in_bytes(void) {
|
uint64_t sdcard_get_capacity_in_bytes(void) {
|
||||||
|
@ -43,6 +43,16 @@ void touch_init(void)
|
|||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
|
||||||
|
// configure the CTP circuitry on/off pin
|
||||||
|
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStructure.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
||||||
|
GPIO_InitStructure.Pin = GPIO_PIN_10;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||||
|
|
||||||
|
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // CTP_ON/PB10
|
||||||
|
HAL_Delay(50);
|
||||||
|
|
||||||
// Enable I2C clock
|
// Enable I2C clock
|
||||||
__HAL_RCC_I2C1_CLK_ENABLE();
|
__HAL_RCC_I2C1_CLK_ENABLE();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user