1
0

PIC32MZ-serial.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. void _mon_putc(char c);
  2. #define BAUD_GEN(sysclk, baud) ((sysclk / (16 * baud)) - 1)
  3. #ifdef MICROCHIP_PIC32
  4. #if defined (__32MZ2048ECH144__) || defined(__32MZ2048ECM144__) || defined(__32MZ2048EFM144__)
  5. /* Code generated from Harmony example then exported using Window -> PIC32 Memory View -> Configuration Bits into system_config.h */
  6. #define SYS_CLK_FREQ 200000000ul
  7. #define SYS_CLK_BUS_PERIPHERAL_2 100000000ul
  8. /* PIC32MZ2048EFM144 Configuration Bit Settings */
  9. /*** DEVCFG0 ***/
  10. #pragma config DEBUG = OFF
  11. #pragma config JTAGEN = OFF
  12. #pragma config ICESEL = ICS_PGx2
  13. #pragma config TRCEN = OFF
  14. #pragma config BOOTISA = MIPS32
  15. #pragma config FECCCON = OFF_UNLOCKED
  16. #pragma config FSLEEP = OFF
  17. #pragma config DBGPER = PG_ALL
  18. #pragma config SMCLR = MCLR_NORM
  19. #pragma config SOSCGAIN = GAIN_2X
  20. #pragma config SOSCBOOST = ON
  21. #pragma config POSCGAIN = GAIN_2X
  22. #pragma config POSCBOOST = ON
  23. #pragma config EJTAGBEN = NORMAL
  24. #pragma config CP = OFF
  25. /*** DEVCFG1 ***/
  26. #pragma config FNOSC = SPLL
  27. #pragma config DMTINTV = WIN_127_128
  28. #pragma config FSOSCEN = OFF
  29. #pragma config IESO = OFF
  30. #pragma config POSCMOD = EC
  31. #pragma config OSCIOFNC = OFF
  32. #pragma config FCKSM = CSECME
  33. #pragma config WDTPS = PS1048576
  34. #pragma config WDTSPGM = STOP
  35. #pragma config FWDTEN = OFF
  36. #pragma config WINDIS = NORMAL
  37. #pragma config FWDTWINSZ = WINSZ_25
  38. #pragma config DMTCNT = DMT31
  39. #pragma config FDMTEN = OFF
  40. /*** DEVCFG2 ***/
  41. #pragma config FPLLIDIV = DIV_3
  42. #pragma config FPLLRNG = RANGE_5_10_MHZ
  43. #pragma config FPLLICLK = PLL_POSC
  44. #pragma config FPLLMULT = MUL_50
  45. #pragma config FPLLODIV = DIV_2
  46. #pragma config UPLLFSEL = FREQ_24MHZ
  47. /*** DEVCFG3 ***/
  48. #pragma config USERID = 0xffff
  49. #pragma config FMIIEN = ON
  50. #pragma config FETHIO = ON
  51. #pragma config PGL1WAY = ON
  52. #pragma config PMDL1WAY = ON
  53. #pragma config IOL1WAY = ON
  54. #pragma config FUSBIDIO = ON
  55. /*** BF1SEQ0 ***/
  56. #pragma config TSEQ = 0x0000
  57. #pragma config CSEQ = 0xffff
  58. /* #pragma config statements should precede project file includes. */
  59. /* Use project enums instead of #define for ON and OFF. */
  60. #include <xc.h>
  61. #endif
  62. #endif
  63. static void init_serial(unsigned int sysClk) {
  64. #ifdef MICROCHIP_PIC32
  65. #if defined (__32MZ2048ECH144__) || defined(__32MZ2048ECM144__) || defined(__32MZ2048EFM144__)
  66. /* This is for pin B14 which is connected to the USB to UART connector J11 located under Ethernet connector */
  67. /* Setup UART2 */
  68. #ifdef SYS_CLK_BUS_PERIPHERAL_2
  69. U2BRG = BAUD_GEN(SYS_CLK_BUS_PERIPHERAL_2, 115200);
  70. #else
  71. if (sysClk > 100000000)
  72. sysClk /= 2;
  73. U2BRG = BAUD_GEN(sysClk, 115200);
  74. #endif
  75. ANSELBCLR = 0x4000;
  76. ANSELGCLR = 0x0040;
  77. RPB14R = 0x02;
  78. U2RXR = 0x01;
  79. U2MODE = 0x8000;
  80. U2STA = 0x400;
  81. #endif
  82. #endif
  83. (void)sysClk;
  84. }