oxygen_sh 发表于 2022-2-1 15:16

【国民技术M4内核热销款N32G45XVL评估】第二篇 IO口复用配置及IO输出频率评估

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">一、</font><font face="Calibri">IO</font><font face="宋体">口复用配置</font></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">打开例程</font><font face="Calibri">LedBlink</font><font face="宋体">。</font></span></span></span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:Calibri">N32G45XVL-STB</span></span><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">板上</font><font face="Calibri">D1/D2/D3</font><font face="宋体">三颗</font><font face="Calibri">LED</font><font face="宋体">分别由</font><font face="Calibri">PA8/PB4/PB5</font><font face="宋体">控制。</font></span></span></span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">在</font><font face="Calibri">main.h</font><font face="宋体">中,按照上面电路修改</font><font face="Calibri">IO</font><font face="宋体">端口分配:</font></span></span></span></span></p>

<pre>
<code>#define PORT_GROUP1 GPIOA
#define PORT_GROUP2 GPIOB
#define LED1_PORT   PORT_GROUP1
#define LED2_PORT   PORT_GROUP2
#define LED3_PORT   PORT_GROUP2</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">程序编译和下载后,</font><font face="Calibri">LED1</font><font face="宋体">和</font><font face="Calibri">LED3</font><font face="宋体">正常闪烁;但</font><font face="Calibri">LED2</font><font face="宋体">没有按照预想进行闪烁。</font></span></span></span></span></p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">查手册,发现</font><font face="Calibri">PB4</font><font face="宋体">管脚复位后功能为</font><font face="Calibri">JTAG</font><font face="宋体">接口的</font><font face="Calibri">NJTRST</font><font face="宋体">信号,</font><font face="Calibri">GPIO</font><font face="宋体">是只是此管脚的复位功能。应该要先将此管脚配置为复用功能(</font><font face="Calibri">GPIO</font><font face="宋体">)才行。</font></span></span></span></span></p>

<p style="text-align:justify"> &nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">增加以下代码,将</font><font face="Calibri">PB4</font><font face="宋体">配置为</font><font face="Calibri">IO</font><font face="宋体">口功能。</font></span></span></span></span></p>

<pre>
<code>        GPIO_InitType GPIO_InitStructure;
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOB, ENABLE);
        GPIO_ConfigPinRemap(GPIO_RMP_SW_JTAG_DISABLE, ENABLE);
        GPIO_InitStructure.Pin = GPIO_PIN_4;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode= GPIO_Mode_Out_PP;
GPIO_InitPeripheral(GPIOB, &amp;GPIO_InitStructure);</code></pre>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">修改完后,再编译运行,</font><font face="Calibri">LED2</font><font face="宋体">也能正常显示了。</font></span></span></span></span></p>

<p style="text-indent:21.0000pt; text-align:justify">&nbsp;</p>

<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="Calibri">二、 IO</font><font face="宋体">口输出频率评估</font></span></span></span></span></p>

<p align="justify" style="text-align:justify">&nbsp;</p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">选择</font><font face="Calibri">PC6</font><font face="宋体">作为测试</font><font face="Calibri">IO</font><font face="宋体">口。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify">&nbsp;</p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">系统时钟选择</font><font face="Calibri">PLL</font><font face="宋体">输出,设置为最高的</font><font face="Calibri">144MHz</font><font face="宋体">。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">注意:使用内部时钟</font><font face="Calibri">HSI</font><font face="宋体">最高只能到</font><font face="Calibri">128MHz</font><font face="宋体">。只有使用外部时钟,才能达到最高的</font><font face="Calibri">144MHz</font><font face="宋体">。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify">&nbsp;</p>

<pre>
<code>        GPIO_InitType GPIO_InitStructure;
        Delay(0x28FFFF*4);

        SetSysClockToPLL(144000000, SYSCLK_PLLSRC_HSE);
        RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO | RCC_APB2_PERIPH_GPIOC, ENABLE);
        GPIO_InitStructure.Pin = GPIO_PIN_6;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode= GPIO_Mode_Out_PP;
    GPIO_InitPeripheral(GPIOC, &amp;GPIO_InitStructure);</code></pre>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">使用下面代码不断切换</font><font face="Calibri">IO</font><font face="宋体">口输出电平。</font></span></span></span></span></span></p>

<pre>
<code>        while(1){
                GPIOC-&gt;POD = 0x00000040;
                GPIOC-&gt;POD = 0x0000FFBF;
        }</code></pre>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">使用示波器测量</font><font face="Calibri">PC6</font><font face="宋体">的输出信号频率,为</font><font face="Calibri">14.4MHz</font><font face="宋体">。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify"> &nbsp;<span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri">&nbsp;</span></span></span></p>

<p align="justify" style="text-align:justify">&nbsp;</p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">下面分析一下测到的这个频率是否合理。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify"><span style="font-size:10.5pt"><span style="text-justify:inter-ideograph"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">当系统时钟为</font><font face="Calibri">144MHz</font><font face="宋体">时,</font><font face="Calibri">Flash Lantency</font><font face="宋体">需要设置为</font><font face="Calibri">4</font><font face="宋体">。</font><font face="Calibri">Flash</font><font face="宋体">访问速度受限,测到的</font><font face="Calibri">14.4MHz</font><font face="宋体">应该是合理的。</font></span></span></span></span></span></p>

<p align="justify" style="text-align:justify">&nbsp;</p>

<p align="justify" style="text-align:justify"> &nbsp;</p>

<p align="justify" style="text-align:justify"> &nbsp;</p>

<p align="justify" style="text-align:justify">&nbsp;</p>
页: [1]
查看完整版本: 【国民技术M4内核热销款N32G45XVL评估】第二篇 IO口复用配置及IO输出频率评估