Keil MDK使用调试GPIO寄存器显示问题

问题描述

本人在尝试使用结构体来操作寄存器完成STM32F429TIZx芯片的GPIO操作时,发现在Keil MDK的GPIOG寄存器视图中无法查看到寄存器值的变化。我使用的是ST-LINK调试器操作的是GPIOG端口,如下图所示:

代码:

//#include "my_gpio_driver.h"

#include "stdint.h"
	
#define RCC_BASE_ADDR (0x40003800U)
#define GPIOG_BASE_ADDR (0x40021800U)

//SET GPIOx Peripheral
typedef struct{
	volatile uint32_t	GPIOx_MODER;
	volatile uint32_t	GPIOx_OTYPER;
	volatile uint32_t	GPIOx_OSPEEDR;
	volatile uint32_t	GPIOx_PUPDR;
	volatile uint32_t	GPIOx_IDR;
	volatile uint32_t	GPIOx_ODR;
	volatile uint32_t	GPIOx_BSRR;
	volatile uint32_t	GPIOx_LCKR;
	volatile uint32_t	GPIOx_AFRL;
	volatile uint32_t	GPIOx_AFRH;
}GPIOx_Type;

typedef struct{
	volatile uint32_t RCC_CR;
	volatile uint32_t RCC_PLLCFGR;
	volatile uint32_t RCC_CFGR;
	volatile uint32_t RCC_CIR;
	volatile uint32_t RCC_AHB1RSTR;
	volatile uint32_t RCC_AHB2RSTR;
	volatile uint32_t RCC_AHB3RSTR;
	volatile uint32_t Reserved_0;
	volatile uint32_t RCC_APB1RSTR;
	volatile uint32_t RCC_APB2RSTR;
	volatile uint32_t Reserved_1;
	volatile uint32_t Reserved_2;
	volatile uint32_t RCC_AHB1ENR;
	volatile uint32_t RCC_AHB2ENR;
	volatile uint32_t RCC_AHB3ENR;
	volatile uint32_t Reserved_3;
	volatile uint32_t RCC_APB1ENR;
	volatile uint32_t RCC_APB2ENR;
	volatile uint32_t Reserved_4;
	volatile uint32_t Reserved_5;
	volatile uint32_t RCC_AHB1LPENR;
	volatile uint32_t RCC_AHB2LPENR;
	volatile uint32_t RCC_AHB3LPENR;
	volatile uint32_t Reserved_6;
	volatile uint32_t RCC_APB1LPENR;
	volatile uint32_t RCC_APB2LPENR;
	volatile uint32_t Reserved_7;
	volatile uint32_t Reserved_8;
	volatile uint32_t RCC_BDCR;
	volatile uint32_t RCC_CSR;
	volatile uint32_t Reserved_9;
	volatile uint32_t Reserved_10;
	volatile uint32_t RCC_SSCGR;
	volatile uint32_t RCC_PLLI2SCFGR;
}RCC_CLOCK;


#define RCC ((RCC_CLOCK *)RCC_BASE_ADDR)
#define GPIOG ((GPIOx_Type *)GPIOG_BASE_ADDR)

void LED_Init(void)
{
	
	 RCC->RCC_AHB1ENR |= (1 << 6);
	 GPIOG->GPIOx_MODER |= (1 << 26);
	 GPIOG->GPIOx_OSPEEDR |= (1 << 26);
	 GPIOG->GPIOx_PUPDR |= (1 << 26);
	 GPIOG->GPIOx_ODR |= (1 << 13);
}

void LED_on(void)
{
		GPIOG->GPIOx_BSRR |= (1 << 13);
}

void LED_off(void)
{
		GPIOG->GPIOx_BSRR |= (1 << 29);
}

int main(void)
{
		LED_Init();
		while(1)
		{
				LED_on();
			  LED_off();
		}
		return 0;
}

 但是使用MDK的软件仿真是可以查看到寄存器的变化的,如下图所示:

解决:

后来反复对比外设地址,发现是RCC时钟地址搞错了将它写成0x40003800而它实际应该为0x40023800修改地址后一切正常!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值