Debugger issues with NUCLEO-L476RG

Hi,

I’m using Mbed Studio 1.3.1 on Windows 10 with the NUCLEO-L476RG. This target is not natively supported by the debugger.

In 1.3.0, in order to make it work, I had to :

  • Manually download Keil.STM32L4xx_DFP.2.5.0.pack and Keil.STM32NUCLEO_BSP.1.7.0.pack (Keil.STM32L4xx_DFP.2.3.0 coming with Mbed Studio does not work).
  • Fix the IRAM definitions in Keil.STM32L4xx_DFP.2.5.0.pack to avoid this error:
warning: Overlapping regions in memory map: ignoring
"0012839:ERROR:gdbserver:Unhandled exception in handle_message: individual memory accesses must not cross memory region boundaries"
  • Create a custom target with the following options:
--target STM32L476RGTx --erase=chip --frequency 1800000 --pack Keil.STM32L4xx_DFP.2.5.0.pack --pack Keil.STM32NUCLEO_BSP.1.7.0.pack -O connect_mode=under-reset

After upgrading to 1.3.1, the update of the internal tools was broken, so I had to uninstall, clean, and reinstall Mbed Studio.

In 1.3.1, the port issue is fixed, but:

  • With Keil.STM32L4xx_DFP.2.3.0, I get:
Selected port 50000 for debugging
0000736:CRITICAL:__main__:Target type 'stm32l476rgtx' not recognized. Use 'pyocd list --targets' to see currently available target types. See  for how to install additional target support.
Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\board\board.py", line 61, in __init__
    self.target = TARGET[self._target_type](session)
KeyError: 'stm32l476rgtx'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\__main__.py", line 362, in run
    self._COMMANDS[self._args.cmd](self)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\__main__.py", line 676, in do_gdbserver
    options=sessionOptions)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\helpers.py", line 242, in session_with_chosen_probe
    return Session(probe, auto_open=auto_open, options=options, **kwargs)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\session.py", line 178, in __init__
    self._board = probe.create_associated_board() \
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 111, in create_associated_board
    return MbedBoard(self.session, board_id=self._board_id)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\board\mbed_board.py", line 67, in __init__
    super(MbedBoard, self).__init__(session, target)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\board\board.py", line 67, in __init__
    "for how to install additional target support." % self._target_type), exc)
  File "", line 3, in raise_from
pyocd.core.exceptions.TargetSupportError: Target type 'stm32l476rgtx' not recognized. Use 'pyocd list --targets' to see currently available target types. See  for how to install additional target support.
"GDB server stopped unexpectedly with exit code 1"
  • With Keil.STM32L4xx_DFP.2.5.0.pack (patched or unpatched) and Keil.STM32NUCLEO_BSP.1.7.0.pack with -O connect_mode=under-reset or -O connect_mode=pre-reset, I get:
Selected port 50000 for debugging
0000593:INFO:board:Target type is stm32l476rgtx
0000665:INFO:coresight_target:Asserting reset prior to connect
0000719:INFO:dap:DP IDR = 0x2ba01477 (v1 rev2)
0000797:INFO:ap:AHB-AP#0 IDR = 0x24770011 (AHB-AP var1 rev2)
0000802:INFO:rom_table:AHB-AP#0 Class 0x1 ROM table #0 @ 0xe00ff000 (designer=020 part=415)
0000804:INFO:rom_table:[0]
0000806:INFO:rom_table:[1]
0000807:INFO:rom_table:[2]
0000808:INFO:rom_table:[3]
0000810:INFO:rom_table:[4]
0000811:INFO:rom_table:[5]
0000812:INFO:cortex_m:CPU core #0 is Cortex-M4 r0p1
0000816:INFO:dwt:4 hardware watchpoints
0000819:INFO:fpb:6 hardware breakpoints, 4 literal comparators
0000828:INFO:coresight_target:Deasserting reset post connect
0000837:INFO:server:Semihost server started on port 4444 (core 0)
0000838:INFO:gdbserver:GDB server started on port 50000 (core 0)
Exception in thread gdb-server-core0:
Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 272, in run
    self.target.halt()
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 683, in halt
    self.write_memory(CortexM.DHCSR, CortexM.DBGKEY | CortexM.C_DEBUGEN | CortexM.C_HALT)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 640, in write_memory
    self.ap.write_memory(addr, value, transfer_size)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 241, in write_memory
    self._link.write_mem32(addr, conversion.u32le_list_to_byte_list([data]), self._apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 391, in write_mem32
    self._write_mem(addr, data, Commands.JTAG_WRITEMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 381, in _write_mem
    raise self._ERROR_CLASSES[status](error_message)
pyocd.core.exceptions.TransferTimeoutError: STLink error (20): DP wait

0000848:ERROR:board:link exception during target disconnect:
Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\board\board.py", line 98, in uninit
    self.target.disconnect(resume)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\coresight_target.py", line 305, in disconnect
    core.disconnect(resume)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 506, in disconnect
    self.write32(CortexM.DEMCR, 0)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\core\memory_interface.py", line 44, in write32
    self.write_memory(addr, value, 32)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 640, in write_memory
    self.ap.write_memory(addr, value, transfer_size)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 241, in write_memory
    self._link.write_mem32(addr, conversion.u32le_list_to_byte_list([data]), self._apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 391, in write_mem32
    self._write_mem(addr, data, Commands.JTAG_WRITEMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 379, in _write_mem
    raise exc
pyocd.core.exceptions.TransferFaultError: SWD/JTAG Transfer Fault @ 0xe000edfc-0xe000ee03
  • With the unpatched Keil.STM32L4xx_DFP.2.5.0.pack and Keil.STM32NUCLEO_BSP.1.7.0.pack with -O connect_mode=halt or -O connect_mode=attach, the debugger starts, but then, after stepping, I get:
pyocd.cache.memory.MemoryAccessError: individual memory accesses must not cross memory region boundaries
"0017170:ERROR:gdbserver:Unhandled exception in handle_message: individual memory accesses must not cross memory region boundaries"
  • With my patched Keil.STM32L4xx_DFP.2.5.0.pack and Keil.STM32NUCLEO_BSP.1.7.0.pack with -O connect_mode=halt or -O connect_mode=attach, the debugger starts, but then, after stepping, I get:
warning: Remote failure reply: E01
0018711:ERROR:gdbserver:Unhandled exception in handle_message: SWD/JTAG Transfer Fault @ 0xe000ed30-0xe000ed37
Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 558, in resume
    if self.target.get_state() == Target.State.HALTED:
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 982, in get_state
    dhcsr = self.read_memory(CortexM.DHCSR)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 646, in read_memory
    result = self.ap.read_memory(addr, transfer_size, now)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 255, in read_memory
    result = conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, 4, self._apsel))[0]
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 387, in read_mem32
    return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 347, in _read_mem
    raise self._ERROR_CLASSES[status](error_message)
pyocd.core.exceptions.TransferTimeoutError: STLink error (20): DP wait

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 383, in handle_message
    reply = handler(msg[msgStart:])
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 610, in v_command
    return self.v_cont(cmd)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 661, in v_cont
    return self.resume(None)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 577, in resume
    val = ('S%02x' % self.target_facade.get_signal_value()).encode()
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\context_facade.py", line 146, in get_signal_value
    if self._context.core.is_debug_trap():
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 1331, in is_debug_trap
    debugEvents = self.read_memory(CortexM.DFSR) & (CortexM.DFSR_DWTTRAP | CortexM.DFSR_BKPT | CortexM.DFSR_HALTED)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 646, in read_memory
    result = self.ap.read_memory(addr, transfer_size, now)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 255, in read_memory
    result = conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, 4, self._apsel))[0]
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 387, in read_mem32
    return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 345, in _read_mem
    raise exc
pyocd.core.exceptions.TransferFaultError: SWD/JTAG Transfer Fault @ 0xe000ed30-0xe000ed37
0018744:ERROR:gdbserver:Unhandled exception in handle_message: SWD/JTAG Transfer Fault @ 0xe000edf0-0xe000edf7
Traceback (most recent call last):
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 381, in handle_message
    reply = handler()
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\gdbserver.py", line 817, in get_registers
    return self.create_rsp_packet(self.target_facade.get_register_context())
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\gdbserver\context_facade.py", line 69, in get_register_context
    vals = self._context.read_core_registers_raw(reg_num_list)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\rtos\rtx5.py", line 195, in read_core_registers_raw
    reg_vals.append(self._parent.read_core_register_raw(reg))
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\debug\context.py", line 104, in read_core_register_raw
    vals = self.read_core_registers_raw([reg])
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\debug\cache.py", line 48, in read_core_registers_raw
    return self._regcache.read_core_registers_raw(reg_list)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\cache\register.py", line 100, in read_core_registers_raw
    self._check_cache()
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\cache\register.py", line 77, in _check_cache
    if self._core.is_running():
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 1013, in is_running
    return self.get_state() == Target.State.RUNNING
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 982, in get_state
    dhcsr = self.read_memory(CortexM.DHCSR)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\coresight\cortex_m.py", line 646, in read_memory
    result = self.ap.read_memory(addr, transfer_size, now)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink_probe.py", line 255, in read_memory
    result = conversion.byte_list_to_u32le_list(self._link.read_mem32(addr, 4, self._apsel))[0]
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 387, in read_mem32
    return self._read_mem(addr, size, Commands.JTAG_READMEM_32BIT, self.MAXIMUM_TRANSFER_SIZE, apsel)
  File "c:\ProgramData\Mbed Studio\mbed-studio-tools\python\lib\site-packages\pyocd\probe\stlink\stlink.py", line 345, in _read_mem
    raise exc
pyocd.core.exceptions.TransferFaultError: SWD/JTAG Transfer Fault @ 0xe000edf0-0xe000edf7
"0018711:ERROR:gdbserver:Unhandled exception in handle_message: SWD/JTAG Transfer Fault @ 0xe000ed30-0xe000ed37"
Remote failure reply: E01

And, in case you wonder, I’m using the latest ST-LINK/V2 driver and firmware from ST’s website.

This IDE is an absolute nightmare and a huge waste of time. Please fix it. In the meantime, I will have to downgrade to 1.3.0.

And of course, there is only a link to download the latest version of Mbed Studio, but nothing to downgrade it. Where can I get the 1.3.0 installer, please?

Hi Benoît,

Apologies for this issue. Unfortunately, it is very difficult for us to test every board. Especially targets that are not officially supported by pyOCD. We are actively working on a new debugger in Studio that should improve the number of supported boards and the general stability of debugging. Until it is ready we recommend:

a) One difference between 1.3.0 and 1.3.1 that may explain this regression is a pyOCD update:
1.3.0 is bundled with pyOCD 0.27.0
1.3.1 is bundled with pyOCD 0.27.3

All python tools bundled with Studio are accessible from the built-in terminal (Using tools in the terminal - Using tools in the terminal | Mbed Studio Documentation). That includes pip. You can downgrade pyOCD version included in Studio by running the following command in the terminal:

pip install pyOCD==0.27.0

b) Mbed Studio 1.3.0 is still available for download. We always keep at least 2-3 previous versions. Windows version can be found here: https://studio.mbed.com/installers/latest/win/MbedStudio-1.3.0.exe

Please only keep in mind that Mbed Studio has auto-update enabled. It means that 1.3.0 version will be automatically updated to 1.3.1. You can find information on how to disable auto-update in this post: Mbed studio 1.2 won't detect platform - #17 by arekzaluski

Thanks,
Arek - Studio team

Hi Arek,

Thanks for your quick reply.

Your first solution did not work. The result was exactly the same. Moreover, I had to run it as administrator, so I had to find the whole context used by Mbed Studio (I did not want to run Mbed Studio itself as administrator):

cmd.exe /K "set PATH=c:\ProgramData\Mbed^ Studio\mbed-studio-tools\python;c:\ProgramData\Mbed^ Studio\mbed-studio-tools\python\Scripts;c:\ProgramData\Mbed^ Studio\mbed-studio-tools\git\cmd;c:\ProgramData\Mbed^ Studio\mbed-studio-tools\gcc\bin;%PATH%"

Upgrading pyOCD to 0.28.3 did not work either.

I will now try to downgrade Mbed Studio and to disable the auto-update feature. Thanks for the link.

Well, surprisingly, downgrading to 1.3.0 did not help. I have no idea what’s going on. The board can be flashed, but the debugger won’t start, still with the same error messages.

It turns out that the pyocd.core.exceptions.TransferFaultError: SWD/JTAG Transfer Fault issue was not caused by Mbed Studio 1.3.1, but by the choice of the program to debug, namely the regular Blinky Mbed OS example, unmodified, using the Debug build profile. More specifically, it was the use of ThisThread::sleep_for() that was breaking everything.

Adding the following lines at the beginning of main() fixed the issue:

#ifdef MBED_DEBUG
    HAL_DBGMCU_EnableDBGSleepMode();
#endif

This function sets a bit required on this target to make the debug mode work properly with the WFI instruction:

/**
  * @brief  Enable the Debug Module during SLEEP mode.
  * @retval None
  */
void HAL_DBGMCU_EnableDBGSleepMode(void)
{
  SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
}

The fact that this change is required in Mbed Studio does not seem normal to me, for two reasons:

  • One would expect to be able to run or debug this example on all Mbed-OS-supported platforms without having to modify it. It would be more natural if this bit were set by Mbed Studio (using Mbed OS or pyOCD) either if the Debug build profile is selected or when the debugger is started.
  • According to this page of the Mbed documentation, the sleep mode is supposed to be disabled for the Debug build profile, but this is actually not the case: the mbed-os-example-blinky\BUILD\NUCLEO_L476RG\ARMC6\.profile* files set DEVICE_SLEEP=1 for this build profile.

This hardware requirement applies to many other Cortex-M targets supported by Mbed OS. I don’t know how Mbed Studio handles it for these other targets.

I will edit the title of this topic to reflect my latest findings.

1 Like

Hi Benoît,

Thank You for your extended investigation. We appreciate it. There used to be a problem with ThisThread::sleep_for() and pyOCD in the past but it was resolved from what I remember. Apparently, there is still a case when it doesn’t work correctly. We will investigate it with pyOCD team next week. I’ll let you know when I have more information.

Thanks,
Arek - Mbed Studio team

Hi Arek,

You are probably referring to this issue, which I found while investigating:

The mentioned MCU erratum requiring 3 NOPs after WFI does not apply to the STM32L476RG. As to the current topic, there are two issues, as explained in my previous post:

  • Whether the sleep mode should be enabled or not with the Debug build profile: Mbed documentation vs. DEVICE_SLEEP=1. Both choices are technically possible, but the documentation should match what Mbed Studio actually does.
  • When the debugger is used with the sleep mode enabled, who or what is responsible for setting DBGMCU_CR_DBG_SLEEP so that the debugger is not broken by WFI:
    • The end user, by adding a call to HAL_DBGMCU_EnableDBGSleepMode() in the source code to debug?
    • Mbed OS, by adding this call to the early initialization code executed before main() for this target and enabling it if the Debug profile is selected?
      #if defined(MBED_DEBUG) && DEVICE_SLEEP
          HAL_DBGMCU_EnableDBGSleepMode();
      #endif
      
    • Mbed Studio or pyOCD, by setting this bit thanks to a debugger initialization script?

Just in case someone else faced this same issue recently, this still being a problem on Mbed OS 6.17.0, with this topic board. The call HAL_DBGMCU_EnableDBGSleepMode() also solved this issue for me, but I’ve come across with another workaround, just in case.