私はstm32f407vgに少しプロジェクト(c)を開発していますの残りとでUARTのチュートリアル次へ輸出プロトタイプ:STM32 C、プロジェクト
http://letanphuc.net/2015/09/stm32f0-uart-tutorial-5/#comment-346
私の問題は、関数のプロトタイプである:
/* Includes ——————————————————————*/
#include “usart.h”
#include “gpio.h”
/* Private function prototypes ———————————————–*/
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to ‘Yes’) calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 100);
return ch;
}
/* USER CODE END PFP */
UART_HandleTypeDef huart1;
/* USART1 init function */
void MX_USART1_UART_Init(void)
{
…
..
..
私はusart.hで宣言しなければならないので、printf()を使ってプロジェクトの残りの部分を使用できますか?
ありがとうございました。
EDIT:2017年1月20日に応答ギヨーム・ミシェル
私はusart.cでusart.h
#ifndef __usart_H
#define __usart_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"
#include "globals.h"
extern UART_HandleTypeDef huart1;
/* **********************************************
*
* **********************************************/
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
とPUTCHAR_PROTOTYPEに入れている:
/* Includes ------------------------------------------------------------------*/
#include "usart.h"
#include "gpio.h"
#include "string.h"
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the USART */
HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 100);
return ch;
}
/* USER CODE END PFP */
//UART_HandleTypeDef huart1;
/* USART1 init function */
void MX_USART1_UART_Init(void){
..
..
}
そして、 main.c内:
/* Includes ------------------------------------------------------------------*/
#include "globals.h"
#include "stm32f4xx_hal.h"
#include "syscfg.h"
#include "can.h"
#include "usart.h"
#include "gpio.h"
#include "kernel.h"
#include <stdio.h>
int main(void){
SysIniCfg();
printf("Hola");
while (1){
//kernelMotor();
HAL_GPIO_TogglePin(LED_G_GPIO_Port,LED_G_Pin);
}
}
私はコードの2つのセクションを置くために他の場所を試しましたが、これは唯一の警告またはエラーを取得しません
私は応答としてメインポストを編集しました。ブリーフィング:私はusart.hのコードとusart.cの宣言を入れました。私はエラーも警告もなくビルドできましたが、何も印刷しません。 – taquionbcn
私はあなたの 'SysIniCfg'で' MX_USART1_UART_Init'を呼び出すと思います。チュートリアルの第3節では、sprintfを使用してデータを送信する2番目の方法を示します。これを試して、それが動作するかどうかを確認できますか?それがうまくいくならば、何も出力しない理由を理解するために 'printf'関数に入る必要があります。 –
こんにちはギョーム、はい、sprintfが動作します – taquionbcn