PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/platforms/swlink/platform.h

https://github.com/esden/blackmagic
C Header | 187 lines | 129 code | 20 blank | 38 comment | 0 complexity | 60c85ea6358f90b68f53da427bcec868 MD5 | raw file
  1. /*
  2. * This file is part of the Black Magic Debug project.
  3. *
  4. * Copyright (C) 2011 Black Sphere Technologies Ltd.
  5. * Written by Gareth McMullin <gareth@blacksphere.co.nz>
  6. * Copyright (C) 2018 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de)
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /* This file implements the platform specific functions for the STM32
  22. * implementation.
  23. */
  24. #ifndef __PLATFORM_H
  25. #define __PLATFORM_H
  26. #include "gpio.h"
  27. #include "timing.h"
  28. #include "timing_stm32.h"
  29. #ifdef ENABLE_DEBUG
  30. # define PLATFORM_HAS_DEBUG
  31. # define USBUART_DEBUG
  32. extern bool debug_bmp;
  33. int usbuart_debug_write(const char *buf, size_t len);
  34. #endif
  35. #define PLATFORM_IDENT "(SWLINK) "
  36. /* Hardware definitions... */
  37. #define TMS_PORT GPIOA
  38. #define TCK_PORT GPIOA
  39. #define TDI_PORT GPIOA
  40. #define TDO_PORT GPIOB
  41. #define JRST_PORT GPIOB
  42. #define TMS_PIN GPIO13
  43. #define TCK_PIN GPIO14
  44. #define TDI_PIN GPIO15
  45. #define TDO_PIN GPIO3
  46. #define JRST_PIN GPIO4
  47. #define SWDIO_PORT TMS_PORT
  48. #define SWCLK_PORT TCK_PORT
  49. #define SWDIO_PIN TMS_PIN
  50. #define SWCLK_PIN TCK_PIN
  51. /* Use PC14 for a "dummy" uart led. So we can observere at least with scope*/
  52. #define LED_PORT_UART GPIOC
  53. #define LED_UART GPIO14
  54. #define PLATFORM_HAS_TRACESWO 1
  55. #define NUM_TRACE_PACKETS (128) /* This is an 8K buffer */
  56. #define TRACESWO_PROTOCOL 2 /* 1 = Manchester, 2 = NRZ / async */
  57. # define SWD_CR GPIO_CRH(SWDIO_PORT)
  58. # define SWD_CR_MULT (1 << ((13 - 8) << 2))
  59. #define TMS_SET_MODE() \
  60. gpio_set_mode(TMS_PORT, GPIO_MODE_OUTPUT_2_MHZ, \
  61. GPIO_CNF_OUTPUT_PUSHPULL, TMS_PIN);
  62. #define SWDIO_MODE_FLOAT() do { \
  63. uint32_t cr = SWD_CR; \
  64. cr &= ~(0xf * SWD_CR_MULT); \
  65. cr |= (0x4 * SWD_CR_MULT); \
  66. SWD_CR = cr; \
  67. } while(0)
  68. #define SWDIO_MODE_DRIVE() do { \
  69. uint32_t cr = SWD_CR; \
  70. cr &= ~(0xf * SWD_CR_MULT); \
  71. cr |= (0x1 * SWD_CR_MULT); \
  72. SWD_CR = cr; \
  73. } while(0)
  74. #define UART_PIN_SETUP() do { \
  75. AFIO_MAPR |= AFIO_MAPR_USART1_REMAP; \
  76. gpio_set_mode(USBUSART_PORT, GPIO_MODE_OUTPUT_50_MHZ, \
  77. GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, USBUSART_TX_PIN); \
  78. gpio_set_mode(USBUSART_PORT, GPIO_MODE_INPUT, \
  79. GPIO_CNF_INPUT_PULL_UPDOWN, USBUSART_RX_PIN); \
  80. gpio_set(USBUSART_PORT, USBUSART_RX_PIN); \
  81. } while(0)
  82. #define USB_DRIVER st_usbfs_v1_usb_driver
  83. #define USB_IRQ NVIC_USB_LP_CAN_RX0_IRQ
  84. #define USB_ISR(x) usb_lp_can_rx0_isr(x)
  85. /* Interrupt priorities. Low numbers are high priority.
  86. * TIM2 is used for traceswo capture and must be highest priority.
  87. */
  88. #define IRQ_PRI_USB (1 << 4)
  89. #define IRQ_PRI_USBUSART (2 << 4)
  90. #define IRQ_PRI_USBUSART_DMA (2 << 4)
  91. #define IRQ_PRI_USB_VBUS (14 << 4)
  92. #define IRQ_PRI_SWO_DMA (0 << 4)
  93. #define USBUSART USART1
  94. #define USBUSART_CR1 USART1_CR1
  95. #define USBUSART_DR USART1_DR
  96. #define USBUSART_IRQ NVIC_USART1_IRQ
  97. #define USBUSART_CLK RCC_USART1
  98. #define USBUSART_PORT GPIOB
  99. #define USBUSART_TX_PIN GPIO6
  100. #define USBUSART_RX_PIN GPIO7
  101. #define USBUSART_ISR(x) usart1_isr(x)
  102. #define USBUSART_DMA_BUS DMA1
  103. #define USBUSART_DMA_CLK RCC_DMA1
  104. #define USBUSART_DMA_TX_CHAN DMA_CHANNEL4
  105. #define USBUSART_DMA_TX_IRQ NVIC_DMA1_CHANNEL4_IRQ
  106. #define USBUSART_DMA_TX_ISR(x) dma1_channel4_isr(x)
  107. #define USBUSART_DMA_RX_CHAN DMA_CHANNEL5
  108. #define USBUSART_DMA_RX_IRQ NVIC_DMA1_CHANNEL5_IRQ
  109. #define USBUSART_DMA_RX_ISR(x) dma1_channel5_isr(x)
  110. #define TRACE_TIM TIM2
  111. #define TRACE_TIM_CLK_EN() rcc_periph_clock_enable(RCC_TIM2)
  112. #define TRACE_IRQ NVIC_TIM2_IRQ
  113. #define TRACE_ISR(x) tim2_isr(x)
  114. #define TRACE_IC_IN TIM_IC_IN_TI2
  115. #define TRACE_TRIG_IN TIM_SMCR_TS_IT1FP2
  116. /* On F103, only USART1 is on AHB2 and can reach 4.5 MBaud at 72 MHz.
  117. * USART1 is already used. sp maximum speed is 2.25 MBaud. */
  118. #define SWO_UART USART2
  119. #define SWO_UART_DR USART2_DR
  120. #define SWO_UART_CLK RCC_USART2
  121. #define SWO_UART_PORT GPIOA
  122. #define SWO_UART_RX_PIN GPIO3
  123. /* This DMA channel is set by the USART in use */
  124. #define SWO_DMA_BUS DMA1
  125. #define SWO_DMA_CLK RCC_DMA1
  126. #define SWO_DMA_CHAN DMA_CHANNEL6
  127. #define SWO_DMA_IRQ NVIC_DMA1_CHANNEL6_IRQ
  128. #define SWO_DMA_ISR(x) dma1_channel6_isr(x)
  129. #define LED_PORT GPIOC
  130. #define LED_IDLE_RUN GPIO15
  131. #define SET_RUN_STATE(state)
  132. #define SET_ERROR_STATE(state)
  133. extern void set_idle_state(int state);
  134. #define SET_IDLE_STATE(state) set_idle_state(state)
  135. extern uint8_t detect_rev(void);
  136. /*
  137. * Use newlib provided integer only stdio functions
  138. */
  139. /* sscanf */
  140. #ifdef sscanf
  141. #undef sscanf
  142. #define sscanf siscanf
  143. #else
  144. #define sscanf siscanf
  145. #endif
  146. /* sprintf */
  147. #ifdef sprintf
  148. #undef sprintf
  149. #define sprintf siprintf
  150. #else
  151. #define sprintf siprintf
  152. #endif
  153. /* vasprintf */
  154. #ifdef vasprintf
  155. #undef vasprintf
  156. #define vasprintf vasiprintf
  157. #else
  158. #define vasprintf vasiprintf
  159. #endif
  160. /* snprintf */
  161. #ifdef snprintf
  162. #undef snprintf
  163. #define snprintf sniprintf
  164. #else
  165. #define snprintf sniprintf
  166. #endif
  167. #endif