Use pins PB6 PB7 for USART [solved]

Maple Mini, Maple Rev3, Maple Rev 5 and Maple Ret 6, iTead Maple etc
Post Reply
oribotic
Posts: 5
Joined: Mon Jun 01, 2020 6:19 am
Answers: 1

Use pins PB6 PB7 for USART [solved]

Post by oribotic »

Hello,

[edit: this might be the wrong thread for this question... sorry]

I've built a custom board with STM32F103C8 mcu and I'm trying to run hardware serial on PB6 And PB7, these are listed as alternative USART pins

I'm using the maple core, and the standard pc13 stm32duino bootloader

I create a board variant under arduino15/packages/stm32duino/hardware/STM32F1/.... and modify my board.h file to the pins I want to use.

#define BOARD_USART3_TX_PIN PB6
#define BOARD_USART3_RX_PIN PB7

I use Serial3 in my arduino code, but get no serial data out of the TX pin.
I'm also using the software Serial object to echo the same output to the port, for debugging.

I think this is the problem. When I check the pin number of PB6 using:

Serial.println(PB6);
> 22

When on my data sheet, PB6 is pin 42!!

Any suggestions on a fix?

thanks, Matthew
Last edited by oribotic on Wed Oct 14, 2020 11:31 pm, edited 1 time in total.
oribotic
Posts: 5
Joined: Mon Jun 01, 2020 6:19 am
Answers: 1

Re: Problem with pin mapping

Post by oribotic »

or is the pin number returned just the position in PIN_MAP?
oribotic
Posts: 5
Joined: Mon Jun 01, 2020 6:19 am
Answers: 1

the solution to remap USART1

Post by oribotic »

found my own solution.

the problem with mapping new serial pins is a bit deeper than it presents itself initially in the source code.
hardware serial devices can only be remapped to particular predefined pins. In my case, USART1 > Serial1 is the device I want as it can be remapped from PA9/PA10 to PB6/PB7 TX/RX. My mistake above was to try using an arbitrary hardware serial device (serial3), which can only be remapped on a different MCU! If you are looking at a similar problem, check the datasheet under pin definitions e.g. https://www.st.com/resource/en/datashee ... f103c8.pdf and compare the numbers on USART1, USART2, USART3 for the F103, check the remap and alternate function columns.

To do the remap, I created a variant for my custom board and then:

I added a call to the afio_remap function in boards.cpp to pass AFIO_REMAP_USART1

Code: Select all

void boardInit(void) {
	afio_remap(AFIO_REMAP_USART1); // Remap USART1 to (TX/PB6, RX/PB7)
#ifndef CONFIG_MAPLE_MINI_NO_DISABLE_DEBUG
    disableDebugPorts();
#endif
}
then in board.h updated the TX and RX pins for USART1

Code: Select all

#define BOARD_USART1_TX_PIN       PB6
#define BOARD_USART1_RX_PIN       PB7
got it working for me.

I really like the variant system, its a handy way to set up a new board.
Post Reply

Return to “Maple & Maple mini etc”