Is there a STM-core where hardware-serial enables to assign IO-pins to serial1, serial2, serial3 and works immidiately?

First of all if you want to avoid making me upset don't post anything if you try to support me in writing a lot of steps how to fiddle around with it to make it work.

With this question I am exclusively, solely, only interested in

  1. install STM-core
  2. Serial1, Serial2, Serial3, works WITHOUT any modifications

Recently I tried to compile a small code for STM-microcontrollers that tries to assign IO-pins to from me chosen IO-pins to the serial1 interface.

//#define Serial SerialUSB
//                      RX    TX
HardwareSerial Serial2(PA10, PA9);

void setup() {
  pinMode(PA5,OUTPUT);
  Serial1.begin(115200);
}


void loop() {
  digitalWrite(PA5, HIGH);
  Serial1.println("turn on the LED");
  delay(1000);
  digitalWrite(PA5, LOW);
  Serial1.println("turn off the LED");
  delay(1000);
}

The title is meant in this way:

Does there exist a STM-core that works this way:

  1. install the core with the board-manager
  2. create sketch
  3. compile sketch compiling is successfull
  4. upload is successful

I tried this with by installing these two board-packages

But the code below did not compile

don't post advice like this:

I don't want advice like this
1a. install the core with the board-manager
1b. modify ......
1c. modify .....
1d.
....
1z.
2. create sketch
3. compile sketch compiling is successfull
4. upload is successful

my question is
does there exist a board-package that works with
serial1
and
serial2
and
serial3
straight out of the box
this way

  1. install the core with the board-manager
  2. create sketch
  3. compile sketch that uses serial1, serial2, serial3 compiling is successfull
  4. upload is successful

I am serios:
This is a closed question. So answer with "Yes" or "No"

Just in case you can answer with "Yes". Add the link to Github where this core can be downloaded.

If you can't resist to write the 1a., 1b, 1c, .... 1z. manual
Open a textfile write it there and store it on your harddisk - done
But do not post it in this thread!

If storing it in a personal textfile is not satisfying for you write an introductional tutorial but
But do not post it in this thread!

best regards Stefan

NO

STM doesn't support assigning the user chosen pins to the Serials. Serials can be used on predefined pins only!

Take the note that you defined the Serial2, but try to use Serial1 :slight_smile:

ups ! I forgot to unify them all to 1 or 2 before posting

Is this a Bluepill Stm32F103xxxx ? Yes, you can use 3 serial ports with a simple sketch. However, getting to the stage where you can upload your first sketch is somewhat more complex than say getting a Uno up and running with a bit of detail which you may not like to hear. Hint: use the official STmicroElectronics Arduino core.

No, I don't think you can do this without additional steps that you so clearly state that you don't want to hear about.

Jeez man, relax a little. So what if someone posts something that you don't want?

1 Like

I wanted a very clear answer "Yes" or "No"
There was one post saying look up this link that does use IOn-pins as parameters for hardwareserial
another post saying you can't change the IO-pins. serial IO-pins are fixed

So what? Who cares? You're not the only one here Stefan. Maybe someone later will find your thread and wants the long answer. It's ok if they're both here. It's not going to hurt you in any way if someone gives a more detailed answer than you wanted. It might even help you. Maybe the extra steps aren't really that hard.

Try to relax a little. Being so uptight like this isn't good for your health.

Here's a picture of a kitten to help lighten your mood. See, you can still get answers on your thread even with a useless post. Nobody is harmed.

3 Likes

sweet kitten :slightly_smiling_face: :smile:

2 Likes

Maybe you want it - but life isn't always as easy as yes or no.
You can remap some functions ( also USART) to other pins, but not freely. There are fixed 'alternate pin settings) you can use. But not arbitrary pins. So what answer do you want to hear - Yes or No??
[EDIT] Because of your first post, I was about to not answer, because I can't just say YES or NO. Would you have preferred that ( so I know next time)?

First, you have to be clear about which core you are talking about. There is the official STmicroElectronics Arduino core (recommended) and other maybe abandoned cores such as "Roger Clark (dan.drown)" core.

Second, if it is the Stm32F103xxxx (bluepill) then it appears to be true that the mapping between the UARTs and physical pins is fixed.
Also, I can't see a way of remapping these in the STM32cube IDE

image

Third, there is a dedicated web site https://www.stm32duino.com/ for Arduino STM32 stuff.

I use ST-Link hardware (clone $3 on Ebay) plus STM32Cube programmer software to integrate these with Arduino. There are numerous other possibilities.

This is the tutorial I recommend: Program "blue pill" with STM32 Cores in Arduino IDE · One Transistor

The possibility of remapping also depends on the chip size ( nbr. of pins ). The 48pin chip indeed has no remapping feature on USART2 and USART3 pins (while it has on USART1). So even more a 'depends' then 'yes' or 'no'.

1 Like

Indeed and I've just seen how to do it:

And this is the code that it generates to set up the GPIO pin registers for the alternative function. I wouldn't want to have to lift that out and use it in an Arduino sketch. Maybe there is a mapping function which can be more easily used.

void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(huart->Instance==USART1)
  {
  /* USER CODE BEGIN USART1_MspInit 0 */

  /* USER CODE END USART1_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_USART1_CLK_ENABLE();

    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**USART1 GPIO Configuration
    PB6     ------> USART1_TX
    PB7     ------> USART1_RX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    GPIO_InitStruct.Pin = GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    __HAL_AFIO_REMAP_USART1_ENABLE();

  /* USER CODE BEGIN USART1_MspInit 1 */

  /* USER CODE END USART1_MspInit 1 */
  }
. . .
. . .

Yes, it is probably easier to plan the wiring so that the standard pins are used. :wink:

I found it. With the STM Core its really easy. Simply create the Serial1 with

HardwareSerial Serial1(PB7,PB6); 

But in the tools menu you must not generate 'Serial' for USART support.
Select: enabled( no generic 'Serial' ).
Otherwise Serial is mapped to Serial1, what means Serial1 is already instantiated with default values.

4 Likes

Using the Blackpill F401CC selection

const uint8_t INC_TX_PIN = PA11; // TX6
const uint8_t INC_RX_PIN = PA12; // RX6
const uint8_t GPS_TX_PIN = PB6;
const uint8_t GPS_RX_PIN = PB7;

HardwareSerial _gps(GPS_RX_PIN, GPS_TX_PIN);
HardwareSerial _inclinometer(INC_RX_PIN, INC_TX_PIN);

I use this to read two serial devices and still have USB available. Never tried redirecting the other serial port but I assume you can do something similar.
HTH. Let me know if you have any questions

Yes. UART1 can be remapped even in the smaller packages. That has already been dealt with in post #14 and later.
The exact STM32 MCU was never made clear. We were assuming a 48 pin package (as in the popular Bluepill) where only UART1 can be remapped. With the 100 and 144 pin packages there is much more flexibility.

Thank you all for your contributions. Very much appreciated.
My initial question was not specific to a certain STM32 MCU but general about STM32-cores

best regards Stefan