Skip to content

Commit

Permalink
- replaced debug_printf calls with hal_printf calls for STM32F4 ether…
Browse files Browse the repository at this point in the history
…net driver and WireProtocol.cpp to keep clarity and consistency as network could be used for the Debug transport and DebugTextPort.

- restored DEBUG_TRACE so it uses hal_printf() instead of debug_printf so that it is useful for tracing issues even when the debug port isn't fully functional.
  • Loading branch information
smaillet-ms committed Jul 1, 2015
1 parent 8e1d7be commit 6e476df
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void eth_resumeDmaReception()
void eth_dmaInterruptHandler()
{
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf("DMA Int:");
hal_printf("DMA Int:");
#endif

// Normal interrupt summary
Expand All @@ -239,7 +239,7 @@ void eth_dmaInterruptHandler()
{
// Ethernet frame received
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" RS");
hal_printf(" RS");
#endif

// Clear interrupt flag
Expand All @@ -257,7 +257,7 @@ void eth_dmaInterruptHandler()
{
// Ethernet frame sent
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" TS");
hal_printf(" TS");
#endif

// Clear interrupt flag
Expand All @@ -269,7 +269,7 @@ void eth_dmaInterruptHandler()
{
// Transmit buffer unavailable
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" TBUS");
hal_printf(" TBUS");
#endif

// Clear interrupt flag, transmition is resumed after descriptors have been prepared
Expand All @@ -281,7 +281,7 @@ void eth_dmaInterruptHandler()
{
// Early receive
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" ERS");
hal_printf(" ERS");
#endif

// Clear interrupt flag. Also cleared automatically by RI
Expand All @@ -301,7 +301,7 @@ void eth_dmaInterruptHandler()
{
// Fatal bus error
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" FBES");
hal_printf(" FBES");
#endif

// Clear interrupt flag
Expand All @@ -313,7 +313,7 @@ void eth_dmaInterruptHandler()
{
// Transmit process stopped
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" TPSS");
hal_printf(" TPSS");
#endif

// Clear interrupt flag
Expand All @@ -325,7 +325,7 @@ void eth_dmaInterruptHandler()
{
// Transmit jabber timeout
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" TJTS");
hal_printf(" TJTS");
#endif

// Clear interrupt flag
Expand All @@ -337,7 +337,7 @@ void eth_dmaInterruptHandler()
{
// Receive overflow
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" ROS");
hal_printf(" ROS");
#endif

// Clear interrupt flag
Expand All @@ -349,7 +349,7 @@ void eth_dmaInterruptHandler()
{
// Transmit underflow
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" TUS");
hal_printf(" TUS");
#endif

// Clear interrupt flag
Expand All @@ -361,7 +361,7 @@ void eth_dmaInterruptHandler()
{
// Receive buffer unavailable
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" RBUS");
hal_printf(" RBUS");
#endif

// Clear interrupt flag
Expand All @@ -373,7 +373,7 @@ void eth_dmaInterruptHandler()
{
// Receive process stopped
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" RPSS");
hal_printf(" RPSS");
#endif

// Clear interrupt flag
Expand All @@ -385,7 +385,7 @@ void eth_dmaInterruptHandler()
{
// Receive watchdog timeout
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" RWTS");
hal_printf(" RWTS");
#endif

// Clear interrupt flag
Expand All @@ -397,7 +397,7 @@ void eth_dmaInterruptHandler()
{
// Early transmit interrupt
#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf(" ETS");
hal_printf(" ETS");
#endif

// Clear interrupt flag
Expand All @@ -410,7 +410,7 @@ void eth_dmaInterruptHandler()
}

#if defined (_DEBUG) && DEBUG_DMA_INT
debug_printf("\r\n");
hal_printf("\r\n");
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BOOL STM32F4_ETH_LWIP_open(Netif_t *const pNetif)
if ( !initEthernet(pNetif) )
{
#ifdef _DEBUG_TRACE
debug_printf("Ethernet driver cannot be opened\r\n");
hal_printf("Ethernet driver cannot be opened\r\n");
#endif

// Set flag as closed and abort
Expand All @@ -107,7 +107,7 @@ BOOL STM32F4_ETH_LWIP_open(Netif_t *const pNetif)
s_isDriverOpened = TRUE;

#ifdef _DEBUG_TRACE
debug_printf("Ethernet driver opened\r\n");
hal_printf("Ethernet driver opened\r\n");
#endif

return TRUE;
Expand Down Expand Up @@ -135,7 +135,7 @@ void STM32F4_ETH_LWIP_close(const BOOL disableClocks)
}

#ifdef _DEBUG_TRACE
debug_printf("Ethernet driver closed\r\n");
hal_printf("Ethernet driver closed\r\n");
#endif
}

Expand Down Expand Up @@ -177,7 +177,7 @@ static uint32_t processFrame(Netif_t *const pNetif)
if (frameLength == 0)
{
#ifdef _DEBUG_TRACE
debug_printf("%s: erroneous frame\r\n", __func__);
hal_printf("%s: erroneous frame\r\n", __func__);
#endif

return releaseRxDescUntilNextFrame();
Expand All @@ -188,7 +188,7 @@ static uint32_t processFrame(Netif_t *const pNetif)
if (!pbuf)
{
#ifdef _DEBUG_TRACE
debug_printf("%s: pbuf_alloc failed, discard current frame\r\n", __func__);
hal_printf("%s: pbuf_alloc failed, discard current frame\r\n", __func__);
#endif

return releaseFrame();
Expand Down Expand Up @@ -218,7 +218,7 @@ static uint32_t copyFrameToPbuf(Pbuf_t *pbuf)
while (!eth_isRxDescOwnedByDma() && !isLastDescProcessed)
{
#if DEBUG_RX_DESC
debug_printf("----- Before processing RX -----\r\n");
hal_printf("----- Before processing RX -----\r\n");
eth_displayRxDescStatus();
#endif

Expand All @@ -237,7 +237,7 @@ static uint32_t copyFrameToPbuf(Pbuf_t *pbuf)
nRxDesc++;

#if DEBUG_RX_DESC
debug_printf("----- After processing RX -----\r\n");
hal_printf("----- After processing RX -----\r\n");
eth_displayRxDescStatus();
#endif
}
Expand Down Expand Up @@ -400,7 +400,7 @@ static BOOL waitForTxDescriptor(uint32_t timeout)
if (nWait == timeout)
{
//#ifdef _DEBUG
//debug_printf("%s: TX descriptor owned by DMA\r\n", __func__);
//hal_printf("%s: TX descriptor owned by DMA\r\n", __func__);
//#endif

return FALSE;
Expand All @@ -426,7 +426,7 @@ static BOOL copyFrameFromPbuf(const Pbuf_t *pbuf)
if (frameLength > TX_BUFFER_LENGTH)
{
#ifdef _DEBUG_TRACE
debug_printf("%s: Frame larger than TX buffer (%d)\r\n", __func__, frameLength);
hal_printf("%s: Frame larger than TX buffer (%d)\r\n", __func__, frameLength);
#endif

return FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void findPhyAddr()
if ((value == PHY_KENDIN_OUI_ID1) || (value == PHY_ST802RT1X_OUI_ID1))
{
rc = phyAddress;
debug_printf( "Valid PHY Found: %x (%x)\r\n", rc, value);
hal_printf( "Valid PHY Found: %x (%x)\r\n", rc, value);
g_foundPhyAddress = TRUE;
g_phyAddress = phyAddress;

Expand Down Expand Up @@ -189,7 +189,7 @@ EthMode eth_enableAutoNegotiation()
return ETHMODE_FAIL;

#if (DEBUG_TRACE)
debug_printf("PHY CR status 0x%x \n",status);
hal_printf("PHY CR status 0x%x \n",status);
#endif

// Start Auto Negotiation
Expand All @@ -210,13 +210,13 @@ EthMode eth_enableAutoNegotiation()
// Check auto negotiation completed
if ((status & PHY_SR_ANEGC) != PHY_SR_ANEGC)
{
debug_printf("autonegotiate failed. Status: %x\n", status);
hal_printf("autonegotiate failed. Status: %x\n", status);
return ETHMODE_FAIL;

}

#if (DEBUG_TRACE)
debug_printf("Autonegotiate Complete SR:%x\n", status);
hal_printf("Autonegotiate Complete SR:%x\n", status);
#endif

#if STM32F4_ETH_PHY_MII
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void eth_initRxDescriptors()
}

#if DEBUG_RX_DESC
debug_printf("----- After init RX desc -----\r\n");
hal_printf("----- After init RX desc -----\r\n");
eth_displayRxDescStatus();
#endif

Expand Down Expand Up @@ -282,7 +282,7 @@ void eth_displayRxDescStatus()

for (uint32_t i = 0; i < N_RX_DESC; i++)
{
debug_printf("%d: 0x%08x %s\r\n", i, s_rxDescriptor[i].rdes0,
hal_printf("%d: 0x%08x %s\r\n", i, s_rxDescriptor[i].rdes0,
s_pRxDesc == &s_rxDescriptor[i] ? "<===" : "");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void eth_initTxDescriptor()
}

#if DEBUG_TX_DESC
debug_printf("----- After init TX desc -----\r\n");
hal_printf("----- After init TX desc -----\r\n");
eth_displayTxDescStatus();
#endif

Expand Down Expand Up @@ -220,9 +220,9 @@ void eth_displayTxDescStatus()

for (uint32_t i = 0; i < N_TX_DESC; i++)
{
debug_printf("tdes0: 0x%08x %s\r\n", s_txDescriptor[i].tdes0,
hal_printf("tdes0: 0x%08x %s\r\n", s_txDescriptor[i].tdes0,
s_pTxDesc == &s_txDescriptor[i] ? "<===" : "");
debug_printf("tdes1: 0x%08x\r\n", s_txDescriptor[i].tdes1);
hal_printf("tdes1: 0x%08x\r\n", s_txDescriptor[i].tdes1);
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ typedef intptr_t mem_ptr_t;
#define PACK_STRUCT_END

/* Plaform specific diagnostic output */
extern void debug_printf(const char *format, ...);
extern void hal_printf(const char *format, ...);

#define LWIP_PLATFORM_DIAG(x) do {debug_printf x;} while(0)

#ifndef LWIP_NOASSERT
#define LWIP_PLATFORM_ASSERT(x) \
do {debug_printf("LWIP Assertion \"%s\" failed at line %d in %s\n", \
do {hal_printf("LWIP Assertion \"%s\" failed at line %d in %s\n", \
x, __LINE__, __FILE__); } while(0)
#else
#define LWIP_PLATFORM_ASSERT(x)
Expand Down
29 changes: 18 additions & 11 deletions DeviceCode/include/tinyhal.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,17 @@ struct HAL_SYSTEM_CONFIG

COM_HANDLE DebuggerPorts[c_MaxDebuggers];
COM_HANDLE MessagingPorts[c_MaxMessaging];

// communication channel for debug messages in the debugger
// which may be VS, MFDEPLOY, etc... Accessed via debug_printf
// in the HAL/PAL and System.Diagnostics.Debug.Print() in managed
// applications
COM_HANDLE DebugTextPort;

UINT32 USART_DefaultBaudRate;
// internal HAL/PAL debug/tracing channel, this is seperate
// to allow tracing messages in the driver that implements
// the transport for the Debugger and DebugTextPort. This
// channel is accessed via hal_printf() in the HAL/PAL
COM_HANDLE stdio;

HAL_SYSTEM_MEMORY_CONFIG RAM1;
Expand Down Expand Up @@ -1449,16 +1456,16 @@ extern const ConfigurationSector g_ConfigurationSector;

#if !defined(BUILD_RTM)

#define DEBUG_TRACE0(t, s) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s) )
#define DEBUG_TRACE1(t, s, p1) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1) )
#define DEBUG_TRACE2(t, s, p1,p2) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2) )
#define DEBUG_TRACE3(t, s, p1,p2,p3) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3) )
#define DEBUG_TRACE4(t, s, p1,p2,p3,p4) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4) )
#define DEBUG_TRACE5(t, s, p1,p2,p3,p4,p5) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4),(p5) )
#define DEBUG_TRACE6(t, s, p1,p2,p3,p4,p5,p6) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6) )
#define DEBUG_TRACE7(t, s, p1,p2,p3,p4,p5,p6,p7) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7) )
#define DEBUG_TRACE8(t, s, p1,p2,p3,p4,p5,p6,p7,p8) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8) )
#define DEBUG_TRACE9(t, s, p1,p2,p3,p4,p5,p6,p7,p8,p9) if(((t) & DEBUG_TRACE) != 0) debug_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8),(p9) )
#define DEBUG_TRACE0(t, s) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s) )
#define DEBUG_TRACE1(t, s, p1) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1) )
#define DEBUG_TRACE2(t, s, p1,p2) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2) )
#define DEBUG_TRACE3(t, s, p1,p2,p3) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3) )
#define DEBUG_TRACE4(t, s, p1,p2,p3,p4) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4) )
#define DEBUG_TRACE5(t, s, p1,p2,p3,p4,p5) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4),(p5) )
#define DEBUG_TRACE6(t, s, p1,p2,p3,p4,p5,p6) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6) )
#define DEBUG_TRACE7(t, s, p1,p2,p3,p4,p5,p6,p7) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7) )
#define DEBUG_TRACE8(t, s, p1,p2,p3,p4,p5,p6,p7,p8) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8) )
#define DEBUG_TRACE9(t, s, p1,p2,p3,p4,p5,p6,p7,p8,p9) if(((t) & DEBUG_TRACE) != 0) hal_printf( (s), (p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8),(p9) )

#else

Expand Down
4 changes: 2 additions & 2 deletions Support/WireProtocol/WireProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////

#if 0
#define TRACE0( msg, ...) debug_printf( msg )
#define TRACE( msg, ...) debug_printf( msg, __VA_ARGS__ )
#define TRACE0( msg, ...) hal_printf( msg )
#define TRACE( msg, ...) hal_printf( msg, __VA_ARGS__ )
#else
#define TRACE0(msg,...)
#define TRACE(msg,...)
Expand Down

0 comments on commit 6e476df

Please sign in to comment.