main.c 可以添加一句打印提示
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
if(IS_ENGINEERING_BOOT_MODE())
{
/* Configure the system clock */
SystemClock_Config();
}
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_UART4_Init();
/* USER CODE BEGIN 2 */
printf("test for all...\n");
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
gpio.c 添加
/* USER CODE BEGIN 2 */
void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin)
{
switch (GPIO_Pin)
{
case GPIO_PIN_7:
HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_10);
printf("led2 toggle...\n");
break;
case GPIO_PIN_8:
HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_8);
printf("led3 toggle...\n");
break;
case GPIO_PIN_9:
HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_10);
printf("led1 toggle...\n");
break;
}
}
void HAL_GPIO_EXTI_Rising_Callback(uint16_t GPIO_Pin)
{
switch (GPIO_Pin)
{
case GPIO_PIN_5:
HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_10);
break;
case GPIO_PIN_12:
HAL_GPIO_TogglePin(GPIOF,GPIO_PIN_10);
break;
case GPIO_PIN_15:
HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_8);
break;
}
}
/* USER CODE END 2 */
usart.c 添加
/* USER CODE BEGIN 0 */
int fputc(int ch , FILE *STREAM)
{
while(!(huart4.Instance->ISR &(0x1<<7)));
huart4.Instance->TDR = ch;
if(ch == '\n')
{
while(!(huart4.Instance->ISR &(0x1<<7)));
huart4.Instance->TDR = '\r';
}
return ch;
}
/* USER CODE END 0 */
现象: