Microcontroller Embedded C Programming Lecture 160| Bit-field structure for RCC_AHB1ENR

  • Post author:
  • Post category:Blog

 

Bit-field structure for RCC_AHB1ENR

 

The RCC_AHB1ENR register is a control register used in the STM32 microcontroller series for enabling or disabling clock signals for various peripherals connected to the AHB1 (Advanced High-Performance Bus 1) bus.

The RCC_AHB1ENR register typically consists of multiple individual bits, each representing the enable/disable state of a specific peripheral clock signal. These individual bits are often referred to as bit fields.

The below figure shows the typedef structure for the RCC_AHB1ENR.

#ifndef MAIN_H_
#define MAIN_H_

#include<stdint.h>

typedef struct
{
    uint32_t gpioa_en     :1;
    uint32_t gpiob_en     :1;
    uint32_t gpioc_en     :1;
    uint32_t gpiod_en     :1;
    uint32_t gpioe_en     :1;
    uint32_t gpiof_en     :1;
    uint32_t gpiog_en     :1;
    uint32_t gpioh_en     :1;
    uint32_t gpioi_en     :1;
    uint32_t reserved1    :3;
    uint32_t crc_en       :1;
    uint32_t reserved2    :3;
    uint32_t reserved3    :2;
    uint32_t bkpsram_en   :1;
    uint32_t reserved4    :1;
    uint32_t ccmdat_en    :1;
    uint32_t dma1_en      :1;
    uint32_t dma2_en      :1;
    uint32_t reserved5    :2;
    uint32_t ethmac_en    :1;
    uint32_t ethmactx_en  :1;
    uint32_t ethmacrx_en  :1;
    uint32_t ethmacptp_en :1;
    uint32_t otghs_en     :1;
    uint32_t otghsulpi_en :1;
}RCC_AHB1ENR_t;



#endif /* MAIN_H_ */

typedef struct for the RCC_AHB1ENR

 

This completely encodes the  AHB1ENR register. 

And also for the reserved member elements use different names. Here I have used reserved1,  reserved2, and reserved3, like that. Because two member elements cannot have the same name. That’s why you can do something like this.

After creating the typedef structure, always try to compile your code, that is very much important. So, it will immediately report whether there are any errors in the structures or not.

Similarly, create two more typedef structures. One for the GPIO mode register and another one for the GPIO output data register. I will show you in the following article. 

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.