STM32 TIM2 remapping

Publisher:JoyfulExplorerLatest update time:2018-06-15 Source: eefocusKeywords:STM32  TIM2 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

There are four port usage combinations of TIM2 of stm32:


1. When not remapped, the default four IO ports of TIM2 are PA0, PA1, PA2, and PA3

2. To use the port combination of PA15, PB3, PA2, and PA3, call the following statement for partial remapping:

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Remapping requires turning on the AFIO clock

  GPIO_PinRemapConfig(GPIO_PartialRemap1_TIM2, ENABLE);


3. To use the port combination of PA0, PA1, PB10, and PB11, call the following statement for partial remapping:

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Remapping requires turning on the AFIO clock

  GPIO_PinRemapConfig(GPIO_PartialRemap2_TIM2, ENABLE);


4. To use the port combination of PA15, PB3, PB10, and PB11, call the following statement for complete remapping:

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); //Remapping requires turning on the AFIO clock

  GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);

At the same time, the JTAG function must be disabled so that PA15, PB3, PB10, and PB11 can output normally.


Fully mapped port configuration function:


  1. static void TIM2_GPIO_Config(void) //CH1-PA15 CH2-PB3 CH3-PB10 CH4-PB11 remapping  

  2. {  

  3.   GPIO_InitTypeDef GPIO_InitStructure;  

  4.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);   

  5.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);   

  6.   

  7.   GPIO_PinRemapConfig(GPIO_FullRemap_TIM2, ENABLE);  

  8.   GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //Disable JTAG function and use PB3 and PB4 as normal IO ports  

  9.       

  10.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;  

  11.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // Multiplexed push-pull output  

  12.   GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz;  

  13.   GPIO_Init(GPIOA, &GPIO_InitStructure);  

  14.   

  15.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_10 | GPIO_Pin_11;  

  16.   GPIO_Init(GPIOB, &GPIO_InitStructure);  

  17. }  


Keywords:STM32  TIM2 Reference address:STM32 TIM2 remapping

Previous article:STM32 Self-study Notes - External Interrupts
Next article:STM32 external interrupt configuration steps

Recommended ReadingLatest update time:2024-11-16 23:49

STM32 JNTRST JTDI JTDO pins are used as normal IO method
When STM32 starts by default, the three pins PB4, PB3, and PA15 are not ordinary IOs, but JTAG multiplexing functions, namely JNTRST, JTDI, and JTDO. When we try to use the SWD interface to debug the simulation, these three pins can be used as normal IO. The specific method is to disable the JTAG function. Just use
[Microcontroller]
Try STM32 interrupt program
    I wrote an interrupt function using STM32F103VBT6 some time ago. I wanted to learn more about the interrupt mechanism of STM32. After using it, I found that the interrupt configuration of STM32 is quite flexible and stable. After testing, I found that there were almost no errors. I opened three interrupts in the p
[Microcontroller]
Try STM32 interrupt program
PIC 1508 TIM2 timer usage
The frequency calculation formula using TIM2 is f=FOSC/4/T2CKPS/T2OUTPS/TMR2 (TMR2 is the data register of TIM2) void main() {     OSCCON = 0x78; //The main frequency is 16M, that is, FOSC = 16M     __delay_ms(50);     ANSC6 = 1;     TRISC6 = 0;     RC6 = 1; //RC6 is connected to an LED          T2CON = 0x04;  
[Microcontroller]
PIC 1508 TIM2 timer usage
STM32 study notes: HEX file and BIN file format
1 Introduction Today we are looking at the serial port IAP. Usually we download HEX files through tools such as JTAG, and we have never thought about the composition of HEX files. However, the serial port IAP downloads BIN files, so it is just right to learn how to distinguish them here. We usually do not need to se
[Microcontroller]
STM32 study notes: HEX file and BIN file format
STM32 running RTOS operating system ucosii serial port interrupt implementation
First, let’s take a look at how the book is written. The screenshot is as follows: It says: In μC/OS, the interrupt service subroutine must be written in assembly language. However, if the C language compiler used by the user supports online assembly language, the user can directly put the interrupt service subrou
[Microcontroller]
STM32 running RTOS operating system ucosii serial port interrupt implementation
STM32 software reset (based on library file V3.5)
STM32 software reset (based on library file V3.5)   void SoftReset(void) { __set_FAULTMASK(1); // Turn off all mid-end NVIC_SystemReset(); // Reset }   In the core_cm3.h file of the official software library, a system reset function is directly provided     static __INLINE void NVIC_SystemReset(void) {  
[Microcontroller]
STM32-IIC analog slave mode
Here we are talking about simulated IIC, not hardware IIC. Why use software simulated IIC instead of hardware IIC? In addition to the problems of ST's IIC module itself, it is also because hardware IIC is not convenient to transplant and cannot be used universally in different MCUs; and some projects require switching
[Microcontroller]
Getting started with BIT_BAND (bit segment/bit band) and alias area in STM32
1. What are bit segments and alias areas? Yes, remember MCS51? MCS51 has bit operations, which take one bit (BIT) as the data object. MCS51 can simply operate the second bit of port P1 independently: P1.2=0;P1.2=1; thus, the third pin (BIT2) of port P1 is set to 0 or 1. Now the bit segment and bit band alias area of
[Microcontroller]
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号