2017-01-19 13 views
0

私は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つのセクションを置くために他の場所を試しましたが、これは唯一の警告またはエラーを取得しません

答えて

0

私は確かにキャッチがあると確信している、私はあなたが下のコードをあなたのuart.hに貼り付けて貼り付けるとうまくいくと思います。

#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__ */ 

どこでもあなたのプロジェクトにNEWLIBのlibcのを使用している場合は、main.cの(あなただけint __io_putchar(int ch)にプロジェクト内の任意の場所を実装する必要があります(STM32Cubeが発生した)printf

+0

私は応答としてメインポストを編集しました。ブリーフィング:私はusart.hのコードとusart.cの宣言を入れました。私はエラーも警告もなくビルドできましたが、何も印刷しません。 – taquionbcn

+0

私はあなたの 'SysIniCfg'で' MX_USART1_UART_Init'を呼び出すと思います。チュートリアルの第3節では、sprintfを使用してデータを送信する2番目の方法を示します。これを試して、それが動作するかどうかを確認できますか?それがうまくいくならば、何も出力しない理由を理解するために 'printf'関数に入る必要があります。 –

+0

こんにちはギョーム、はい、sprintfが動作します – taquionbcn

0

を呼び出すuart.hを含めることを忘れないでください。このインプリメンテーションは、(printfによる)標準出力に文字を出力するために使用されます。

注意:extern int __io_putchar(int ch) __attribute__((weak));はsyscalls.cに弱くリンクされています。

コンパイル時には関数のプロトタイプのみが使用され、プロジェクトのリンク時にはユーザー定義関数が使用されます。

(あなたのプロジェクト全体では、uart.hを含む)はすてきな解決策ではありません。残りのNewlibファイルが含まれていることを確認してください。

関連する問題