write.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*******************
  2. *
  3. * Copyright 1998-2010 IAR Systems AB.
  4. *
  5. * This is a template implementation of the "__write" function used by
  6. * the standard library. Replace it with a system-specific
  7. * implementation.
  8. *
  9. * The "__write" function should output "size" number of bytes from
  10. * "buffer" in some application-specific way. It should return the
  11. * number of characters written, or _LLIO_ERROR on failure.
  12. *
  13. * If "buffer" is zero then __write should perform flushing of
  14. * internal buffers, if any. In this case "handle" can be -1 to
  15. * indicate that all handles should be flushed.
  16. *
  17. * The template implementation below assumes that the application
  18. * provides the function "MyLowLevelPutchar". It should return the
  19. * character written, or -1 on failure.
  20. *
  21. ********************/
  22. // #include <yfuns.h>
  23. #include "main.h"
  24. #include "cmsis_os.h"
  25. extern UART_HandleTypeDef DEBUG_UART;
  26. /*
  27. * If the __write implementation uses internal buffering, uncomment
  28. * the following line to ensure that we are called with "buffer" as 0
  29. * (i.e. flush) when the application terminates.
  30. */
  31. size_t _write(int handle, const unsigned char * buffer, size_t size) {
  32. if (buffer == 0) {
  33. /*
  34. * This means that we should flush internal buffers. Since we
  35. * don't we just return. (Remember, "handle" == -1 means that all
  36. * handles should be flushed.)
  37. */
  38. return 0;
  39. }
  40. HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)buffer, (uint16_t)size, HAL_MAX_DELAY);
  41. return (int)size;
  42. }