[SOLVED] HardwareSerial stm32f103 pin remapping

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
Post Reply
41300895
Posts: 28
Joined: Tue Oct 25, 2016 12:19 pm

[SOLVED] HardwareSerial stm32f103 pin remapping

Post by 41300895 » Mon Feb 06, 2017 9:08 am

Hello I want to use HardwareSerial with USART1 pin PB6, PB7 on stm32f103 blue pill board but I don't know how to define it in my code, please show me how

stevestrong
Posts: 1746
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: HardwareSerial stm32f103 pin remapping

Post by stevestrong » Mon Feb 06, 2017 10:50 am

I would try:

Code: Select all

#include <libmaple/gpio.h>
...
afio_remap(AFIO_REMAP_USART1);

stevestrong
Posts: 1746
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: HardwareSerial stm32f103 pin remapping

Post by stevestrong » Mon Feb 06, 2017 11:01 pm

And, did it work?

C_D
Posts: 62
Joined: Mon May 11, 2015 3:27 am
Location: New Zealand

Re: HardwareSerial stm32f103 pin remapping

Post by C_D » Mon Sep 11, 2017 1:52 am

I just had to do the same thing but on USART3. The following worked for me:

Code: Select all

  // remap USART3
  afio_remap(AFIO_REMAP_USART3_PARTIAL);
  gpio_set_mode(GPIOC, 10, GPIO_AF_OUTPUT_PP);
  gpio_set_mode(GPIOC, 11, GPIO_INPUT_FLOATING);
  gpio_set_mode(GPIOC, 12, GPIO_AF_OUTPUT_PP);
If you do not explicitly set the gpio mode it does not work, I am guessing this is normally done somewhere in Serial3.begin() but that function wont know about the remapping.

Post Reply