硬件:秉火(还是*火)的STM32F746核心板(两个双排针+W25Q128+SDRAM_IS42S16400J-7TLI),有一个小蓝LED和一个红 {MOD}电源指示LED
软件:IAR7.5+JLINK V9 SWD
代码:一段简单的测试GPIO翻转的小程序:
int main(void)
{
/* 1. Enable the CPU Cache */
CPU_CACHE_Enable();
/* This sample code shows how to use GPIO HAL API to toggle GPIOA-GPIO_PIN_5 IO
in an infinite loop. It is possible to connect a LED between GPIOA-GPIO_PIN_5
output and ground via a 330ohm resistor to see this external LED blink.
Otherwise an oscilloscope can be used to see the output GPIO signal */
/* 2. STM32F7xx HAL library initialization:
- Configure the Flash ART accelerator
- Systick timer is configured by default as source of time base, but user
can eventually implement his proper time base source (a general purpose
timer for example or other time source), keeping in mind that Time base
duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
handled in milliseconds basis.
- Set NVIC Group Priority to 4
- Low Level Initialization
*/
HAL_Init();
/* 3. Configure the system clock to 216 MHz */
SystemClock_Config();
/* 4. Enable GPIO Clock (to be able to program the configuration registers) */
__HAL_RCC_GPIOA_CLK_ENABLE();
/* 5. Configure IO in output push-pull mode to drive external LEDs */
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Pin = GPIO_PIN_5;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* 6. Toggle IO in an infinite loop */
while (1)
{
GPIOA->BSRR = GPIO_PIN_5;
(void)GPIOA->BSRR;
GPIOA->BSRR = ((uint32_t)GPIO_PIN_5 << 16);
(void)GPIOA->BSRR;
/* 中间有很多这样的翻转语句 */
GPIOA->BSRR = GPIO_PIN_5;
(void)GPIOA->BSRR;
GPIOA->BSRR = ((uint32_t)GPIO_PIN_5 << 16);
(void)GPIOA->BSRR;
}
}
用示波器看到,只有不到15MHz的翻转频率。
如果去掉
(void)GPIOA->BSRR;
就比较奇怪,大部分处于1.5V左右的中间电平状态,偶尔蹦出一个高电平或低电平来。
有谁知道是怎么回事吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
没有接外设,就是用作单纯的GPIO。
这个“(void)GPIOA->BSRR;”的作用是仅仅读一下GPIOA的寄存器,但不做任何处理。就像USART口清除接收中断一样,读一下USARTx->SR,形式就是(void)USARTx->SR;
在这里,如果不读一下GPIO的寄存器,它的输出好像还没来得及完全开通IO口的上下MOS管就又关闭了,导致其波形在1.5V左右的电平上下波动。但如果读一下,就能完全打开上下MOS管,从而输出正常的高低电平。
大侠,你能达到100MHz吗?
有别的什么设置,或者硬件上有什么要求我没达到吗?
一周热门 更多>