本节测试NUCLEO-F412ZG的GPIO功能,通过下载固件库中的代码GPIO范例,可以看到流水灯闪烁,对于GPIO操作主要是先使能GPIO的时钟,再初始化GPIO,配置GPIO模式,最后设置GPIO输出高低还是读取IO的数据,下面给对应的程序做一下解释。
int main(void)
{
/* This sample code shows how to use GPIO HAL API to toggle LED1 and LED3 IOs
in an infinite loop. */
/* STM32F4xx HAL library initialization:
- Configure the Flash prefetch
- 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();//初始化HAL库
/* Configure the system clock to 100 MHz */
SystemClock_Config();//配置系统时钟为100MHz
/* -1- Enable GPIO Clock (to be able to program the configuration registers) */
LED1_GPIO_CLK_ENABLE();//使能控制LED1 GPIO时钟
LED2_GPIO_CLK_ENABLE();//使能控制LED2 GPIO时钟
LED3_GPIO_CLK_ENABLE();//使能控制LED2 GPIO时钟