This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem using Serial Wire and SPI3

Hi,

I'm using the STM32F105 and unfortunately I have a problem regarding to the serial wire debugging.

Abstract:
In my application I have to use both, SPI2 and SPI3 simultaneously. In order to use SPI3 without remapping I want to disable the JTAG Port as discribed in chapter 29.4.4 in the RM0008 to free PB3.
That means I just want to use PA13 and PA14 (Serial Wire) for debugging purposes. Therefore I added the following lines at the beginning of my source code (just after main()):

 RCC->APB2ENR |=  (1 <<  2)|(1 << 0)|(1 << 3);        /* Enable PortA, PortB, Enable AFIO  */
 AFIO->MAPR &= 0xF8FFFFFF;                            /* reset SWJ_CFG     */
 AFIO->MAPR |= 0x02000000;                            /* enable sw, disable jtag   */

In addition I disabled the Trace function in the debug section of the ULINK2, disabled the SWJ and enabled the usage of SW.

Problem:

I'm able to program the target. Then the function of SPI2 and SPI3 is correct.
BUT if I enter the debugger suddenly SPI3 stops working.
The clock output of SPI3 (PB3) which is usually used for tracing doesn't output a clock signal any more.
The rest of the application works fine besides SPI3.

When I want to reprogram or reset the target, the problem still remains. Even if I leave the debugger.
This happens until I remove VDD from the target.

When VDD was removed I'm able to reprogram the target. Then the application runs with the correct function.
But when I enter the debug mode again the problem appears again.

I hope anybody can help me

Thanking you in anticipation
Best regards

Thomas

  • The problem you are seeing is most probably caused by missconfigured DBGMCU_CR register.

    DBGMCU_CR controls (among other stuff) the global enable for Trace pins. TRACE_IOEN bit needs to be 0 in order to release trace pins for I/O.

    Check if you have a debugger ini file which configures the DBGMCU_CR register and sets TRACE_IOEN to 1 (default configuration when trace is used). Since this register is only reset at power on this also explains why regular reset has no effect.

    Also note that you still need to enable SWJ in the debugger settings.

    SWJ enables the switch sequence from JTAG to SWD. JTAG is default debug interface after reset and a special sequence is required on the two JTAG pins that are shared with SWD to switch to SWD. You can use only the two SWD pins (shared with JTAG) for debugging but the SWJ sequence still needs to be executed.

  • Hi Robert,

    thank you for your answer.
    Your recommendation fixed the problem mostly.

    But now I have another issue.

    Your solution (disable TRACE_IOEN) works fine on an application without OS (RTX). But when I disable the TRACE_IOEN bit on an application using OS the program doesn't reach the task task_init after function call os_sys_init (task_init);.

    Any ideas?

    Thomas

  • RTX uses ITM channel for providing RTOS related information (task switch ...).

    Disable ITM Stimulus Ports in the ULINK Trace configuration.

  • Hi Robert,

    I already disbled the checkbox "Trace Enable".
    But the problem still remains.

    Regards

    Thomas

  • Did you set the "ITM Stimulus Ports - Enable" to 0 (disabling all ITM channels)?

    Also Power off/on the target.

    If it still fails can you stop the target and provide the disassembly of the current PC and a few instructions?

  • Hi Robert,

    It seems it works now.

    I forgot to disconnect the target from VDD.
    (I'm not used to do it)
    But now I am able to debug the application.

    Many thanks to you

    regards

    Thomas