Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WiFi_Scanner mbed_nucleo_swo DISCO-F429ZI_LCDTS_demo_richard TEST_SM_SPEED
Diff: SWO.cpp
- Revision:
- 0:0fd55660fc26
- Child:
- 1:bae4cff278f6
diff -r 000000000000 -r 0fd55660fc26 SWO.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SWO.cpp Fri Mar 28 19:32:13 2014 +0000
@@ -0,0 +1,68 @@
+
+#include "SWO.h"
+
+
+/*********************************************************************
+*
+* Defines for Cortex-M debug unit
+*/
+#define ITM_STIM_U32(n) (*(volatile unsigned int*)(0xE0000000+4*n)) // Stimulus Port n Register word access
+//#define ITM_STIM_U32_0 (*(volatile unsigned int*)0xE0000000) // Stimulus Port 0 Register word access
+//#define ITM_STIM_U8_0 (*(volatile char*)0xE0000000) // Stimulus Port 0 Register byte access
+#define ITM_ENA (*(volatile unsigned int*)0xE0000E00) // Trace Enable Ports Register
+#define ITM_TCR (*(volatile unsigned int*)0xE0000E80) // Trace control register
+
+
+
+/*********************************************************************
+*
+* SWO_PrintChar()
+*
+* @brief
+* Checks if SWO is set up. If it is not, return,
+* to avoid program hangs if no debugger is connected.
+* If it is set up, print a character to the ITM_STIM register
+* in order to provide data for SWO.
+* @param c The Character to be printed.
+* @notes Additional checks for device specific registers can be added.
+*/
+void SWO_PrintChar(char c) {
+ //
+ // Check if ITM_TCR.ITMENA is set
+ //
+ if ((ITM_TCR & 1) == 0) {
+ return;
+ }
+ //
+ // Check if stimulus port is enabled
+ //
+ if ((ITM_ENA & 1) == 0) {
+ return;
+ }
+ //
+ // Wait until STIMx is ready,
+ // then send data
+ //
+// while ((ITM_STIM_U8(0) & 1) == 0);
+// ITM_STIM_U8(0) = c;
+
+ while ((ITM_STIM_U32(0) & 1) == 0);
+ ITM_STIM_U32(0) = c;
+}
+
+/*********************************************************************
+*
+* SWO_PrintString()
+*
+* @brief Print a string via SWO.
+* @param *s The string to be printed.
+*
+*/
+void SWO_PrintString(const char *s) {
+ //
+ // Print out character per character
+ //
+ while (*s) {
+ SWO_PrintChar(*s++);
+ }
+}
\ No newline at end of file
SWO viewer