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/simple_receiver.cc b/motors/simple_receiver.cc
index 3b174b0..36d489f 100644
--- a/motors/simple_receiver.cc
+++ b/motors/simple_receiver.cc
@@ -11,11 +11,10 @@
#include "motors/peripheral/adc.h"
#include "motors/peripheral/can.h"
#include "motors/peripheral/configuration.h"
+#include "motors/print/print.h"
#include "motors/seems_reasonable/drivetrain_dog_motor_plant.h"
#include "motors/seems_reasonable/polydrivetrain_dog_motor_plant.h"
#include "motors/seems_reasonable/spring.h"
-#include "motors/usb/cdc.h"
-#include "motors/usb/usb.h"
#include "motors/util.h"
namespace frc971 {
@@ -83,8 +82,6 @@
};
-::std::atomic<teensy::AcmTty *> global_stdout{nullptr};
-
::std::atomic<PolyDrivetrain<float> *> global_polydrivetrain{nullptr};
::std::atomic<Spring *> global_spring{nullptr};
@@ -647,15 +644,6 @@
extern "C" {
void *__stack_chk_guard = (void *)0x67111971;
-
-int _write(int /*file*/, char *ptr, int len) {
- teensy::AcmTty *const tty = global_stdout.load(::std::memory_order_acquire);
- if (tty != nullptr) {
- return tty->Write(ptr, len);
- }
- return 0;
-}
-
void __stack_chk_fail(void);
} // extern "C"
@@ -742,13 +730,11 @@
delay(100);
- teensy::UsbDevice usb_device(0, 0x16c0, 0x0492);
- usb_device.SetManufacturer("Seems Reasonable LLC");
- usb_device.SetProduct("Simple Receiver Board");
-
- teensy::AcmTty tty0(&usb_device);
- global_stdout.store(&tty0, ::std::memory_order_release);
- usb_device.Initialize();
+ PrintingParameters printing_parameters;
+ printing_parameters.dedicated_usb = true;
+ const ::std::unique_ptr<PrintingImplementation> printing =
+ CreatePrinting(printing_parameters);
+ printing->Initialize();
SIM_SCGC6 |= SIM_SCGC6_PIT;
// Workaround for errata e7914.