Several common questions about STM32 peripheral configuration

Publisher:悠闲之旅Latest update time:2019-02-14 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the process of developing STM32 applications, we often encounter various problems, many of which are related to the configuration of peripherals and related GPIOs. Let's summarize and discuss these issues here.


The current STM32 chip is a programmable microprocessor based on the ARM core. We can simply call everything outside the core peripherals, such as TIMER, UART, SPI, USB, I2C, memory and other functional modules. Take the 32F427 chip functional block diagram as an example, those in the red circle are all peripherals.

 


Okay, let's get straight to the point. The problems we encounter regarding the configuration of peripherals can be roughly divided into two categories.


1. Clock problem. This problem can be divided into several small points.


1.1 Use without turning on the clock.


This is not difficult to understand, that is, the clock of the relevant peripherals is not turned on. For example, the clock of UART5 is not turned on, the clock of SPI is not turned on, etc., so it is naturally impossible to operate or have no response.


1.2 The clock was turned on incorrectly due to a bus error. In simple terms, it was a case of misidentification .


This has often happened to people before. For example, similar to USART1 and USART2, SP1 and SP2, TIM1 and


TIM2 may not be on the same bus, but it was configured as if it was the same, which resulted in a problem.


1.3 The clock rate configuration is incorrect.


This point seems to overlap with point 2. It mainly refers to the abnormality caused by the clock data configuration error, which leads to the clock supplied to the peripherals being too high. Someone once went crazy because the USB configuration clock of the 32F1 series chip was higher than 48M, making its performance extremely unstable.


1.4 The multiplexed clock is not turned on, that is, the AFIO clock is not turned on.


The first three points are all right, the configuration is correct, but some functions must turn on the multiplexed clock, but I don't know or forget to turn it on. The AFIO clock is mainly for the STM32F1 series chips. I will continue to add to this later.


2. The physical arrangement and configuration of GPIO pins can also be divided into two categories.


2.1 A contention conflict occurs when pins are reused, that is, one or several pins are assigned to two peripherals for use at the same time.


When an engineer used the STM32F103V chip, he used two I2Cs at the same time. It turned out that I2C2 always worked properly, but I2C1 did not work properly. There was no problem with the clock and pin configuration. Later, it was found that he enabled the relevant FSMC function, and one of the FSMC function pins happened to conflict with the SDA pin of I2C1.


2.2 The pins that need to be remapped have not been REMAP’d.


For the functional pins of the STM32F1 series that need to be remapped, they will be marked in the REMAP column in the data sheet.




For example, the USART_TX/RX function in the above figure must execute the relevant REMAP instruction before the relevant function can be reflected on PB6/7. Remember to turn on the GPIOB clock and USART1 clock.


2.3 Let me say a few more words on the topic from 1.4.


The AFIO clock problem was mentioned in 1.4 above. The AFIO clock is only mentioned in the STM32F1 series. For the 32F1 series, the AFIO clock needs to be turned on when the EXTI, REMAP, and event output of the pins are involved. For example, the AFIO clock must be turned on for the REMAP pin mentioned above. The same is true for configuring the EXTI interrupt, otherwise it will not take effect.


For STM32 series other than STM32F1, AFIO is no longer mentioned. There is an additional SYSCFG [system controller] peripheral, which has similar functions to F1's AFIO but has some differences. It mainly manages memory space mapping, IO configuration related to EXTI interrupt source, and other configuration matters. There are also slight differences between different 32 series.


If the SYSCFG clock is not turned on, operations related to memory space remapping and EXTI configuration will be invalid.




/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


The pin multiplexing arrangement of other series except STM32F1 is also different from that of F1. It provides a dedicated pin function multiplexing register and a mapping table of the multiplexing functions that each pin may play, instead of simply providing the pin REMAP and AFIO clock. If you want to use some pins for something, you can check the table configuration by combining the GPIOx_AFR. register in the reference manual and the multiplexing function mapping table in the data manual.

 

The following table is the multiplexing function table of the STM32F207 chip. PA2/PA3 can be selected according to different multiplexing function needs. If it is used as TX/RX of USART2, select AF7, and AF7 corresponds to the configuration bit of the corresponding GPIO multiplexing function register. Here it uses the lower 8-bit port line of GPIOA, so it is configured in the GPIOA_AFRL register. Write 0x0111 to AFRL2 and AFRL3 respectively. Of course, if you use the official library code of STMCU, the operation is also relatively intuitive. The sample code below the picture is just to help illustrate the topic.




/* Enable GPIO clock */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA , ENABLE);

/* Enable USART clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

/* Connect USART TX/RX pins to AF7 */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_7);

GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_7);


By the way, GPIO_PinSource2 and GPIO_Pin_2 are defined differently in the ST official library code. Sometimes people confuse the two and make mistakes. Their definitions are as follows: one focuses on indicating the position of the pin on the port, and the other focuses on indicating the serial number of the pin on the port.


#define GPIO_Pin_2 ((uint16_t)0x0004) /* Pin 2 selected */

#define GPIO_PinSource2 ((uint8_t)0x02)

 

In summary, the above-mentioned problems may occur more often when engineers develop based on ST official firmware libraries or build their own projects. Fortunately, ST has officially launched a configuration tool called STM32CUBE, which is very convenient for handling the pin arrangement and clock configuration of STM32 MCUs. It can avoid many troubles and troubles caused by misunderstandings in understanding pins or clocks and visual negligence. It is recommended to use this tool as much as possible for auxiliary development.



Keywords:STM32 Reference address:Several common questions about STM32 peripheral configuration

Previous article:About the STM32 serial port idle interrupt problem
Next article:stm32f103c8t6 pitfall record

Recommended ReadingLatest update time:2024-11-16 15:35

Understanding of SPI_NSS of STM32 series
I was also confused about SPI's NSS before. I saw in other manuals that NSS is the chip select signal. The chip select of most SPI slaves is valid at low level. When the NSS pin of a slave is low, the machine is selected and can communicate with the host through SPI. All masters and slaves actually have chip select sig
[Microcontroller]
STM32 stepper motor seedling board application design
This motor is also an application of the Xiaomiao board. It is a 28BYJ-48 stepper motor . The following is the information of the stepper motor: This is the parameter of the stepper motor . It can be seen that this is a motor with a reducer. Such a motor can only be used as a servo or something like that, and canno
[Power Management]
STM32 stepper motor seedling board application design
Stm32 clock analysis
Most of the analysis materials come from the opendev forum. All I did was add some of my own analysis and collation. Due to my limited personal ability, omissions are inevitable. I welcome your corrections. The Stm32 clock structure diagram is as follows, ( http://www.openedv.com/posts/list/302.htm ) The analysis
[Microcontroller]
Stm32 clock analysis
Modification of systick part when transplanting ucos-II to stm32
Systick initialization is usually placed in the creation of the first task, specifically at the beginning of the first task after OSInit(); In the early version of the library file, there are two files, stm32f10x_systick.c and stm32f10x_systick.h. Therefore, we only need to call the following function at the beginni
[Microcontroller]
STMicroelectronics updates TouchGFX software, adds video features to enrich STM32 user experience
STMicroelectronics updates TouchGFX software, adds video capabilities, enriches STM32 user experience China, November 5, 2021 - STMicroelectronics has released the latest version of TouchGFX Version 4.18, its graphical interface development software for STM32* microcontrollers (MCUs), which adds video
[Embedded]
STMicroelectronics updates TouchGFX software, adds video features to enrich STM32 user experience
STM32 DAC
The DAC module (digital/analog conversion module) of STM32 is a 12-bit digital input, voltage output DAC. The DAC can be configured in 8-bit or 12-bit mode, and can also be used in conjunction with a DMA controller. When the DAC works in 12-bit mode, the data can be set to left-aligned or right-aligned. The DAC module
[Microcontroller]
STM32's I2C hardware bug caused a murder
There is a BUG in the function below, that is, SR2 cannot be polled using WHILE, but should be read directly. As shown in the following code segment, Therefore, what I say here is a BUG of STM32 is actually an error in my code:     I2C2- DR = inerAddress ;     while( (I2C2- SR1&Q_I2C_SR1_BIT_BTF)==0 );     I2C2- SR2;
[Microcontroller]
STM32 DMA buffersize understanding
DMA Refer to Wildfire's "STM32 Library Development Practice" P195-P215 "DMA - Direct Memory Area Access" chapter for explanations. DMA FIFO Each data stream has four independent 32-bit FIFOs. DMA transfer has FIFO mode and direct transfer mode.  FIFO is used to temporarily store data between source and destination a
[Microcontroller]
STM32 DMA buffersize understanding
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号