Brian Silverman | 4787a6e | 2018-10-06 16:00:54 -0700 | [diff] [blame] | 1 | #ifndef MOTORS_PRINT_SEMIHOSTING_H_ |
| 2 | #define MOTORS_PRINT_SEMIHOSTING_H_ |
| 3 | |
| 4 | #include "motors/print/print.h" |
| 5 | |
| 6 | namespace frc971 { |
| 7 | namespace motors { |
| 8 | |
| 9 | // A printing implementation which uses the ARM semihosting interface. This |
| 10 | // requries an attached debugger with software support. |
| 11 | // |
| 12 | // You have to do "arm semihosting enable" in openocd to enable this. |
| 13 | // It also seems to be broken with the usb-tiny-h in the openocd version we're |
| 14 | // using, but works fine with the st-link-v2. |
| 15 | // It may also only work if you do this immediately after starting openocd. |
| 16 | // |
| 17 | // Note that this implementation has strange effects on timing even of |
| 18 | // interrupts-disabled code and is in general extremely slow. |
| 19 | class SemihostingPrinting final : public PrintingImplementation { |
| 20 | public: |
| 21 | SemihostingPrinting() = default; |
| 22 | ~SemihostingPrinting() override = default; |
| 23 | |
| 24 | void Initialize() override {} |
| 25 | |
| 26 | int WriteStdout(gsl::span<const char> buffer) override; |
| 27 | |
| 28 | // Could easily implement an optional WriteDebug which goes to a separate |
| 29 | // file if the name is filled out in the parameters. |
| 30 | }; |
| 31 | |
| 32 | } // namespace motors |
| 33 | } // namespace frc971 |
| 34 | |
| 35 | #endif // MOTORS_PRINT_SEMIHOSTING_H_ |