{"id":26742768,"url":"https://github.com/fescron/dbprint","last_synced_at":"2025-06-12T08:36:55.479Z","repository":{"id":209518923,"uuid":"158114653","full_name":"Fescron/dbprint","owner":"Fescron","description":"DeBugPrint - Homebrew minimal low-level println/printf replacement using UART for EFM32.","archived":false,"fork":false,"pushed_at":"2019-12-14T19:01:33.000Z","size":885,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T06:20:40.778Z","etag":null,"topics":["converter","dbprint","debugprint","dramco","efm32","efm32hg","em-usart","emlib","geckoboard","kuleuven","microcontroller","print","printf","println","putty","serial","simplicity-studio","slstk3400a","uart","vcom"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Fescron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-11-18T18:33:43.000Z","updated_at":"2024-07-26T14:26:50.000Z","dependencies_parsed_at":"2023-11-27T19:54:55.522Z","dependency_job_id":"e59a4707-67c9-4bda-9fed-3324b8ebe8c0","html_url":"https://github.com/Fescron/dbprint","commit_stats":null,"previous_names":["fescron/dbprint"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Fescron/dbprint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fescron%2Fdbprint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fescron%2Fdbprint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fescron%2Fdbprint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fescron%2Fdbprint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Fescron","download_url":"https://codeload.github.com/Fescron/dbprint/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Fescron%2Fdbprint/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259431112,"owners_count":22856432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["converter","dbprint","debugprint","dramco","efm32","efm32hg","em-usart","emlib","geckoboard","kuleuven","microcontroller","print","printf","println","putty","serial","simplicity-studio","slstk3400a","uart","vcom"],"created_at":"2025-03-28T06:20:05.375Z","updated_at":"2025-06-12T08:36:55.459Z","avatar_url":"https://github.com/Fescron.png","language":"C","readme":"# dbprint\n\n![License](https://img.shields.io/badge/license-GNU%20GPL%20v3.0-blue.svg)\n![GitHub last commit](https://img.shields.io/github/last-commit/Fescron/dbprint.svg)\n![GitHub Release Date](https://img.shields.io/github/release-date/Fescron/dbprint.svg)\n![GitHub release](https://img.shields.io/github/release/Fescron/dbprint.svg)\n![Target device](https://img.shields.io/badge/target%20device-EFM32HG322F64G-yellow.svg)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Fescron/dbprint.svg)\n\n**DeBugPrint** is a homebrew minimal low-level `println/printf` replacement. It can be used to to print text/values to `UART`without a lot of external libraries. The end goal was to use no exernal libraries (with methods like `itoa`) apart from the ones specific to the microcontroller.\n\n**DeBugPrint** was originally designed for use on the `Silicon Labs Happy Gecko EFM32 board (EFM32HG322 -- TQFP48)` (`SLSTK3400A`) and was developed on `Simplicity Studio v4` on `Ubuntu 19.04`.\n\n\u003cbr/\u003e\n\n- There are a lot of useful yet simple code-examples at https://github.com/SiliconLabs/peripheral_examples\n- Click [**here**](https://fescron.github.io/dbprint/dbprint__documentation_8h.html) to find a lot of **useful information** (general info, info about keywords and datatypes, ...) about the project and C in general.\n- Click [**here**](https://fescron.github.io/dbprint/dbprint_8h.html) to find **detailed information about all available methods**.\n\n\u003cbr/\u003e\n\n## Table of contents\n\n- [dbprint](#dbprint)\n  - [Table of contents](#table-of-contents)\n  - [1 - Installation instructions](#1---installation-instructions)\n    - [1.1 - Add `dbprint` folder to your project](#11---add-dbprint-folder-to-your-project)\n    - [1.2 - Add `em_usart.c` to your project (if not already added)](#12---add-emusartc-to-your-project-if-not-already-added)\n    - [1.3 - Include `debug_dbprint.h` in your project's `main.c` (or another) file](#13---include-debugdbprinth-in-your-projects-mainc-or-another-file)\n    - [1.4 - Start adding dbprint functionality](#14---start-adding-dbprint-functionality)\n    - [1.5 - Clean \u0026 Build](#15---clean--build)\n  - [2 - Enable/disable dbprint using definition in `debug_dbprint.h`](#2---enabledisable-dbprint-using-definition-in-debugdbprinth)\n  - [3 - VCOM](#3---vcom)\n  - [4 - Energy profiler and dbprint](#4---energy-profiler-and-dbprint)\n  - [5 - Methods](#5---methods)\n    - [5.1 - Definitions](#51---definitions)\n    - [5.2 - Usage examples](#52---usage-examples)\n      - [5.2.1 - Basic functions](#521---basic-functions)\n      - [5.2.2 - More advanced functions](#522---more-advanced-functions)\n      - [5.2.3 - Interrupt functionality](#523---interrupt-functionality)\n  - [6 - Alternate locations of pins](#6---alternate-locations-of-pins)\n\n\u003cbr/\u003e\n\n## 1 - Installation instructions\n\n### 1.1 - Add `dbprint` folder to your project\n\n**Copy** the `dbprint` folder containing the header and source files from this repository to your project folder.\n\nOpen the **project settings** using `File \u003e Properties` (or right click on your project in the *Project Explorer* and choose `Properties`).\n\nIn the opened window choose `C/C++ General \u003e Paths and Symbols` on the left.\n\nIn the tab **\"Includes\"**:\n\n1. Click `Add... \u003e Workspace...`\n2. Browse to the **\"dbprint\"** folder in your project folder and press OK. \n3. Check the boxes *\"Add to all languages\"* and *\"Is a workspace path\"* and press OK.\n\n\u003cbr/\u003e\n\n### 1.2 - Add `em_usart.c` to your project (if not already added)\n\nIn any *Simplicity Studio example project* (like **blink**) all of the header files (`.h`) for **`emlib`** are included but the source files (`.c`) are sometimes not. This needs to be done manually:\n\n1. In the **Project Explorer** on the left, rightclick on the **`emlib`** folder under your project and select `New \u003e File from Template`\n2. Click on `Advanced\u003e\u003e`and check *\"Link to file in the file system\"*.\n3. Click `Browse...`, go to `SimplicityStudio_v4/developer/sdks/gecko_sdk_suite/v2.4/platform/emlib/src`, select the the **`em_usart.c`** file and press OK.\n4. Press FINISH.\n\n\u003cbr/\u003e\n\n### 1.3 - Include `debug_dbprint.h` in your project's `main.c` (or another) file\n\n```C\n#include \"debug_dbprint.h\"\n```\n\n\u003cbr/\u003e\n\n### 1.4 - Start adding dbprint functionality\n\nIt's advised to **surround dbprint statements in your code with `IF ... ENDIF`** so they can be enabled/disabled by setting the definition `DEBUG_DBPRINT` in `debug_dbprint.h` to `1` or `0`:\n\n```C\n#if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */\n\ndbprint_INIT(USART1, 4, true, false); /* Initialize dbprint for use with VCOM */\n\ndbprintln(\"Hello world!\"); /* An example of a dbprint statement */\n\n#endif /* DEBUG_DBPRINT */\n```\n\nMore information about this can be found in [\"2 - Enable/disable dbprint using definition in `debug_dbprint.h`\"](#2---enabledisable-dbprint-using-definition-in-debugdbprinth).\n\n\u003cbr/\u003e\n\n### 1.5 - Clean \u0026 Build\n\nPerform a *clean and build* action to fix errors that would occur when the project would just get *build* after the dbprint files are added.\n\n1. Click `Project \u003e Clean...`\n2. Select *\"Clean projects selected below\"* and check the current project.\n3. Check *\"Start a build immediately\"* while *\"Build only the selected projects\"* is selected.\n4. Press OK.\n\n\u003cbr/\u003e\n\n## 2 - Enable/disable dbprint using definition in `debug_dbprint.h`\n\nIn the file `debug_dbprint.h` dbprint UART functionality can be enabled/disabled with the definition `#define DEBUG_DBPRINT`. If it's value is `0`, all dbprint functionality is disabled. This means that the **only header file to include in your projects** for dbprint to work is `#include debug_dbprint.h`\n\nAgain, it's advised to **surround dbprint statements in your code with `IF ... ENDIF`** so they can be enabled/disabled by setting the definition `DEBUG_DBPRINT` in `debug_dbprint.h` to `1` or `0`:\n\n```C\n#if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */\n\ndbprintln(\"Hello world!\"); /* An example of a dbprint statement */\n\n#endif /* DEBUG_DBPRINT */\n```\n\n\u003cbr/\u003e\n\n## 3 - VCOM\n\n When using `dbprint` functionality, the following settings are used and can't be changed without editing the source code:\n\n- `Baudrate = 115200`\n- `8 databits`\n- `1 stopbit`\n- `No parity`\n\n\u003cbr/\u003e\n\nVCOM is an on-board (on the `SLSTK3400A`) **UART to USB converter** alongside the Segger J-Link debugger. It's connected with microcontroller pins `PA0` (RX) and `PF2` (TX). This converter can then be used with [Putty](https://www.putty.org/) or another serial port program.\n\nWhen you want to **debug using VCOM with interrupt functionality disabled**, you can use the following initialization settings:\n\n```C\ndbprint_INIT(USART1, 4, true, false);\n```\n\nSetting the third argument to `true` indicates to the code that `PA9`(`EFM_BC_EN`) should be set high to enable the isolation switch on the PCB of the Happy Gecko to link `PA0` (RX) and `PF2` (TX) to the debugger. **Don't use this pin yourself if you want to make use of the on-board UART to USB converter!**\n\n\u003cbr/\u003e\n\n## 4 - Energy profiler and dbprint\n\nThe Energy profiler in Simplicity Studio seems to use VCOM somehow. Use an **external UART adapter** if both the energy profiler and UART debugging are necessary at the same time!\n\nDon't forget to change the `INIT` arguments to select the correct pins if necessary! (see section [\"6 - Alternate locations of pins\"](#6---alternate-locations-of-pins)).\n\nIf the energy profiler was used and the code functionality was switched, physically re-plug the board to make sure VCOM UART starts working again!\n\n\u003cbr/\u003e\n\n\u003c!--\nThe following instructions are used when you want to be able to use `dbprint` in every project you create. Place the source files somewhere safe so you don't accidentally delete them!\n\nOpen the project settings using `File \u003e Properties \u003e C/C++ General \u003e Paths and Symbols`.\n\nIn the tab **\"Includes\"**:\n\n1. Click `Add... \u003e File system...`\n2. Browse to the **\"dbprint-inc\"** folder and press OK. \n3. Check *\"Add to all languages\"* and press OK.\n\nIn the tab **\"Source Location\"**:\n\n1. Click `Link Folder...`\n2. Check *\"Link to folder in the file system\"*\n3. Click `Browse...`, select the the **\"dbprint-scr\"** folder and press OK.\n--\u003e\n\n## 5 - Methods\n\n### 5.1 - Definitions\n\nThis is a list of all available methods. **Detailed documentation about them can be found [here](https://fescron.github.io/dbprint/dbprint_8h.html).**\n\n```C\nvoid dbprint_INIT(USART_TypeDef* pointer, uint8_t location, bool vcom, bool interrupts);\n \nvoid dbAlert(void);\nvoid dbClear(void);\n\nvoid dbprint(char *message);\nvoid dbprintln(char *message);\n\nvoid dbprintInt(int32_t value);\nvoid dbprintlnInt(int32_t value);\n\nvoid dbprintInt_hex(int32_t value);\nvoid dbprintlnInt_hex(int32_t value);\n\nvoid dbprint_color(char *message, dbprint_color_t color);\nvoid dbprintln_color(char *message, dbprint_color_t color);\n\nvoid dbinfo(char *message);\nvoid dbwarn(char *message);\nvoid dbcrit(char *message);\n\nvoid dbinfoInt(char *message1, int32_t value, char *message2);\nvoid dbwarnInt(char *message1, int32_t value, char *message2);\nvoid dbcritInt(char *message1, int32_t value, char *message2);\n\nvoid dbinfoInt_hex(char *message1, int32_t value, char *message2);\nvoid dbwarnInt_hex(char *message1, int32_t value, char *message2);\nvoid dbcritInt_hex(char *message1, int32_t value, char *message2);\n\nchar dbReadChar(void);\nuint8_t dbReadInt(void);\nvoid dbReadLine(char *buf);\n\nbool dbGet_RXstatus(void);\nvoid dbGet_RXbuffer(char *buf);\n```\n\n\u003cbr/\u003e\n\n### 5.2 - Usage examples\n\n#### 5.2.1 - Basic functions\n\n```C\ndbprint_INIT(USART1, 4, true, false); /* Initialize UART1 on VCOM, no interrupts*/\n```\n\n```C\ndbprint(\"Hello World\");    /* Print text to uart */\ndbprintln(\"\");             /* Go to next line */\ndbprintln(\"Hello World\");  /* Print text to uart and go to the next line */\n\ndbinfo(\"Info.\");           /* Print an info message (prefix \"INFO: \") */\ndbwarn(\"Warning.\");        /* Print a warning message in yellow (prefix \"WARN: \") */\ndbcrit(\"Critical error.\"); /* Print a critical error message in red (prefix \"CRIT: \") */\n```\n\n```C\nuint32_t value = 42;\n\n/* Print \"unsigned int\" value in decimal notation */\ndbprintInt(value);       /* Stay on the current line */\ndbprintlnInt(value);     /* Go to next line */\n\n/* Print \"unsigned int\" value in hexadecimal notation */\ndbprintInt_hex(value);   /* Stay on the current line */\ndbprintlnInt_hex(value); /* Go to next line */\n\n/* The methods above also work for printing \"signed int\" values like: */\nint32_t intValue = -42;\n```\n\n```C\n/* Read a character and check wich one it is */\ndbprint(\"Type 'y' or 'n': \");\nchar test = dbReadChar();\nif (test == 'y') dbprintln(\"Yes\");\nif (test == 'n') dbprintln(\"No\");\n\n/* Read a character and convert it to a uint8_t value, print it afterwards */\ndbprint(\"Type a number (1 character): \");\nuint8_t test2 = dbReadInt();\ndbprintlnInt(test2);\n\n/* Read a line and print it, press enter to stop typing.\n * It also stops when DBPRINT_BUFFER_SIZE is reached. */\ndbprint(\"Type a line: \");\nchar testArray[DBPRINT_BUFFER_SIZE];\ndbReadLine(testArray);\ndbprintln(testArray);\n```\n\n\u003cbr/\u003e\n\n#### 5.2.2 - More advanced functions\n\n```C\ndbAlert(); /* Let the console make an \"alert\" (bell) sound */\ndbClear(); /* Clear the console window */\n```\n\n```C\ndbprint_color(\"Hello World\", RED);   /* Print red text to uart */\ndbprintln(\"\");                       /* Go to next line */\ndbprintln_color(\"Hello World\", RED); /* Print red text to uart and go to the next line */\n```\n\n```C\nuint32_t value = 42;\n\n/* Print an info message with prefix \"INFO: \" where a value\n   in decimal notation is enclosed between two strings */\ndbinfoInt(\"Info = \", value, \" [unit of value]\");\n\n/* Print an info message with prefix \"INFO: \" where a value\n   in hexadecimal notation is enclosed between two strings */\ndbinfoInt_hex(\"Info = \", value, \" [unit of value]\");\n\n/* Print a warning message in yellow with prefix \"WARN: \" where a value\n   in decimal notation is enclosed between two strings */\ndbwarnInt(\"Warning = \", value, \" [unit of value]\");\n\n/* Print a warning message in yellow with prefix \"WARN: \" where a value\n   in hexadecimal notation is enclosed between two strings */\ndbwarnInt_hex(\"Warning = \", value, \" [unit of value]\");\n\n/* Print a critical error message in red with prefix \"CRIT: \" where a value\n  in decimal notation is enclosed between two strings */\ndbcritInt(\"Critical error = \", value, \" [unit of value]\");\n\n/* Print a critical error message in red with prefix \"CRIT: \" where a value\n  in hexadecimal notation is enclosed between two strings */\ndbcritInt_hex(\"Critical error = \", value, \" [unit of value]\");\n```\n\n\u003cbr/\u003e\n\n#### 5.2.3 - Interrupt functionality\n\nDbprint can also be put in **interrupt mode** by using the `INIT` arguments below, using VCOM for this example. Then, **received characters will be automatically stored in an internal buffer** for later use.\n\n```C\ndbprint_INIT(USART1, 4, true, true); /* Initialize dbprint on VCOM, interrupt mode */\n```\n\nA *getter* (`dbGet_RXstatus();`) can be used to check if there is received data in this internal buffer and another *getter* (`dbGet_RXbuffer();`) can be used to copy the data from this internal buffer to another one.\n\nAn example using these two getters is depicted below and can be put in, for example, the `main.c` file.\n\n```C\nbool received = dbGet_RXstatus(); /* Check if there is data received in the buffer */\n\n/* If we received data do the following */\nif (received)\n{\n  char buf[DBPRINT_BUFFER_SIZE]; /* Create a temporary buffer to store the received data in */\n  dbGet_RXbuffer(buf); /* Copy the received data to this temporary buffer */\n  dbprintln(buf); /* Print the contents of this temporary buffer in the terminal */\n}\n```\n\n\u003cbr/\u003e\n\n## 6 - Alternate locations of pins\n\nIn C, pin selection/routing happens at the end of initialization methods using statements like:\n\n```C\nUSART1-\u003eROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;\n```\n\nIf you use dbprint you don't really need to worry about this but you need to make sure you **select the correct location when calling the `dbprint_INIT` method**.\n\nThe location numbers and corresponding `RX`and `TX`pins for `USART0`and `USART1` (EFM32HG322) are given below.\n\n| Location |  #0  |  #1  |  #2  |  #3  |  #4  |  #5  |  #6  |\n| -------- |:----:|:----:|:----:|:----:|:----:|:----:|:----:| \n| US0_RX   | PE11 |      | PC10 | PE12 | PB8  | PC1  | PC1  |\n| US0_TX   | PE10 |      |      | PE13 | PB7  | PC0  | PC0  |\n| US1_RX   | PC1  |      | PD6  | PD6  | PA0  | PC2  |      |\n| US1_TX   | PC0  |      | PD7  | PD7  | PF2  | PC1  |      |\n\n\u003cbr/\u003e\n\nVCOM:\n - `USART1 #4` (`USART0` can't be used)\n - RX - `PA0`\n - TX - `PF2`\n - Isolation switch - `PA9` (`EFM_BC_EN`) \u003cbr/\u003e **Don't use this pin yourself when using the on-board UART to USB converter!**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffescron%2Fdbprint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffescron%2Fdbprint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffescron%2Fdbprint/lists"}