예제 #1
0
void TM_SWO_Init(void) {
	/* Enable SWO output */
	DBGMCU->CR = 0x00000020;
	
	/* Link output function for output stream functionality */
	TM_STDIO_SetOutputFunction(&TM_SWO_File, TM_SWO_fputc);
}
예제 #2
0
파일: main.c 프로젝트: Mars55/stm32f429
int main(void) {
	char str[100];
	
	/* Initialize system */
	SystemInit();

	/* Initialize delay */
	TM_DELAY_Init();
	
	/* Initialize USART1, TX = PB6, RX = PB7, 115200 bauds */
	TM_USART_Init(USART1, TM_USART_PinsPack_2, 115200);
	
	/* Initialize USART2, TX = PD5, RX = PD6, 115200 bauds*/
	TM_USART_Init(USART2, TM_USART_PinsPack_2, 115200);
	
	/* Initialize USART6, TX = PC6, RX = PC7, 115200 bauds */
	TM_USART_Init(USART6, TM_USART_PinsPack_1, 115200);
	
	/* Add output function for USART2_Stream */
	TM_STDIO_SetOutputFunction(&USART2_Stream, USART2_Stream_OutputFunction);
	
	/* Add input function for USART2_Stream */
	TM_STDIO_SetInputFunction(&USART2_Stream, USART2_Stream_InputFunction);
	
	/* Add output function for USART6_Stream */
	TM_STDIO_SetOutputFunction(&USART6_Stream, USART6_Stream_OutputFunction);
	
	/* Add input function for USART6_Stream */
	TM_STDIO_SetInputFunction(&USART6_Stream, USART6_Stream_InputFunction);
	
	/* Print something on USART1 */
	printf("Hello USART1 user\n");
	
	/* Print something on USART2 */
	fprintf(&USART2_Stream, "Hello USART2 user\n");
	
	/* Print something on USART6 */
	fprintf(&USART6_Stream, "Hello USART6 user\n");
	
	while (1) {
		/* If data are available on stream */
		
		/* Check data on standard header, USART1 */
		/* stdin or standard input */
		if (fgets(str, 100, stdin) != NULL) {
			/* Send data back */
			
			/* Statement below is the same as of use printf function */
			fprintf(stdout, (char *)str);
		}
		
		/* Check data on USART2 stream */
		if (fgets(str, 100, &USART2_Stream) != NULL) {
			/* Send data back */
			
			/* Send data to USART2 stream */
			fprintf(&USART2_Stream, (char *)str);
		}
		
		/* Check data on USART6 stream */
		if (fgets(str, 100, &USART6_Stream) != NULL) {
			/* Send data back */
			
			/* Send data to USART2 stream */
			fprintf(&USART6_Stream, (char *)str);
		}
		
		/* Some delay */
		/* If you call your gets too often, then it can happen that USART characters are not in buffer yet */
		/* and function will not do as it should */
		Delayms(1000);
	}
}