|
| 1 | +Semihosting Support |
| 2 | +=================== |
| 3 | + |
| 4 | +Using special debugger breakpoints and commands, the Pico can read and write to the debugging console as well |
| 5 | +as read and write files on a development PC. The ``Semihosting`` library allows applications to use the |
| 6 | +semihosting support as a normal filesystem or serial port. |
| 7 | + |
| 8 | +**NOTE** Semihosting only works when connected to an OpenOCD + GDB debug session. Running an application |
| 9 | +compiled for Semihosting without the debugger will cause a panic and hang the chip. |
| 10 | + |
| 11 | +As of now, only ARM has support for Semihosting. |
| 12 | + |
| 13 | +Running Semihosting on the Development Host |
| 14 | +------------------------------------------- |
| 15 | + |
| 16 | +Start OpenOCD normally from inside a directory that you can read and write files within (i.e. do not run from |
| 17 | +``C:\\Program Files\\..`` on Windows where general users aren't allowed to write). The starting |
| 18 | +directory will be where the Pico will read and write files using the ``SemiFS`` class. |
| 19 | +Be sure to keep the terminal window you ran OpenOCD in open, because all ``SerialSemi`` input and output |
| 20 | +will go to **that** terminal and not ``gdb``'s. |
| 21 | + |
| 22 | +Start GDB normally and connect to the OpenOCD debugger and enable semihosting support |
| 23 | + |
| 24 | +.. code:: |
| 25 | +
|
| 26 | + (gdb) target extended-remote localhost:3333 |
| 27 | + (gdb) monitor arm semihosting enable |
| 28 | +
|
| 29 | +At this point load and run your ``ELF`` application as normal. Again, all ``SerialSemi`` output will go |
| 30 | +to the **OpenOCD** window, not GDB. |
| 31 | + |
| 32 | +See the ``hellosemi`` example in the ``Semihosting`` library. |
| 33 | + |
| 34 | +SerialSemi - Serial over Semihosting |
| 35 | +------------------------------------ |
| 36 | + |
| 37 | +Simply include ``<Semihosting.h>`` in your application and use ``SerialSemi`` as you would any other |
| 38 | +``Serial`` port with the following limitations: |
| 39 | + |
| 40 | +* Baud rate, bit width, etc. are all ignored |
| 41 | +* Input is limited because ``read`` may hang indefinitely in the host and ``available`` is not part of the spec |
| 42 | + |
| 43 | +SemiFS - Host filesystem access through Semihosting |
| 44 | +--------------------------------------------------- |
| 45 | + |
| 46 | +Use ``SemiFS`` the same way as any other file system. Note that only file creation and renaming are supported, with |
| 47 | +no provision for iterating over directories or listing files. In most cases simply opening a ``File`` and writing out |
| 48 | +a debug dump is all that's needed: |
| 49 | + |
| 50 | +.. code:: |
| 51 | +
|
| 52 | + SemiFS.begin(); |
| 53 | + File f = SemiFS.open("debug.dmp", "w"); |
| 54 | + f.write(buffer, size); |
| 55 | + f.close(); |
| 56 | + SerialSemi.printf("Debug dump nopw available on host.\n"); |
0 commit comments