My Project
Loading...
Searching...
No Matches
PIC32MZ-serial.h
1void _mon_putc(char c);
2
3#define BAUD_GEN(sysclk, baud) ((sysclk / (16 * baud)) - 1)
4
5#ifdef MICROCHIP_PIC32
6#if defined (__32MZ2048ECH144__) || defined(__32MZ2048ECM144__) || defined(__32MZ2048EFM144__)
7 /* Code generated from Harmony example then exported using Window -> PIC32 Memory View -> Configuration Bits into system_config.h */
8 #define SYS_CLK_FREQ 200000000ul
9 #define SYS_CLK_BUS_PERIPHERAL_2 100000000ul
10
11 // DEVCFG3
12 #pragma config FMIIEN = ON // Ethernet RMII/MII Enable (MII Enabled)
13 #pragma config FETHIO = ON // Ethernet I/O Pin Select (Default Ethernet I/O)
14 #pragma config PGL1WAY = ON // Permission Group Lock One Way Configuration (Allow only one reconfiguration)
15 #pragma config PMDL1WAY = ON // Peripheral Module Disable Configuration (Allow only one reconfiguration)
16 #pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow only one reconfiguration)
17 #pragma config FUSBIDIO = ON // USB USBID Selection (Controlled by the USB Module)
18
19 // DEVCFG2
20 #pragma config FPLLIDIV = DIV_1 // System PLL Input Divider (1x Divider)
21 #pragma config FPLLRNG = RANGE_5_10_MHZ // System PLL Input Range (5-10 MHz Input)
22 #pragma config FPLLICLK = PLL_FRC // System PLL Input Clock Selection (FRC is input to the System PLL)
23 #pragma config FPLLMULT = MUL_50 // System PLL Multiplier (PLL Multiply by 50)
24 #pragma config FPLLODIV = DIV_2 // System PLL Output Clock Divider (2x Divider)
25 #pragma config UPLLFSEL = FREQ_24MHZ // USB PLL Input Frequency Selection (USB PLL input is 24 MHz)
26
27 // DEVCFG1
28 #pragma config FNOSC = SPLL // Oscillator Selection Bits (System PLL)
29 #pragma config DMTINTV = WIN_127_128 // DMT Count Window Interval (Window/Interval value is 127/128 counter value)
30 #pragma config FSOSCEN = OFF // Secondary Oscillator Enable (Disable SOSC)
31 #pragma config IESO = OFF // Internal/External Switch Over (Disabled)
32 #pragma config POSCMOD = OFF // Primary Oscillator Configuration (Primary osc disabled)
33 #pragma config OSCIOFNC = OFF // CLKO Output Signal Active on the OSCO Pin (Disabled)
34 #pragma config FCKSM = CSECME // Clock Switching and Monitor Selection (Clock Switch Enabled, FSCM Enabled)
35 #pragma config WDTPS = PS1048576 // Watchdog Timer Postscaler (1:1048576)
36 #pragma config WDTSPGM = STOP // Watchdog Timer Stop During Flash Programming (WDT stops during Flash programming)
37 #pragma config WINDIS = NORMAL // Watchdog Timer Window Mode (Watchdog Timer is in non-Window mode)
38 #pragma config FWDTEN = OFF // Watchdog Timer Enable (WDT Disabled)
39 #pragma config FWDTWINSZ = WINSZ_25 // Watchdog Timer Window Size (Window size is 25%)
40 #pragma config DMTCNT = DMT31 // Deadman Timer Count Selection (2^31 (2147483648))
41 #pragma config FDMTEN = OFF // Deadman Timer Enable (Deadman Timer is disabled)
42
43 // DEVCFG0
44 #pragma config ICESEL = ICS_PGx2 // ICE/ICD Comm Channel Select (Communicate on PGEC2/PGED2)
45
46 // DEVCP0
47 #pragma config CP = OFF // Code Protect (Protection Disabled)
48
49 #include <xc.h>
50#endif
51#endif
52
53static void init_serial(unsigned int sysClk) {
54#ifdef MICROCHIP_PIC32
55#if defined (__32MZ2048ECH144__) || defined(__32MZ2048ECM144__) || defined(__32MZ2048EFM144__)
56 /* This is for pin B14 which is connected to the USB to UART connector J11 located under Ethernet connector */
57
58 /* Setup UART2 */
59#ifdef SYS_CLK_BUS_PERIPHERAL_2
60 U2BRG = BAUD_GEN(SYS_CLK_BUS_PERIPHERAL_2, 115200);
61#else
62 if (sysClk > 100000000)
63 sysClk /= 2;
64 U2BRG = BAUD_GEN(sysClk, 115200);
65#endif
66 ANSELBCLR = 0x4000;
67 ANSELGCLR = 0x0040;
68 RPB14R = 0x02;
69 U2RXR = 0x01;
70 U2MODE = 0x8000;
71 U2STA = 0x400;
72#endif
73#endif
74 (void)sysClk;
75}