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