Menu

#263 Improper Setting of TPIU Prescale When Using External

0.9.0
new
nobody
2020-09-07
2020-04-19
No

Problem:

When trying to configure the TPIU with a system clock of 72000000 and a desired baud rate of 2000000 I get a prescale value of 29 going into register 0xe0040010 (TPIU_ACPR) vice the value of 36 which would be expected. Output frequency verified to be 2.5MHz with an oscope. This corresponds with the presale value of 29 (72000000/29 -> 2.48MHz)

Setup:

Openocd (git hash a1c51caa) compiled on Raspberry Pi 4B connected to a STM32 Bluepill using the bitbanged driver.

Openocd Config File

source [find interface/raspberrypi2-native.cfg]
transport select swd

#set CHIPNAME stm32f103
set CHIPNAME stm32
source [find target/stm32f1x.cfg]

# did not yet manage to make a working setup using srst
#reset_config srst_only
#reset_config  srst_nogate

adapter srst delay 100
adapter srst pulse_width 100

bindto 0.0.0.0

#tpiu config external uart off 72000000 2000000

init
targets
reset halt

tpiu config external uart off 72000000 2000000

Based on an initial review of the Opened source code, I see that the function armv7m_trace_tpiu_config [src/target/armv7m_trace.c (Line 55)] does not initialize the value of the variable prescaler. When I break into the program using GDB, I see that the default value assigned is 30. This value is not updated in the call to adapter_config_trace(...) on line 64.

The value is not updated in that function call because jtag->config_trace is false and enabled is set to false. Therefore the adapter_config_trace function silently returns ERROR_OK. The original calling function continues to just use the value of 30 (the data at the memory location as the var was uninitialized) and sets the register 0xe0040010 to 29 (which is prescaler - 1) on line 80 of src/target/armv7m_trace.c.

Is this the intended behavior (Did I miss a setting somewhere?). I was attempting to follow the manual on page 138 (Section 16.6.3).

Discussion

  • Justace Clutter

    Justace Clutter - 2020-04-19

    I realized that the jlink references I made were incorrect. This seems to be an interaction issue with setting the TPIU configuration while using the Raspberry Pi interface. I have added the following lines in my openocd.conf file and this has the trace being consistantly generated:

    mww phys 0xE000EDFC 0x01000000
    mwb phys 0xE0042004 0x27
    mwb phys 0xE00400F0 2
    mwb phys 0xE0040010 34
    mww phys 0xE0000FB0 0xC5ACCE55
    mww phys 0xE0000E80 0x0001000D
    mwb phys 0xE0000E40 0x0000000F
    mwb phys 0xE0000E00 0x1
    

    This enabled stimulus port 0 and setup the stream for a 2MHz baud rate. (I had to finagle the write to 0xE0040010 (the prescaler value) to 34 to get the 2MHz output. I thought it should have been 35 to get a true value of 36 which is 72MHz / 2MHz)

     

    Last edit: Justace Clutter 2020-04-19
  • Antonio Borneo

    Antonio Borneo - 2020-09-07

    Could you please check if patch http://openocd.zylin.com/5807 can solve this issue?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.