HC32F460的GPIO操作
//时钟配置如下void SYSClk_Config(void) {
CLK_HrcCmd(Disable);
uint32_t delay = 1000;
while(delay--) {};
CLK_XtalCmd(Enable);
CLK_HrcCmd(Enable);//HRC默认16M
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_SRAMH, Enable);
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_SRAM12, Enable);
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_SRAM3, Enable);
PWC_Fcg0PeriphClockCmd(PWC_FCG0_PERIPH_SRAMRET, Enable);
stc_clk_output_cfg_t stcOutputClkCfg;
MEM_ZERO_STRUCT(stcOutputClkCfg);
{
//主时钟和ram时钟配置
stc_sram_config_t stcSramConfig;
MEM_ZERO_STRUCT(stcSramConfig);
/* sram init include read/write wait cycle setting */
stcSramConfig.u8SramIdx = Sram12Idx | Sram3Idx | SramRetIdx;
stcSramConfig.enSramRC = SramCycle2;
stcSramConfig.enSramWC = SramCycle2;
stcSramConfig.enSramEccMode = EccMode3;
stcSramConfig.enSramEccOp = SramNmi;
stcSramConfig.enSramPyOp = SramNmi;
SRAM_Init(&stcSramConfig);
stcSramConfig.u8SramIdx = SramHsIdx;
stcSramConfig.enSramRC = SramCycle1;
stcSramConfig.enSramWC = SramCycle1;
stcSramConfig.enSramEccMode = EccMode3;
stcSramConfig.enSramEccOp = SramNmi;
stcSramConfig.enSramPyOp = SramNmi;
SRAM_Init(&stcSramConfig);
/* flash 读等待周期*/
EFM_Unlock();
EFM_SetLatency(EFM_LATENCY_5);
EFM_InstructionCacheCmd(Enable);
EFM_Lock();
stc_clk_mpll_cfg_t stcMpllCfg;
MEM_ZERO_STRUCT(stcMpllCfg);
/* MPLL config (XTAL / pllmDiv * plln / PllpDiv = 200M). */
stcMpllCfg.pllmDiv = 2ul;// 16/2 = 8M MPLL的VCO输入频率介于1MHz到12MHz之间。
stcMpllCfg.plln = 24ul;// 8x42 = 192M 确保MPLL的VCO频率介于240MHz到480MHz之间
stcMpllCfg.PllpDiv = 1ul;// 192M
stcMpllCfg.PllqDiv = 1ul;// 192M
stcMpllCfg.PllrDiv = 1ul;// 192M
CLK_SetPllSource(ClkPllSrcXTAL);
CLK_MpllConfig(&stcMpllCfg);
/* Enable MPLL. */
CLK_MpllCmd(Enable);
}
{
//外设时钟分频
stc_clk_sysclk_cfg_t stcSysClkCfg;
MEM_ZERO_STRUCT(stcSysClkCfg);
/* Set bus clk div. */
stcSysClkCfg.enHclkDiv= ClkSysclkDiv1;//CPU
stcSysClkCfg.enExclkDiv = ClkSysclkDiv2;//SDIO CAN
stcSysClkCfg.enPclk0Div = ClkSysclkDiv1;//TIM6计数
stcSysClkCfg.enPclk1Div = ClkSysclkDiv2;//UART SPI USB逻辑 TIM0 TIMA TIM4 TIM6逻辑
stcSysClkCfg.enPclk2Div = ClkSysclkDiv4;//ADC变换
stcSysClkCfg.enPclk3Div = ClkSysclkDiv4;//RTC I2C CMP WDT SWDT
stcSysClkCfg.enPclk4Div = ClkSysclkDiv2;//ADC逻辑控制,TRNG
CLK_SysClkConfig(&stcSysClkCfg);
}
PWC_HS2HP();// high speed -> high performance
CLK_SetSysClkSource(CLKSysSrcMPLL);
}
int main() {
PORT_Unlock();
M4_PORT->PSPCR = 3;
M4_PORT->PCCR_f.RDWT = 3;
SYSClk_Config();
stc_port_init_t stcPortInit = {0};
stcPortInit.enPinMode = Pin_Mode_Out;
stcPortInit.enPinDrv = Pin_Drv_H;
PORT_Init(PortB, Pin03, &stcPortInit);
//使用bit-band映射翻转位,暂时不清楚使用bit-band之后keil调试容易崩溃,但是执行无问题
uint32_t* pb3T_bitBand = (unsigned int*)(0x42A7038CUL);
while(1) {
*pb3T_bitBand = 1;
}
}反汇编如下https://i1.hdslb.com/bfs/article/e281df8530019606e89573a706d4c4ea199929899.png@1192w.webp<span]以上代码执行后示波器抓取IO波形,频率为32MHZ:https://i1.hdslb.com/bfs/new_dyn/watermark/f439381fc2c9d7af32bff417f765b521199929899.png@1192w.webp
<span]看看IO口波形:https://i1.hdslb.com/bfs/new_dyn/watermark/588d4a6e4500a7198b4b4e7f230a9ee7199929899.png@1192w.webp
简单的GPIO操作,竟然涉及这么多的时钟设置。RAM的也需要特别设置吗?
页:
[1]