stm32: Reorganize stm32f1 pin remap handling

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-05-25 23:42:28 -04:00
parent 12acb99a38
commit 273106358d
1 changed files with 34 additions and 44 deletions

View File

@ -128,55 +128,45 @@ gpio_peripheral(uint32_t gpio, uint32_t mode, int pullup)
// way from other STM32s.
// Code below is emulating a few mappings to work like an STM32F4
uint32_t func = (mode >> 4) & 0xf;
if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9)) {
if (func == 9) {
// CAN
stm32f1_alternative_remap(AFIO_MAPR_CAN_REMAP_Msk,
AFIO_MAPR_CAN_REMAP_REMAP2);
} else if (func == 4) {
// I2C1 Alt
if (func == 1) {
// TIM2
if (gpio == GPIO('A', 15) || gpio == GPIO('B', 3))
stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_Msk,
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1);
else if (gpio == GPIO('B', 10) || gpio == GPIO('B', 11))
stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_Msk,
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2);
} else if (func == 2) {
// TIM3 and TIM4
if (gpio == GPIO('B', 4) || gpio == GPIO('B', 5))
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_Msk,
AFIO_MAPR_TIM3_REMAP_PARTIALREMAP);
else if (gpio == GPIO('C', 6) || gpio == GPIO('C', 7)
|| gpio == GPIO('C', 8) || gpio == GPIO('C', 9))
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_Msk,
AFIO_MAPR_TIM3_REMAP_FULLREMAP);
else if (gpio == GPIO('D', 12) || gpio == GPIO('D', 13)
|| gpio == GPIO('D', 14) || gpio == GPIO('D', 15))
stm32f1_alternative_remap(AFIO_MAPR_TIM4_REMAP_Msk,
AFIO_MAPR_TIM4_REMAP);
} else if (func == 4) {
// I2C
if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9))
stm32f1_alternative_remap(AFIO_MAPR_I2C1_REMAP_Msk,
AFIO_MAPR_I2C1_REMAP);
}
} else if ((gpio == GPIO('A', 15)
|| gpio == GPIO('B', 3)) && (func == 1)) {
// TIM2 CH1/2
stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1_Msk,
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1);
} else if ((gpio == GPIO('B', 10)
|| gpio == GPIO('B', 11)) && (func == 1)) {
// TIM2 CH3/4
stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2_Msk,
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2);
} else if ((gpio == GPIO('B', 4)
|| gpio == GPIO('B', 5)) && (func == 2)) {
// TIM3 partial remap
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_PARTIALREMAP_Msk,
AFIO_MAPR_TIM3_REMAP_PARTIALREMAP);
} else if ((gpio == GPIO('C', 6)
|| gpio == GPIO('C', 7)
|| gpio == GPIO('C', 8)
|| gpio == GPIO('C', 9)) && (func == 2)) {
// TIM3 full remap
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_FULLREMAP_Msk,
AFIO_MAPR_TIM3_REMAP_FULLREMAP);
} else if ((gpio == GPIO('D', 8) || gpio == GPIO('D', 9)) && func == 7) {
// USART3 remap
stm32f1_alternative_remap(AFIO_MAPR_USART3_REMAP_FULLREMAP_Msk,
AFIO_MAPR_USART3_REMAP_FULLREMAP);
} else if ((gpio == GPIO('D', 12)
|| gpio == GPIO('D', 13)
|| gpio == GPIO('D', 14)
|| gpio == GPIO('D', 15)) && (func == 2)) {
// TIM4
stm32f1_alternative_remap(AFIO_MAPR_TIM4_REMAP_Msk,
AFIO_MAPR_TIM4_REMAP);
} else if (func == 7) {
// USART
if (gpio == GPIO('D', 8) || gpio == GPIO('D', 9))
stm32f1_alternative_remap(AFIO_MAPR_USART3_REMAP_Msk,
AFIO_MAPR_USART3_REMAP_FULLREMAP);
} else if (func == 9) {
// CAN
if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9))
stm32f1_alternative_remap(AFIO_MAPR_CAN_REMAP_Msk,
AFIO_MAPR_CAN_REMAP_REMAP2);
}
// Add more as needed
}
// Handle USB reboot requests
void
usb_request_bootloader(void)