STM32 bit band operation example

Publisher:CuriousObserverLatest update time:2017-09-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

STM32 bit band operation example

int main(void)
{
    GPIO_InitTypeDef GPIO_InitStruction;
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    GPIO_InitStruction.GPIO_Pin=GPIO_Pin_8;   
    GPIO_InitStruction.GPIO_Mode=GPIO_Mode_Out_OD;
    GPIO_InitStruction.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_Init(GPIOA,&GPIO_InitStruction);  //PA8
    /*while(1)
    {
        GPIO_SetBits(GPIOA,GPIO_Pin_8);

        GPIO_ResetBits(GPIOA,GPIO_Pin_8);
    }*/
    #define GPIOA_ODR_Addr (GPIOA_BASE+0X0C)
    //Bit band address, 0X0C is the offset address of the GPIOx_ODR register, GPIOA_BASE has been defined in the header file stm32f10x.h.
    #define BITBAND(addr,bitnum) ((addr&0xF0000000)+0x2000000+((addr&0xFFFFF)<<5)+(bitnum<<2))
    //Map to the address of the alias area
    #define MEM_ADDR(addr) (*((volatile unsigned long *)(addr)))   
    #define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
    #define PA8 BIT_ADDR(GPIOA_ODR_Addr,8)
    while(1)
    {
        PA8=!PA8;
    }
}123456789101112131415161718192021222324252627

Using bit-band operations is more convenient than directly calling library functions. It is a bit like using a 51 single-chip microcomputer, haha!


Keywords:STM32 Reference address:STM32 bit band operation example

Previous article:STM32 Experiment 1: IO Output
Next article:STM32 re-understand GPIO configuration and configure PWM wave output

Recommended ReadingLatest update time:2024-11-16 16:37

STM32 USMART debugging component
1. USMART is a smart serial port debugging interactive component developed by ALIENTEK. Through it, you can call any function in the program through the serial port assistant and execute it. Therefore, you can change the input parameters of the function at will (support numbers (10/16), strings, function entry address
[Microcontroller]
stm32 keil configuration
These errors occurred \output\Buzzer.axf: Error: L6218E: Undefined symbol GPIO_Init (referred from main.o). .\output\Buzzer.axf: Error: L6218E: Undefined symbol GPIO_PinRemapConfig (referred from main.o). .\output\Buzzer.axf: Error: L6218E: Undefined symbol GPIO_SetBits (referred from main.o). .\output\Buzzer.axf: Err
[Microcontroller]
stm32 keil configuration
Why does STM32 choose 8MHz for external clock crystal?
The frequency range of the chip's main crystal oscillator is generally introduced in the datasheet and technical reference manual.   You mentioned that the clock is divided and then multiplied. This requires a deep dive into the internals of STM32 to find out. At the beginning of Section 7.2 Clocks in the technical
[Microcontroller]
Why does STM32 choose 8MHz for external clock crystal?
stm32 microcontroller clock understanding
Systick is slow, usually with a 32k external crystal, used for timing. Sysclk is the main clock, which is the highest 72M for the core and most peripherals. HCLK is the high-speed peripheral clock, which is for external devices, such as memory, flash SYSCLK system clock, maximum 72MHz HCLK: AHB bus clock, obtained b
[Microcontroller]
Tax controller solution using STM32, a high-performance, low-cost chip
    With the promotion of the Golden Tax Project, the tax control market will develop rapidly. As one of the four major tax control products, the tax controller has a market share that cannot be underestimated. Tax control manufacturers need to consider the performance and cost of their products in many aspects. In th
[Microcontroller]
Tax controller solution using STM32, a high-performance, low-cost chip
Step by step STM32 startup code
For those who are familiar with computers, BIOS (the blue interface) may not be too unfamiliar. This thing is the computer's startup code. A computer without BIOS is destined to be a brick! BIOS is mainly used to do some preparatory work before booting, such as system time setting and boot sequence...     In fact, the
[Microcontroller]
Step by step STM32 startup code
STM32 study notes UCOSII (1)
1 Introduction UCOSII is a ROM-based, scalable, preemptive, real-time multitasking kernel with high portability. It is particularly suitable for microprocessors and controllers and is a real-time operating system (RTOS) with performance comparable to many commercial operating systems. 1.1 UCOSII Architecture Diagr
[Microcontroller]
STM32 study notes UCOSII (1)
STM32 learning notes on quadrature encoder interface
I recently worked on a project, the main control chip is STM32RBT6, and I need to use a grating ruler. It originally came with a controller, and the data of the grating ruler can be read through the controller's 232, but this controller is too large to fit in the device, so I considered making one myself. I saw many us
[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号