1*bfc39f3eSMatthias Ringwald // 2*bfc39f3eSMatthias Ringwald // Minimal support for printf to USART 3*bfc39f3eSMatthias Ringwald // - current version is just blocking 4*bfc39f3eSMatthias Ringwald 5*bfc39f3eSMatthias Ringwald #include "app.h" 6*bfc39f3eSMatthias Ringwald #include "system_config.h" 7*bfc39f3eSMatthias Ringwald #include "peripheral/usart/plib_usart.h" 8*bfc39f3eSMatthias Ringwald #include "system/clk/sys_clk.h" 9*bfc39f3eSMatthias Ringwald #include "system/ports/sys_ports.h" 10*bfc39f3eSMatthias Ringwald 11*bfc39f3eSMatthias Ringwald /// Debug Output /// 12*bfc39f3eSMatthias Ringwald 13*bfc39f3eSMatthias Ringwald // called by printf _mon_putc(char c)14*bfc39f3eSMatthias Ringwaldvoid _mon_putc (char c) 15*bfc39f3eSMatthias Ringwald { 16*bfc39f3eSMatthias Ringwald while (!PLIB_USART_TransmitterIsEmpty(APP_DEBUG_USART_ID)); 17*bfc39f3eSMatthias Ringwald PLIB_USART_TransmitterByteSend(APP_DEBUG_USART_ID, c);; 18*bfc39f3eSMatthias Ringwald } 19*bfc39f3eSMatthias Ringwald APP_Debug_Initialize(void)20*bfc39f3eSMatthias Ringwaldvoid APP_Debug_Initialize(void){ 21*bfc39f3eSMatthias Ringwald 22*bfc39f3eSMatthias Ringwald // PPS Output Mapping: 23*bfc39f3eSMatthias Ringwald PLIB_PORTS_RemapOutput(PORTS_ID_0, OUTPUT_FUNC_U1TX, OUTPUT_PIN_RPD3 ); 24*bfc39f3eSMatthias Ringwald 25*bfc39f3eSMatthias Ringwald /* Initialize USART */ 26*bfc39f3eSMatthias Ringwald PLIB_USART_BaudRateSet(APP_DEBUG_USART_ID, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), APP_DEBUG_USART_BAUD); 27*bfc39f3eSMatthias Ringwald PLIB_USART_HandshakeModeSelect(APP_DEBUG_USART_ID, USART_HANDSHAKE_MODE_FLOW_CONTROL); 28*bfc39f3eSMatthias Ringwald PLIB_USART_OperationModeSelect(APP_DEBUG_USART_ID, USART_ENABLE_TX_RX_USED); 29*bfc39f3eSMatthias Ringwald PLIB_USART_LineControlModeSelect(APP_DEBUG_USART_ID, USART_8N1); 30*bfc39f3eSMatthias Ringwald PLIB_USART_TransmitterEnable(APP_DEBUG_USART_ID); 31*bfc39f3eSMatthias Ringwald 32*bfc39f3eSMatthias Ringwald PLIB_USART_Enable(APP_DEBUG_USART_ID); 33*bfc39f3eSMatthias Ringwald }