STM32IO and timer mapping to address

Publisher:hzx312895379Latest update time:2018-09-22 Source: eefocusKeywords:STM32  address Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Significance: Sometimes when we operate multiple STM32 IOs, the hardware design may not be regular, such as the output pins are: PB3, PC4, PC5, PD0, but the operations of these pins have commonalities, or we want to use for(it i = 0; i < 4; i++) to operate these pins like an array, the program will become very concise, then mapping IO to the address can achieve this goal.

method: 

1. //Bit-band operation to achieve GPIO control functions similar to 51

//For specific implementation ideas, refer to Chapter 5 (pages 87-92) of the "CM3 Authoritative Guide". M4 is similar to M3, except that the register address has changed.

//IO port operation macro definition

#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 

//IO port address mapping

#define GPIOA_ODR_Addr    (GPIOA_BASE+20) //0x40020014

#define GPIOB_ODR_Addr    (GPIOB_BASE+20) //0x40020414 

#define GPIOC_ODR_Addr    (GPIOC_BASE+20) //0x40020814 

#define GPIOD_ODR_Addr    (GPIOD_BASE+20) //0x40020C14 

#define GPIOE_ODR_Addr    (GPIOE_BASE+20) //0x40021014 

#define GPIOF_ODR_Addr    (GPIOF_BASE+20) //0x40021414    

#define GPIOG_ODR_Addr    (GPIOG_BASE+20) //0x40021814   

#define GPIOH_ODR_Addr    (GPIOH_BASE+20) //0x40021C14    

#define GPIOI_ODR_Addr    (GPIOI_BASE+20) //0x40022014     

#define GPIOA_IDR_Addr    (GPIOA_BASE+16) //0x40020010 

#define GPIOB_IDR_Addr    (GPIOB_BASE+16) //0x40020410 

#define GPIOC_IDR_Addr    (GPIOC_BASE+16) //0x40020810 

#define GPIOD_IDR_Addr    (GPIOD_BASE+16) //0x40020C10 

#define GPIOE_IDR_Addr    (GPIOE_BASE+16) //0x40021010 

#define GPIOF_IDR_Addr    (GPIOF_BASE+16) //0x40021410 

#define GPIOG_IDR_Addr    (GPIOG_BASE+16) //0x40021810 

#define GPIOH_IDR_Addr    (GPIOH_BASE+16) //0x40021C10 

#define GPIOI_IDR_Addr    (GPIOI_BASE+16) //0x40022010 

 

2. Output: u32 val = BITBAND(GPIOB_ODR_Addr, 3); Print out val (input is: GPIOB_IDR_Addr)

PB3, PC4, PC5, PD0 correspond to: 0x4240828c, 0x42410290, 0x42410294, 0x42418280

3. Operation:

   uint32_t  PinTest[4] = {0x4240828c, 0x42410290, 0x42410294, 0x42418280};

   *((vu32 *)(PinTest[idx])) = 1;       *((vu32 *)(PinTest[idx])) = 0;

4. Input operation is similar

5. Timer related:

   u32 val =  (u32)&(TIM3->CCR3);     // TIM_Pluse

   u32 val =  (u32)&(TIM3->ARR);       // TIM_Period


Keywords:STM32  address Reference address:STM32IO and timer mapping to address

Previous article:STM32 24C02 function I2C routine non-STM32 library method
Next article:STM32 timer (including interrupt) configuration example

Recommended ReadingLatest update time:2024-11-15 10:51

STM32 introductory study notes: watchdog experiment (Part 2)
14.4.2 Window watchdog experiment Function: As soon as the program is run, LED1 connected to PB5 lights up for 300ms and then turns off, entering an infinite loop. Wait for the WWDG interrupt to arrive. In the interrupt, feed the dog and flip LED2 on PE5. You can see that LED2 flashes continuously, and LED1 only flash
[Microcontroller]
STM32 library file systemInit crystal oscillator changes the default crystal oscillator 8M to 12M method
Since the stm32 library is implemented with an external crystal oscillator of 8M by default, the serial port baud rate is also configured at 8M, including the main frequency. If an external crystal oscillator of 12M is used, the configuration clock is 72MHZ. 1) Change the PLL multiplier like this: 8M: RCC- CFGR |= (
[Microcontroller]
STM32 three timers
STM32 has three timers: advanced control timer (TIM1 and TIM8), general timer (TIM2~TIM5), basic timer (TIM6 and TIM7). Functions of TIM1 and TIM8 timers (1) 16-bit up, down, up/down auto-load counter  (2) 16-bit programmable (can be modified in real time) prescaler, the counter clock frequency division factor is any
[Microcontroller]
How to check IO port of STM8
Today I am using STM8L151K6 to enable the output of ADP3110A, so I configured the IO port as follows: PC1 GPIO_Init(ADP3110A_EN_PORT, (GPIO_Pin_TypeDef)ADP3110A_EN_PINS, GPIO_Mode_Out_PP_High_Fast);  GPIO_SetBits(ADP3110A_EN_PORT,ADP3110A_EN_PINS); //Turn on ADP3110A_EN However, the oscilloscope measurement revealed t
[Microcontroller]
How to check IO port of STM8
STM32 NVIC learning
   NVIC_InitTypeDef NVIC_InitStructure;   /* Configure the NVIC Preemption Priority Bits */    /* Configure one bit for preemption priority */   /* The priority group specifies the number of bits used for preemption priority and the number of bits used for subpriority, here 1 and 7 */      NVIC_PriorityGroupConfig(NVI
[Microcontroller]
STM32IAP upgrade-----Summary of problems encountered in writing IAP upgrade
I uploaded the source code and other materials of IAP. There are 12 files in the compressed package. http://download.csdn.net/detail/f907279313/7524849 (If you want points, please give some points for your hard work in collecting them) There is another blog post summarizing IAP: http://blog.csdn.net/super_demo/articl
[Microcontroller]
STM32IAP upgrade-----Summary of problems encountered in writing IAP upgrade
STM32 Systick Timer
Q: What is the SysTick timer?  SysTick is a 24-bit countdown timer. When it counts to 0, it will automatically reload the initial value of the timer from the RELOAD register. As long as its enable bit in the SysTick control and status register is not cleared, it will never stop.  Q: Why set the SysTick timer?  (1) Gen
[Microcontroller]
STM32 Study Notes 3——Systick
For STM32, there is a tool that is often used but rarely mentioned in the data sheet, that is Systick. This tool is common to all microcontrollers with the cortex-M0 core. It is a system timer, and its main purpose is to provide a 100Hz (10ms) timing beat for the embedded operating system. Of course, it can also be us
[Microcontroller]
Latest Microcontroller Articles
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号