调试日志

SDK调试日志打开需要在编译是开启调试开关,开关变量为UART_DEBUG_LOG,在文件lora-sdk\system\debug.h中定义,打开debug配置如下:

#define UART_DEBUG_LOG   /* 关闭调试请注释掉定义 */

系统接口printf输出的日志底层会调用系统接口,驱动UART模块会接管系统接口的实现,UART驱动模块需要适配提供调试接口。

Printf接管实现如下,在文件example\stm32\NucleoL073\board\board.c

#if !defined ( __CC_ARM )

/*
 * Function to be used by stdout for printf etc
 */
int _write( int fd, const void *buf, size_t count )
{
    while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )count ) != 0 ){ };
    return count;
}

/*
 * Function to be used by stdin for scanf etc
 */
int _read( int fd, const void *buf, size_t count )
{
    size_t bytesRead = 0;
    while( UartGetBuffer( &Uart2, ( uint8_t* )buf, count, ( uint16_t* )&bytesRead ) != 0 ){ };
    // Echo back the character
    while( UartPutBuffer( &Uart2, ( uint8_t* )buf, ( uint16_t )bytesRead ) != 0 ){ };
    return bytesRead;
}

#else

// Keil compiler
int fputc( int c, FILE *stream )
{
    while( UartPutChar( &Uart2, ( uint8_t )c ) != 0 );
    return c;
}

int fgetc( FILE *stream )
{
    uint8_t c = 0;
    while( UartGetChar( &Uart2, &c ) != 0 );
    // Echo back the character
    while( UartPutChar( &Uart2, c ) != 0 );
    return ( int )c;
}

#endif
© H3C IoT all right reserved,powered by Gitbook更新时间: 2023-11-08 11:19:35

results matching ""

    No results matching ""