usart.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /********************************* (C) РОТЕК ***********************************
  2. * @module usart
  3. * @file usart.c
  4. * @version 1.0.0
  5. * @date XX.XX.XXXX
  6. * $brief Template
  7. *******************************************************************************
  8. * @history Version Author Comment
  9. * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
  10. *******************************************************************************
  11. */
  12. #include "stm32f4xx.h"
  13. #include "usart.h"
  14. #include "tinystdio.h"
  15. #ifdef __GNUC__
  16. #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
  17. #else
  18. #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
  19. #endif
  20. PUTCHAR_PROTOTYPE
  21. {
  22. //ITM_SendChar((u8) ch);
  23. return ch;
  24. }
  25. void putchar_(uint8_t c) {
  26. while (!(USER_USART->SR & USART_FLAG_TXE));
  27. USER_USART->DR = (uint16_t)c;
  28. }
  29. void putc_(void* p, char c) {
  30. (void)p;
  31. putchar_(c);
  32. }
  33. /**
  34. * @brief
  35. * @retval
  36. */
  37. void InitUSART( void) {
  38. USART_InitTypeDef USART_InitStructure;
  39. RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
  40. USART_InitStructure.USART_BaudRate = 115200;
  41. USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  42. USART_InitStructure.USART_StopBits = USART_StopBits_1;
  43. USART_InitStructure.USART_Parity = USART_Parity_No;
  44. USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  45. USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
  46. USART_Init(USER_USART, &USART_InitStructure);
  47. USART_Cmd(USER_USART, ENABLE);
  48. USART_ITConfig(USER_USART, USART_IT_RXNE, DISABLE);
  49. USART_ITConfig(USER_USART, USART_IT_TXE, DISABLE);
  50. init_printf(NULL, putc_);
  51. }
  52. /********************************* (C) РОТЕК **********************************/