硬件:秉火(还是*火)的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左右的中间电平状态,偶尔蹦出一个高电平或低电平来。
有谁知道是怎么回事吗?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>