#技术资源#
当MCU进入debug模式、程序未运行时,可通过DBGMCU控制MCU的模块是否工作,具体细节见参考手册,以下是以TImer1为例,记录了操作方法及现象。 1 通过驱动库中的库函数实现1.1 包含头文件 apm32f10x_dbgmcu.h,编写代码如下: 1.2 进入debug并在如下位置停下来
1.3 运行观察记录现象 默认情况 | | | | | 执行DBGMCU_Enable(DBGMCU_TMR1_STOP) | | | | | 执行DBGMCU_Disable(DBGMCU_TMR1_STOP) | | | | |
2 通过keil中的调试工具实现2.1 进入debug模式,找到调试中的“DBGMCU”
2.2 找到DGBMCU中设置Timer的bit位
2.3 运行至while(1)位置并并停下来采集波形
2.4 记录现象如下 3 参考代码#include "main.h" #include "apm32f10x_dbgmcu.h" volatile uint32_t tick = 0; int main(void) { GPIO_Config_T GPIO_ConfigStruct; TMR_BaseConfig_T TMR_TimeBaseStruct; TMR_OCConfig_T OCcongigStruct; uint32_tpclk1_value=0,pclk2_value; RCM_ReadPCLKFreq(&pclk1_value,&pclk2_value); RCM_EnableAPB2PeriphClock((RCM_APB2_PERIPH_T)(RCM_APB2_PERIPH_GPIOA |RCM_APB2_PERIPH_TMR1 | RCM_APB2_PERIPH_GPIOB)); GPIO_ConfigStruct.pin = GPIO_PIN_13; GPIO_ConfigStruct.mode = GPIO_MODE_AF_PP; GPIO_ConfigStruct.speed = GPIO_SPEED_50MHz; GPIO_Config(GPIOB, &GPIO_ConfigStruct); GPIO_ConfigStruct.pin = GPIO_PIN_8; GPIO_Config(GPIOA, &GPIO_ConfigStruct); TMR_TimeBaseStruct.clockDivision = TMR_CLOCK_DIV_1; TMR_TimeBaseStruct.countMode = TMR_COUNTER_MODE_UP; TMR_TimeBaseStruct.division =720-1; TMR_TimeBaseStruct.period = 10-1; TMR_ConfigTimeBase(TMR1, &TMR_TimeBaseStruct); OCcongigStruct.idleState = TMR_OC_IDLE_STATE_RESET; OCcongigStruct.mode = TMR_OC_MODE_PWM1; OCcongigStruct.nIdleState = TMR_OC_NIDLE_STATE_RESET; OCcongigStruct.nPolarity = TMR_OC_NPOLARITY_HIGH; OCcongigStruct.outputNState = TMR_OC_NSTATE_ENABLE; OCcongigStruct.outputState = TMR_OC_STATE_ENABLE; OCcongigStruct.polarity = TMR_OC_POLARITY_HIGH; OCcongigStruct.pulse = 3; TMR_ConfigOC1(TMR1, &OCcongigStruct); TMR_ConfigOC1Preload(TMR1, TMR_OC_PRELOAD_ENABLE); TMR_EnableAutoReload(TMR1); TMR_Enable(TMR1); TMR_EnablePWMOutputs(TMR1); DBGMCU_Enable(DBGMCU_TMR1_STOP); DBGMCU_Disable(DBGMCU_TMR1_STOP); while(1) { } }
|