测试期间发现PB3不能直接作为普通IO(第二次遇到这种问题,以防忘记,记录下来。。。),需要在使用此引脚之前进行配置:
1、开启GPIOB及AFIO复用时钟
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
2、配置JTAG
__HAL_AFIO_REMAP_SWJ_NOJTAG();
注:该函数的作用,见官方说明:
/**
* @brief Enable the Serial wire JTAG configuration
* @note NOJTAG: JTAG-DP Disabled and SW-DP Enabled
* @retval None
*/
#define __HAL_AFIO_REMAP_SWJ_NOJTAG() AFIO_DBGAFR_CONFIG(AFIO_MAPR_SWJ_CFG_JTAGDISABLE)
3、示例代码
void led_init(void)
{
__HAL_RCC_AFIO_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_AFIO_REMAP_SWJ_NOJTAG();
rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT);
rt_pin_write(LED_PIN, LED_OFF);
rt_thread_t led_thread = rt_thread_create( "led_thread",
led_entry,
RT_NULL,
LED_STACK_SIZE,
LED_PRIORITY,
LED_TIMESLICE);
if(led_thread != RT_NULL) rt_thread_startup(led_thread);
else return ;
}