开贴记录SWD 脱机烧录器开发过程,请各路大神指教

2019-12-09 19:23发布

参考 CMISI_DAP,BlackMagic代码。
预备下周末结案,目前方案:
1:Host用STM32F427,跑RTEMS系统, IO口模拟SWD时序。
2:flash的操作函数,由Host通过SWD下载入target ram执行。(CMISI_DAP采用这种方式)
     不知道jlink的flash操作是不是一样的原理。他要适用这么多芯片,那得有准备多少这样的小程序啊。。。
3:USB用的虚拟串口,用ST官方提供的驱动,上位机编程简单。tafget本身程序.bin文件由上位机通过虚拟串口传入。
     此虚拟串口的波特率,奇偶,起停位设置均形同虚设。

目前状态:
SWD时序基本调试通过,读写target ID/reg已经正常,暂时未经过高强度测试。。
正在弄flash操作。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
94条回答
shangdawei
2019-12-13 09:32
swddude -- A SWD programmer for ARM Cortex microcontrollers.

需要提供底层驱动

swddude-master.zip (55.88 KB, 下载次数: 107) 2015-8-22 21:18 上传 点击文件名下载附件



  1. #ifndef SWD_H
  2. #define SWD_H

  3. /*
  4. * Abstract base class for SWD interface drivers.
  5. */

  6. #include "libs/error/error_stack.h"

  7. #include <stdint.h>

  8. /*
  9. * SWDDriver provides a low-level interface to SWD interface devices.
  10. * Each function maps directly to a SWD protocol concept.  The ARM ADIv5
  11. * specification explains the SWD protocol in more detail; it's available
  12. * behind a clickwrap license on ARM's site.
  13. *
  14. * Client software should rarely interact with SWDDriver directly.  Instead,
  15. * wrap it in another object that provides a higher-level more pleasant
  16. * interface with support for things like retries and named registers.
  17. */
  18. class SWDDriver {
  19. public:
  20.     /*
  21.      * Creates an instance of the driver.  Because the constructor can't
  22.      * return any meaningful error condition, implementations should only do
  23.      * things that can't fail -- such as copying in constructor arguments
  24.      * and initializing memory.
  25.      */
  26.     SWDDriver() {}

  27.     /*
  28.      * Destroys this driver instance.  Because the destructor can't return
  29.      * any meaningful error condition, any resource cleanup here is
  30.      * last-resort.  Clients should call the close() function to clean up
  31.      * resources in a way that can report errors.  Destructor
  32.      * implementations may optionally log attempts to destroy a driver
  33.      * instance without calling close(), as this indicates a programming
  34.      * error.
  35.      */
  36.     virtual ~SWDDriver() {}

  37.     /*
  38.      * Initialize the SWD link to the target, per the "Connection and line
  39.      * reset sequence" defined by the ARM ADI v5.  This has two parts:
  40.      *   1. 50 clocks with the SWDIO line held high by the master.
  41.      *   2. A read of the IDCODE register in the DP.
  42.      *
  43.      * Because this function reads IDCODE behind the scenes, it can
  44.      * optionally return it to the application through the pointer argument.
  45.      *
  46.      * If this function returns successfully, it indicates that the
  47.      * interface is functioning, and that an attached microprocessor has
  48.      * responded to us.  The state of the target is unknown -- in
  49.      * particular, the contents of the Debug Access Port's SELECT and
  50.      * CTRL/STAT registers are undefined.
  51.      *
  52.      * Return values:
  53.      *  Err::success - initialization complete, target responded, IDCODE
  54.      *                 valid.
  55.      *  Err::failure - initialization failed or target failed to respond.
  56.      */
  57.     virtual Err::Error initialize(uint32_t * idcode_out = 0) = 0;

  58.     /*
  59.      * Asserts the target's reset line continuously until a call to
  60.      * leave_reset.
  61.      *
  62.      * Return values:
  63.      *  Err::success - reset asserted.
  64.      *  Err::failure - communications with interface failed.
  65.      */
  66.     virtual Err::Error enter_reset() = 0;

  67.     /*
  68.      * Deasserts the target's reset line, allowing it to run.
  69.      *
  70.      * Return values:
  71.      *  Err::success - reset deasserted.
  72.      *  Err::failure - communications with interface failed.
  73.      */
  74.     virtual Err::Error leave_reset() = 0;

  75.     /*
  76.      * Reads a 32-bit register from either the Debug Access Port (when
  77.      * debug_port is true) or the Access Port bank named in the DAP's SELECT
  78.      * register (when debug_port is false).
  79.      *
  80.      * Access Port reads are delayed: each read returns the result of the
  81.      * previous operation.  To kick off a read without retrieving the
  82.      * results of the last one, pass a data pointer of zero; the result
  83.      * won't be written.  To retrieve the results of the last Access Port
  84.      * read without starting a new one, read the Debug Access Port's RDBUFF
  85.      * register instead.  
  86.      *
  87.      * Note that some registers can only be accessed in particular states of
  88.      * the CTRL/STAT register, and some registers can't be read at all.
  89.      *
  90.      * Refer to the ARM ADIv5 spec for more information.
  91.      *
  92.      * Implementation note: drivers should implement this function such that
  93.      * it will work regardless of mode.  In particular, it must not assume
  94.      * that Overrun Detection is enabled in the DAP.
  95.      *
  96.      * Return values:
  97.      *  Err::success   - read completed, data valid.
  98.      *  Err::try_again - target returned SWD WAIT response, read not
  99.      *                   completed.
  100.      *  Err::failure   - read failed, either in the interface or due to SWD
  101.      *                   FAULT.
  102.      */
  103.     virtual Err::Error read(unsigned   address,
  104.                             bool       debug_port,
  105.                             uint32_t * data) = 0;

  106.     /*
  107.      * Writes a 32-bit value into a register in either the Debug Access Port
  108.      * (when debug_port is true) or the Access Port bank named in the DAP's
  109.      * SELECT register (when debug_port is false).
  110.      *
  111.      * Access Port writes may take time to complete.  For a MEM-AP, monitor
  112.      * the status of the TrInProg (transaction in progress) bit of the
  113.      * Access Port's CSW register to detect when another write may be
  114.      * issued.
  115.      *
  116.      * Note that some registers can only be accessed in particular states of
  117.      * the CTRL/STAT register, and some registers can't be written at all.
  118.      *
  119.      * Refer to the ARM ADIv5 spec for more information.
  120.      *
  121.      * Implementation note: drivers should implement this function such that
  122.      * it will work regardless of mode.  In particular, it must not assume
  123.      * that Overrun Detection is enabled in the DAP.
  124.      *
  125.      * Return values:
  126.      *  Err::success   - write completed.
  127.      *  Err::try_again - target returned SWD WAIT response, write not
  128.      *                   completed.
  129.      *  Err::failure   - write failed, either in the interface or due to SWD
  130.      *                   FAULT.
  131.      */
  132.     virtual Err::Error write(unsigned address,
  133.                              bool     debug_port,
  134.                              uint32_t data) = 0;
  135. };

  136. #endif  // SWD_H
复制代码

一周热门 更多>