rewrite C library printf function to USART0
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/main.c
									
									
									
									
									
								
							@@ -34,15 +34,20 @@ int main(void)
 | 
				
			|||||||
    delay_ms(5000);
 | 
					    delay_ms(5000);
 | 
				
			||||||
    bldc_enable_set(SET);
 | 
					    bldc_enable_set(SET);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    printf("system start!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while(1){
 | 
					    while(1){
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* retarget the C library printf function to the USART */
 | 
					/* retarget the C library printf function to the USART */
 | 
				
			||||||
int fputc(int ch, FILE *f)
 | 
					int _write (int fd, char *pBuffer, int size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    usart_data_transmit(USART0, (uint8_t)ch);
 | 
					    for (int i = 0; i < size; i++)
 | 
				
			||||||
    while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
 | 
					    {
 | 
				
			||||||
    return ch;
 | 
					        usart_data_transmit(USART0, (uint8_t)pBuffer[i]);
 | 
				
			||||||
 | 
					        while(RESET == usart_flag_get(USART0, USART_FLAG_TBE));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user