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
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
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- Friends in Xi'an, please get out of this pit as soon as possible.
- Xianyu low-cost wireless digital microphone disassembly (Jerry solution)
- [Perf-V Review] + Solidification of Hummingbird Soft Core
- Read the good book "Electronic Engineer Self-study Handbook" + my impression
- Three-port network
- RSL10 drives ink screen
- GoKit Case Study: Gizwits IoT Development Platform’s Pet House Transformed into an Air Quality Detector
- Embedded licensing: why not and why not?
- I found a 1963 "Electron Tube Handbook"
- How to extract the effective value of fundamental wave and each harmonic in MATLAB?