brewで入れたopneOCDに付属しているnucleo用のコンフィグファイルだと、プログラムのダウンロードに失敗します。
結果
どうもst_nucleo_f3.cfgの中身を見ると NUCLEO F334R8 用のようで、F303K8用ではないようです。
そこでCubeIDEで、デバッガとしてOpneOCDを選択したとき生成される"プロジェクト名 Debug.cfg"というファイルを持ってきます。CubeIDEのプロジェクトルートにできますので、自分のディレクトにリネームして突っ込んでおくか、Gitで管理するならプロジェクトのルートにコピーしておきます。
めでたくブレークポイントで止まっています。
違いは何かというと、openOCDについているものは
# SPDX-License-Identifier: GPL-2.0-or-later
# This is an ST NUCLEO F334R8 board with a single STM32F334R8T6 chip.
# http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260004
source [find interface/stlink.cfg]
transport select hla_swd
source [find target/stm32f3x.cfg]
reset_config srst_only
一方CubeIDEが生成しているものは
# This is an NUCLEO-F303K8 board with a single STM32F303K8Tx chip
#
# Generated by STM32CubeIDE
# Take care that such file, as generated, may be overridden without any
# early notice. Please have a look to debug launch configuration setup(s)
source [find interface/stlink-dap.cfg]
set WORKAREASIZE 0x1000
transport select "dapdirect_swd"
set CHIPNAME STM32F303K8Tx
set BOARDNAME NUCLEO-F303K8
# Enable debug when in low power modes
set ENABLE_LOW_POWER 1
# Stop Watchdog counters when halt
set STOP_WATCHDOG 1
# STlink Debug clock frequency
set CLOCK_FREQ 8000
# Reset configuration
# use hardware reset, connect under reset
# connect_assert_srst needed if low power mode application running (WFI...)
reset_config srst_only srst_nogate connect_assert_srst
set CONNECT_UNDER_RESET 1
set CORE_RESET 0
# ACCESS PORT NUMBER
set AP_NUM 0
# GDB PORT
set GDB_PORT 3333
# BCTM CPU variables
source [find target/stm32f3x.cfg]
と色々設定しています。
stlink-dap.cfgをstlink.cfgとしても動きます。
色々コメントアウトしてみたところ、
set WORKAREASIZE 0x1000
という所が効いているようです。
F303K8用のcfgファイルも用意しておいて頂けると助かるんですが。。。
ということで、うんと簡素化すると
# For NUCLEO F303K8
source [find interface/stlink.cfg]
set WORKAREASIZE 0x1000
source [find target/stm32f3x.cfg]
で動いています(WDTはプログラムの中で無効化してます)。
stlink.cfgの中にはST_LinkのUSBのVID, PIDの組が
列挙されていますが、strageあり・なし両方のPIDが書かれているので
どちらでもデバッガとしては問題なく動作します。
他のNucleoボードもこれでいけるのでは。