swd.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * This Source Code Form is subject to the terms of the MIT License.
  3. * If a copy of the MIT License was not distributed with this file,
  4. * you can obtain one at https://opensource.org/licenses/MIT
  5. */
  6. #ifndef INC_SWD_H
  7. #define INC_SWD_H
  8. #include <stdint.h>
  9. #define RCC_AHBENR_GPIO_SWDIO (RCC_AHBENR_GPIOAEN)
  10. #define RCC_AHBENR_GPIO_SWCLK (RCC_AHBENR_GPIOAEN)
  11. #define GPIO_SWDIO (GPIOA)
  12. #define PIN_SWDIO (13u)
  13. #define GPIO_SWCLK (GPIOA)
  14. #define PIN_SWCLK (14u)
  15. /* Internal SWD status. There exist combined SWD status values (e.g. 0x60), since subsequent command replys are OR'ed. Thus there exist cases where the previous command executed correctly (returned 0x20) and the following command failed (returned 0x40), resulting in 0x60. */
  16. typedef enum {
  17. // TODO: 0xA0 fehlt.
  18. swdStatusNone = 0x00u, /* No status available (yet) */
  19. swdStatusOk = 0x20u, /* Status OK */
  20. swdStatusWait = 0x40u, /* Wait/Retry requested (bus access was not granted in time) */
  21. swdStatusWaitOK = 0x60u, /* Wait requested + additional OK (previous command OK, but no bus access) */
  22. swdStatusFault = 0x80u, /* Fault during command execution (command error (access denied etc.)) */
  23. swdStatusFaultOK = 0xA0u, /* Fault during command execution, previous command was successful */
  24. swdStatusFailure = 0xE0u /* Failure during communication (check connection, no valid status reply received) */
  25. } swdStatus_t;
  26. typedef enum {
  27. swdPortSelectDP = 0x00u,
  28. swdPortSelectAP = 0x01u
  29. } swdPortSelect_t;
  30. typedef enum {
  31. swdAccessDirectionWrite = 0x00u,
  32. swdAccessDirectionRead = 0x01u
  33. } swdAccessDirection_t;
  34. void swdCtrlInit( void );
  35. swdStatus_t swdEnableDebugIF( void );
  36. swdStatus_t swdReadIdcode( uint32_t * const idCode );
  37. swdStatus_t swdSelectAPnBank(uint8_t const ap, uint8_t const bank);
  38. swdStatus_t swdReadAHBAddr( uint32_t const addr, uint32_t * const data );
  39. swdStatus_t swdInit( uint32_t * const idcode );
  40. swdStatus_t swdSetAP32BitMode( uint32_t * const data );
  41. swdStatus_t swdSelectAHBAP( void );
  42. #endif