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. // way from other STM32s.
// Code below is emulating a few mappings to work like an STM32F4 // Code below is emulating a few mappings to work like an STM32F4
uint32_t func = (mode >> 4) & 0xf; uint32_t func = (mode >> 4) & 0xf;
if (gpio == GPIO('B', 8) || gpio == GPIO('B', 9)) { if (func == 1) {
if (func == 9) { // TIM2
// CAN if (gpio == GPIO('A', 15) || gpio == GPIO('B', 3))
stm32f1_alternative_remap(AFIO_MAPR_CAN_REMAP_Msk, stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_Msk,
AFIO_MAPR_CAN_REMAP_REMAP2);
} else if (func == 4) {
// I2C1 Alt
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); AFIO_MAPR_TIM2_REMAP_PARTIALREMAP1);
} else if ((gpio == GPIO('B', 10) else if (gpio == GPIO('B', 10) || gpio == GPIO('B', 11))
|| gpio == GPIO('B', 11)) && (func == 1)) { stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_Msk,
// TIM2 CH3/4
stm32f1_alternative_remap(AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2_Msk,
AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2); AFIO_MAPR_TIM2_REMAP_PARTIALREMAP2);
} else if ((gpio == GPIO('B', 4) } else if (func == 2) {
|| gpio == GPIO('B', 5)) && (func == 2)) { // TIM3 and TIM4
// TIM3 partial remap if (gpio == GPIO('B', 4) || gpio == GPIO('B', 5))
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_PARTIALREMAP_Msk, stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_Msk,
AFIO_MAPR_TIM3_REMAP_PARTIALREMAP); AFIO_MAPR_TIM3_REMAP_PARTIALREMAP);
} else if ((gpio == GPIO('C', 6) else if (gpio == GPIO('C', 6) || gpio == GPIO('C', 7)
|| gpio == GPIO('C', 7) || gpio == GPIO('C', 8) || gpio == GPIO('C', 9))
|| gpio == GPIO('C', 8) stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_Msk,
|| gpio == GPIO('C', 9)) && (func == 2)) {
// TIM3 full remap
stm32f1_alternative_remap(AFIO_MAPR_TIM3_REMAP_FULLREMAP_Msk,
AFIO_MAPR_TIM3_REMAP_FULLREMAP); AFIO_MAPR_TIM3_REMAP_FULLREMAP);
} else if ((gpio == GPIO('D', 8) || gpio == GPIO('D', 9)) && func == 7) { else if (gpio == GPIO('D', 12) || gpio == GPIO('D', 13)
// USART3 remap || gpio == GPIO('D', 14) || gpio == GPIO('D', 15))
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, stm32f1_alternative_remap(AFIO_MAPR_TIM4_REMAP_Msk,
AFIO_MAPR_TIM4_REMAP); 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 (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 // Handle USB reboot requests
void void
usb_request_bootloader(void) usb_request_bootloader(void)