feat: 移植 lwprintf
This commit is contained in:
11
project/inc/by_debug.h
Normal file
11
project/inc/by_debug.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _BY_DEBUG_H__
|
||||
#define _BY_DEBUG_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include "lwprintf.h"
|
||||
|
||||
#define BY_DEBUG_USART_INDEX (USART1)
|
||||
|
||||
void by_debug_init(void);
|
||||
|
||||
#endif
|
||||
23
project/src/by_debug.c
Normal file
23
project/src/by_debug.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "by_debug.h"
|
||||
|
||||
#include "at32f403a_407.h"
|
||||
#include "lwprintf.h"
|
||||
|
||||
int lwprintf_out(int ch, lwprintf_t *lwp)
|
||||
{
|
||||
|
||||
/* May use printf to output it for test */
|
||||
|
||||
if (ch != '\0') {
|
||||
while (usart_flag_get(BY_DEBUG_USART_INDEX, USART_TDC_FLAG) == RESET)
|
||||
;
|
||||
usart_data_transmit(BY_DEBUG_USART_INDEX, (char)ch);
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
void by_debug_init(void)
|
||||
{
|
||||
lwprintf_init(lwprintf_out);
|
||||
}
|
||||
@@ -26,10 +26,11 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "at32f403a_407_wk_config.h"
|
||||
#include "dwt_delay.h"
|
||||
/* private includes ----------------------------------------------------------*/
|
||||
/* add user code begin private includes */
|
||||
#include "dwt_delay.h"
|
||||
|
||||
#include "by_debug.h"
|
||||
/* add user code end private includes */
|
||||
|
||||
/* private typedef -----------------------------------------------------------*/
|
||||
@@ -126,13 +127,13 @@ int main(void)
|
||||
|
||||
/* add user code begin 2 */
|
||||
DWT_Init();
|
||||
by_debug_init();
|
||||
/* add user code end 2 */
|
||||
// i2c_start_generate(I2C1);
|
||||
// i2c_7bit_address_send(I2C1, 0x68, I2C_DIRECTION_TRANSMIT);
|
||||
|
||||
|
||||
while (1) {
|
||||
/* add user code begin 3 */
|
||||
// usart_data_transmit(USART1, 0xEF);
|
||||
// DWT_Delay(1000000);
|
||||
/* add user code end 3 */
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user