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.
Previous article:About the STM32 serial port idle interrupt problem
Next article:stm32f103c8t6 pitfall record
Recommended ReadingLatest update time:2024-11-16 15:35
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 【TI mmWave Radar Review】+3D Profile Test
- I thought it was washing the phone, but it turned out to be washing the phone
- Medium and low pressure MODS pipes
- EEWORLD University Hall----Live Replay: Microchip Security Series 14 - GoodLock with SAM L11 and TrustFLEX ATECC608 Security Devices
- 【ST NUCLEO-G071RB Review】_02_LED Light Experiment
- Help, MPU6050 freezes and no data output after running for a while
- TC58CVG0S3HxAIx Engineering Data Sheet
- How to overcome the huge source of electromagnetic interference in adjacent circuits
- A strange MIC (microphone) signal amplifier circuit, I thought about it for a long time but still couldn't understand it
- My Journey of MCU Development (Part 7)