Clean up printing in MCU code and add new options
We now have four different ways of getting debug prints off of boards,
with varying tradeoffs. Split out the printing into dedicated libraries
that are easy to switch between to avoid duplicating even more code, and
also make using the new options easy.
USB is handy for testing the code on a Teensy.
Semihosting is nice in theory, but in practice it's super slow and
messes up the code's timing.
ITM works well, as long as you have a debugger attached.
Serial also works pretty well, but it means having another cable.
Change-Id: I7af5099d421c33f0324aeca92b46732e341848d4
diff --git a/motors/print/semihosting.h b/motors/print/semihosting.h
new file mode 100644
index 0000000..6ea6c3b
--- /dev/null
+++ b/motors/print/semihosting.h
@@ -0,0 +1,35 @@
+#ifndef MOTORS_PRINT_SEMIHOSTING_H_
+#define MOTORS_PRINT_SEMIHOSTING_H_
+
+#include "motors/print/print.h"
+
+namespace frc971 {
+namespace motors {
+
+// A printing implementation which uses the ARM semihosting interface. This
+// requries an attached debugger with software support.
+//
+// You have to do "arm semihosting enable" in openocd to enable this.
+// It also seems to be broken with the usb-tiny-h in the openocd version we're
+// using, but works fine with the st-link-v2.
+// It may also only work if you do this immediately after starting openocd.
+//
+// Note that this implementation has strange effects on timing even of
+// interrupts-disabled code and is in general extremely slow.
+class SemihostingPrinting final : public PrintingImplementation {
+ public:
+ SemihostingPrinting() = default;
+ ~SemihostingPrinting() override = default;
+
+ void Initialize() override {}
+
+ int WriteStdout(gsl::span<const char> buffer) override;
+
+ // Could easily implement an optional WriteDebug which goes to a separate
+ // file if the name is filled out in the parameters.
+};
+
+} // namespace motors
+} // namespace frc971
+
+#endif // MOTORS_PRINT_SEMIHOSTING_H_