Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the reuse and remapping of STM32 ports

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how STM32 port reuse and remapping is, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Now let's talk about the port remapping of STM32 single-chip microcomputer, because we take ourselves as an example. Here is an example of the remapping of USART1..

Because I want a TFT_LCD screen main control board, considering the FSMC, I chose the STM32F103VCT6 model CPU, accidentally connected to the USART1 serial port. Because the error was found when calling the program, there is no way, it can only be solved through port remapping. But I have never used port remapping before, I only know its name, not its body, so.. Hehe. We can only look at it from the beginning.

There are a lot of Imax O ports on STM32, and there are also a lot of built-in external ideas such as I2C, ADC, and IPC, etc. In order to save the lead-out pins, these built-in peripherals basically share pins with Imax O ports, that is, the multiplexing function of IAccord O pins. But there is another special thing about STM32: many Imax O pins that reuse built-in peripherals can be led out from different Imax O pins through remapping function, that is, the pins of the reuse function can be changed by program. Reading here, I believe everyone should understand some of the concepts of port remapping. The principle of things do not elaborate, you can read the manual or online search, there are still a lot of information in this area. Let's talk about my debugging experience.

I don't know why PCB connected the serial port to USART1 when drawing, but I didn't care at that time. When I wrote the USART test program and burned it into the hardware simulation, the serial port gave me garbled code, which I thought was strange at that time. I checked the program several times but couldn't find the problem. I thought there was something wrong with the hardware, but suddenly I thought that STM had a reuse function. I wondered if there was a ghost here. So I asked datasheet to take a look, and the truth came out.

STM32F103VCT6 CPU USART1 is connected to PB6/PB7, but the default function is not USART1 after power-on initialization. So want to use serial port function. Must remap with port..

As we all know, each function module of STM32 single chip microcomputer has its own clock system, so if you want to call the function module of STM32 single chip microcomputer, you must configure the corresponding clock before you can operate the corresponding function module. The same is true of port remapping. As shown in the figure:

The remapping steps are:

1. Turn on the remap clock and the USART O-port pin clock after remapping

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE)

2.I/O mouth remapping is on.

GPIO_PinRemapConfig (GPIO_Remap_USART1,ENABLE)

3. To configure the remapping pin, you only need to configure the remapped Iripple O, not the original one.

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz

GPIO_Init (GPIOB, & GPIO_InitStructure)

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING

GPIO_Init (GPIOB,&GPIO_InitStructure)

Only need these three steps, the serial port can be used normally, is it simple? But it took me more than half an hour to get it done. A lot of things are easier said than done. I hope I can make more progress in the future. Don't aim high and low, well, I'm moving in this direction.

Finally, let's sum up:

To put it simply, STM32's io has three functions, one is the default, one is reuse and the other is remapping (this also belongs to reuse)

If configured to reuse, the second function will be used. If configured to reuse and the corresponding remapping configuration is configured, the third function will be used.

Usually there are more than two reuse and remapping of one port. It depends on which device you enable (which one is enabled).

Open reuse + enable device + whether to remap or not can determine which function the io port uses.

The above is what STM32 port reuse and remapping is like. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report