bsp_retarget.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "Includes.h"
  2. #include "stdio.h"
  3. #pragma import(__use_no_semihosting_swi)
  4. #define __DEBUG_OUT_PORT 0 //- 0:uart0 , 1:uart1
  5. void retarget_init(void)
  6. {
  7. #if (__DEBUG_OUT_PORT == 1)
  8. unsigned int val;
  9. //- uart1 clk
  10. *((unsigned int volatile*)0x40000070) = 0x200020;
  11. __read_hw_reg32(CPR_GPIO_FUN_SEL5 , val);
  12. val &= 0xFFFF;
  13. val |= (8<<16)|(7<<24);
  14. __write_hw_reg32(CPR_GPIO_FUN_SEL5 , val);
  15. (*((volatile unsigned *)(0x40000000 + 0x38))) = 0x110018;
  16. (*((volatile unsigned *)( 0x40000000 + 0x3c ))) = 0x480271;
  17. (*((volatile unsigned *)( 0x40011000 + 0x0c ))) = 0x80;
  18. (*((volatile unsigned *)( 0x40011000 + 0x00 ))) = 0x01;
  19. (*((volatile unsigned *)( 0x40011000 + 0x0c ))) = 0x03;
  20. (*((volatile unsigned *)( 0x40011000 + 0x08 ))) = 0xb7;
  21. #else
  22. #define CPR_GPIO_FUN_SEL4 ((volatile unsigned *)(0x40000000 + 0x0d0))
  23. #define UART0_USR ((volatile unsigned *)(0x40010000 + 0x7c))
  24. #define CPR_RSTCTL_SUBRST_SW ((volatile unsigned *)(0x40000000 + 0x104))
  25. #define CPR_CTLAPBCLKEN_GRCTL ((volatile unsigned *)(0x40000000 + 0x070))
  26. #define CPR_UART0_CLK_GRCTL ((volatile unsigned *)(0x40000000 + 0x030))
  27. #define CPR_UART0_CLK_CTL ((volatile unsigned *)(0x40000000 + 0x034))
  28. #define UART0_TCR ((volatile unsigned *)(0x40010000 + 0x0c))
  29. #define UART0_DLL ((volatile unsigned *)(0x40010000 + 0x00))
  30. #define UART0_DLH ((volatile unsigned *)(0x40010000 + 0x04))
  31. #define UART0_FCR ((volatile unsigned *)(0x40010000 + 0x08))
  32. unsigned int val;
  33. __read_hw_reg32(CPR_GPIO_FUN_SEL4 , val);
  34. val &= 0xFFFF;
  35. val |= ((1<<16) | (2<<24));
  36. __write_hw_reg32(CPR_GPIO_FUN_SEL4 , val);
  37. do {
  38. __read_hw_reg32(UART0_USR, val);
  39. }while(val&0x01);
  40. __write_hw_reg32(CPR_RSTCTL_SUBRST_SW , 0x10000);
  41. __write_hw_reg32(CPR_RSTCTL_SUBRST_SW , 0x10001);
  42. __write_hw_reg32(CPR_CTLAPBCLKEN_GRCTL , 0x100010);
  43. __write_hw_reg32(CPR_UART0_CLK_GRCTL, 0x110018);
  44. __write_hw_reg32(CPR_UART0_CLK_CTL, 0x480271);
  45. __write_hw_reg32(UART0_TCR , 0x80);
  46. __write_hw_reg32(UART0_DLL , 0x01);
  47. __write_hw_reg32(UART0_DLH , 0x00);
  48. __write_hw_reg32(UART0_TCR , 0x03);
  49. __write_hw_reg32(UART0_FCR , 0x37);
  50. #endif
  51. printf("\n SYSTEM BUILD TIME: %s %s \n",__DATE__,__TIME__);
  52. }
  53. int sendchar(int c)
  54. {
  55. unsigned int status;
  56. #if (__DEBUG_OUT_PORT == 1)
  57. for(; ;)
  58. {
  59. status = (*((volatile unsigned *)( 0x40011000 + 0x14 )));
  60. status &= 0x20;
  61. if(status == 0x20) break;
  62. }
  63. (*((volatile unsigned *)( 0x40011000 + 0x00 ))) = c;
  64. return (1);
  65. #else
  66. for(; ;)
  67. {
  68. status = (*((volatile unsigned *)( 0x40010000 + 0x14 )));
  69. status &= 0x20;
  70. if(status == 0x20) break;
  71. }
  72. (*((volatile unsigned *)( 0x40010000 + 0x00 ))) = c;
  73. return (1);
  74. #endif
  75. }
  76. struct __FILE { int handle; /* Add whatever you need here */ };
  77. FILE __stdout;
  78. int fputc(int ch, FILE *f) {
  79. return (sendchar(ch));
  80. }
  81. int ferror(FILE *f) {
  82. /* Your implementation of ferror */
  83. return EOF;
  84. }
  85. void _ttywrch(int ch) {
  86. sendchar(ch);
  87. }
  88. void _sys_exit(int return_code) {
  89. label: goto label; /* endless loop */
  90. }