Discrepancy in RCC_AHB4ENR Address for STM32H7A3RGT6
Hello,
I have designed a custom STM32 module using the STM32H7A3RGT6 microcontroller. In my design, PB9 is connected to an LED, and to verify the module's functionality, I attempted to toggle this LED.
Here’s where the issue arises: According to the STM32H7A3RGT6 reference manual, GPIOB is connected to the AHB4 bus, meaning its peripheral clock should be enabled using RCC_AHB4ENR. The manual specifies an offset of 0x140 for this register. However, when I use this offset in my code, the LED does not toggle, suggesting that the address is incorrect.
Interestingly, when I asked ChatGPT for the correct offset, it provided 0xE0—and when I used this value, the LED toggled successfully!
This raises concerns about the correctness of the reference manual or suggests that I may be missing something. Could you clarify why there is a discrepancy in the RCC_AHB4ENR address?
Here are my codes:
GPIO_DRIVER.H Code
#ifndef INC_STM32H7A3XX_GPIO_DRIVER_H_
#define INC_STM32H7A3XX_GPIO_DRIVER_H_
#ifndef GPIO_H
#define GPIO_H
#include <stdint.h>
// Base Addresses
#define RCC_BASE (0x58024400UL)
#define GPIOB_BASE (0x58020400UL)
// RCC Register
#define RCC_AHB4ENR (*(volatile uint32_t *)(RCC_BASE + 0xE0))
#define RCC_GPIOB_EN (1 << 1) // Bit 1 enables GPIOB clock
// GPIO Registers
#define GPIOB_MODER (*(volatile uint32_t *)(GPIOB_BASE + 0x00))
#define GPIOB_ODR (*(volatile uint32_t *)(GPIOB_BASE + 0x14))
// Function Prototypes
void GPIOB_Init(void);
void GPIOB_TogglePin(void);
#endif // GPIO_H
#endif /* INC_STM32H7A3XX_GPIO_DRIVER_H_ */
GPIO_DRIVER.c code
#include "stm32h7a3xx_gpio_driver.h"
// Enable GPIOB clock and configure PB9 as output
void GPIOB_Init(void) {
RCC_AHB4ENR |= RCC_GPIOB_EN; // Enable GPIOB clock
// Set PB9 as output (MODER9 = 01)
GPIOB_MODER &= ~(0b11 << (9 * 2)); // Clear MODER9 bits
GPIOB_MODER |= (0b01 << (9 * 2)); // Set MODER9 to 01 (output)
}
// Toggle PB9
void GPIOB_TogglePin(void) {
GPIOB_ODR ^= (1 << 9); // Toggle PB9
}
LEDtoggle.c code
#include "Stm32h7a3xx_gpio_driver.h"
void delay(void) {
for (volatile int i = 0; i < 500000; i++);
}
int main(void) {
GPIOB_Init(); // Initialize PB9
while (1) {
GPIOB_TogglePin(); // Toggle LED on PB9
delay();
}
return 0;
}
