7 Replies Latest reply on Mar 22, 2018 11:30 AM by srds

    PSOC6 Serial Wire Viewer

    anders_2738496

      Hi, I am searching for information on how to get printf working over the SWD port.

      I have a miniprog3 connected and I would like a terminal on my computer where I can see debug messages.

       

      Does anyone have some code to set this up? (I guess more is needed than selecting "SWD+SWV" in Programming/Debugging)

       

      Also what is the best way to watch the output? Is it getting a J-link, looking in the Output tab of PSOC Creator, or something else?

       

      So far I have borrowed this together off the internet,

       

      best regards

      Anders

       

      /*********************************************************************

      *

      *       Defines for Cortex-M debug unit

      */

      #define ITM_STIM_U32 (*(volatile unsigned int*)0xE0000000)    // Stimulus Port Register word access

      #define ITM_STIM_U8  (*(volatile         char*)0xE0000000)    // Stimulus Port Register byte access

      #define ITM_ENA      (*(volatile unsigned int*)0xE0000E00)    // Trace Enable Ports Register

      #define ITM_TCR      (*(volatile unsigned int*)0xE0000E80)    // Trace control register

       

      /*********************************************************************

      *

      *       SWO_PrintChar()

      *

      * Function description

      *   Checks if SWO is set up. If it is not, return,

      *    to avoid program hangs if no debugger is connected.

      *   If it is set up, print a character to the ITM_STIM register

      *    in order to provide data for SWO.

      * Parameters

      *   c:    The Chacracter to be printed.

      * Notes

      *   Additional checks for device specific registers can be added.

      */

      void SWO_PrintChar(char c) {

        //

        // Check if ITM_TCR.ITMENA is set

        //

        if ((ITM_TCR & 1) == 0) {

          return;

        }

        //

        // Check if stimulus port is enabled

        //

        if ((ITM_ENA & 1) == 0) {

          return;

        }

        //

        // Wait until STIMx is ready,

        // then send data

        //

        while ((ITM_STIM_U8 & 1) == 0);

        ITM_STIM_U8 = c;

      }

       

       

      int _write(int file, char *ptr, int len)

      {

          int i;

       

          for (i = 0; i < len; i++)

          {

              SWO_PrintChar(*ptr++);

          }

          return len;

      }