5 years, 9 months ago.

How to remap pins on STM32

Hello everyone, does anyone have an example of how to remap the USART or another peripherials pins using mbed library on the STM32? Is it possible or I have to use StdPeriph Library for this operation?

Comment on this question

2 Answers

5 years, 9 months ago.

Also with the online compiler you can do what you want (well minus changing compiler options such as optimization settings, but besides that pretty much everything).

I don't really understand the question though. Well I understand it, but now why it is asked. If you want to use for example the UART, just use Serial serial([your_tx_pin], [your_rx_pin]);. If for whatever reason you can't use the standard libraries, you can always do it manually by setting the correct registers. This is for example how the mbed lib does it: https://github.com/mbedmicro/mbed/blob/master/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/serial_api.c

I know that I can use Serial serial([your_tx_pin], [your_rx_pin]); but my problem is that I need to use USART2. Normally it is on pins PA9, PA10 (STM32F103RBT6), but I have on my board on pins PB6, PB7 as an alternative function. In your link I see only USART1 and USART2 on PA2, PA3 and PA9, PA10. I don't have to care now about code optimization.

posted by Paweł Jabłoński 23 Feb 2014

I assume that those pins support USART2? (Just making sure ;) ).

You can import mbed-src (http://mbed.org/users/mbed_official/code/mbed-src/), and then add it to that list, and it *should* work. I don't have them myself, so I can't test it. But after making that post I looked a bit more into it, and noticed that it indeed really looks like many alternate locations are missing. I made it an issue: https://github.com/mbedmicro/mbed/issues/187, so hopefully they add those soonish.

posted by Erik Olieman 23 Feb 2014

Yes, I thought about USART1. I saw my mistake after I send the message. Your idea with source code was perfect. Thanks a lot for a link. I changed serial_api.c file. I added RCC_APB2Periph_AFIO and GPIO_PinRemapConfig(GPIO_Remap_USART1, ENABLE); in serial_init function and it is working well :) I hope also, that they add remaping for another alternate functions. Thanks a lot for your help.

posted by Paweł Jabłoński 23 Feb 2014
5 years, 9 months ago.

Unless there is a remap pin function in the mbed api for the stm32 uCs, (I don't think there is, but I could be wrong.) then the answer is no. If you move away from the online compiler then you can do what you want.

Dave.