Created
October 7, 2025 13:39
-
-
Save a-sakharov/576a50e1a47e87902071a585067a591b to your computer and use it in GitHub Desktop.
Simple bitbag implementation of tx-only uart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define DEBUG_BITBANG_LOGGING 1 | |
| #if defined(DEBUG_BITBANG_LOGGING) && DEBUG_BITBANG_LOGGING | |
| #define TIME_DELAY_SLOT 0x100 | |
| #define DBGPIN_INIT() {\ | |
| \ | |
| } | |
| #define DBGPIN_LOW() | |
| #define DBGPIN_HIGH() | |
| //functions below doesnt need any porting. everything above should be changed according to platform | |
| static void BitDelay() { | |
| static volatile int i; | |
| for(i=0; i<TIME_DELAY_SLOT; ++i) { | |
| asm(""); | |
| } | |
| } | |
| static void DebugPrepare() { | |
| DBGPIN_INIT(); | |
| //set initial level | |
| DBGPIN_HIGH(); | |
| //wait a bit to setup line | |
| int i; | |
| for (i=0; i<16; ++i) { | |
| BitDelay(); | |
| } | |
| } | |
| static void DebugTransmitByte(unsigned char byte) { | |
| //start bit | |
| DBGPIN_LOW(); | |
| BitDelay(); | |
| //byte | |
| int i; | |
| for(i=0; i<8; ++i) { | |
| if(byte & 1) { | |
| DBGPIN_HIGH(); | |
| } else { | |
| DBGPIN_LOW(); | |
| } | |
| byte >>= 1; | |
| BitDelay(); | |
| } | |
| //stop bit + 3 idle time slot | |
| DBGPIN_HIGH(); | |
| BitDelay(); | |
| BitDelay(); | |
| BitDelay(); | |
| BitDelay(); | |
| } | |
| void DebugTransmitStr(const char *str) { | |
| while(*str) { | |
| DebugTransmitByte(*str++); | |
| } | |
| } | |
| #endif |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple bitbag implementation of tx-only uart. Useful for debuggin MCU systems when no uart available or necessity to debug system without periphery initialization.
You only need to define
DBGPIN_INIT,DBGPIN_LOWandDBGPIN_HIGH. Then callDebugPrepareat start, after that transmission will work. AdjustTIME_DELAY_SLOTto comply with any standart baudrate (value highly depends on your system) or use logic analyzer to decode arbitrary baudrate.