stm32f1-pinctrl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2017 Linaro Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef ZEPHYR_STM32_PINCTRLF1_H_
  7. #define ZEPHYR_STM32_PINCTRLF1_H_
  8. #include <dt-bindings/pinctrl/stm32-pinctrl-common.h>
  9. /* Adapted from Linux: include/dt-bindings/pinctrl/stm32-pinfunc.h */
  10. /**
  11. * @brief Macro to generate pinmux int using port, pin number and mode arguments
  12. * This is adapted from Linux equivalent st,stm32f429-pinctrl binding
  13. */
  14. #define PIN_NO(port, line) (((port) - 'A') * 0x10 + (line))
  15. #define STM32F1_PINMUX(port, line, mode, remap) \
  16. (((PIN_NO(port, line)) << 8) | (mode << 6) | (remap))
  17. /**
  18. * @brief Pin modes
  19. */
  20. #define ALTERNATE 0x0 /* Alternate function output */
  21. #define GPIO_IN 0x1 /* Input */
  22. #define ANALOG 0x2 /* Analog */
  23. /**
  24. * @brief Pin remapping configurations
  25. */
  26. #define NO_REMAP 0x0 /* No remapping */
  27. #define REMAP_1 0x1 /* Partial remapping 1 */
  28. #define REMAP_2 0x2 /* Partial remapping 2 */
  29. #define REMAP_3 0x3 /* Partial remapping 3 */
  30. #define REMAP_FULL 0x4 /* Full remapping */
  31. /**
  32. * @brief PIN configuration bitfield
  33. *
  34. * Pin configuration is coded with the following
  35. * fields
  36. * GPIO I/O Mode [ 0 ]
  37. * GPIO Input config [ 1 : 2 ]
  38. * GPIO Output speed [ 3 : 4 ]
  39. * GPIO Output PP/OD [ 5 ]
  40. * GPIO Output AF/GP [ 6 ]
  41. * GPIO PUPD Config [ 7 : 8 ]
  42. *
  43. * Applicable to STM32F1 series
  44. */
  45. /* Alternate functions */
  46. /* STM32F1 Pinmux doesn't use explicit alternate functions */
  47. /* These are kept for compatibility with other STM32 pinmux */
  48. #define STM32_AFR_MASK 0
  49. #define STM32_AFR_SHIFT 0
  50. /* Port Mode */
  51. #define STM32_MODE_INPUT (0x0<<STM32_MODE_INOUT_SHIFT)
  52. #define STM32_MODE_OUTPUT (0x1<<STM32_MODE_INOUT_SHIFT)
  53. #define STM32_MODE_INOUT_MASK 0x1
  54. #define STM32_MODE_INOUT_SHIFT 0
  55. /* Input Port configuration */
  56. #define STM32_CNF_IN_ANALOG (0x0<<STM32_CNF_IN_SHIFT)
  57. #define STM32_CNF_IN_FLOAT (0x1<<STM32_CNF_IN_SHIFT)
  58. #define STM32_CNF_IN_PUPD (0x2<<STM32_CNF_IN_SHIFT)
  59. #define STM32_CNF_IN_MASK 0x3
  60. #define STM32_CNF_IN_SHIFT 1
  61. /* Output Port configuration */
  62. #define STM32_MODE_OUTPUT_MAX_10 (0x0<<STM32_MODE_OSPEED_SHIFT)
  63. #define STM32_MODE_OUTPUT_MAX_2 (0x1<<STM32_MODE_OSPEED_SHIFT)
  64. #define STM32_MODE_OUTPUT_MAX_50 (0x2<<STM32_MODE_OSPEED_SHIFT)
  65. #define STM32_MODE_OSPEED_MASK 0x3
  66. #define STM32_MODE_OSPEED_SHIFT 3
  67. #define STM32_CNF_PUSH_PULL (0x0<<STM32_CNF_OUT_0_SHIFT)
  68. #define STM32_CNF_OPEN_DRAIN (0x1<<STM32_CNF_OUT_0_SHIFT)
  69. #define STM32_CNF_OUT_0_MASK 0x1
  70. #define STM32_CNF_OUT_0_SHIFT 5
  71. #define STM32_CNF_GP_OUTPUT (0x0<<STM32_CNF_OUT_1_SHIFT)
  72. #define STM32_CNF_ALT_FUNC (0x1<<STM32_CNF_OUT_1_SHIFT)
  73. #define STM32_CNF_OUT_1_MASK 0x1
  74. #define STM32_CNF_OUT_1_SHIFT 6
  75. /* GPIO High impedance/Pull-up/Pull-down */
  76. #define STM32_PUPD_NO_PULL (0x0<<STM32_PUPD_SHIFT)
  77. #define STM32_PUPD_PULL_UP (0x1<<STM32_PUPD_SHIFT)
  78. #define STM32_PUPD_PULL_DOWN (0x2<<STM32_PUPD_SHIFT)
  79. #define STM32_PUPD_MASK 0x3
  80. #define STM32_PUPD_SHIFT 7
  81. /* Alternate defines */
  82. /* IO pin functions are mostly common across STM32 devices. Notable
  83. * exception is STM32F1 as these MCUs do not have registers for
  84. * configuration of pin's alternate function. The configuration is
  85. * done implicitly by setting specific mode and config in MODE and CNF
  86. * registers for particular pin.
  87. */
  88. #define STM32_ALTERNATE (STM32_MODE_OUTPUT | STM32_CNF_ALT_FUNC)
  89. #define STM32_PIN_USART_TX (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  90. #define STM32_PIN_USART_RX (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  91. #define STM32_PIN_I2C (STM32_ALTERNATE | STM32_CNF_OPEN_DRAIN)
  92. #define STM32_PIN_PWM (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  93. #define STM32_PIN_SPI_MASTER_SCK (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  94. #define STM32_PIN_SPI_SLAVE_SCK (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  95. #define STM32_PIN_SPI_MASTER_MOSI (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  96. #define STM32_PIN_SPI_SLAVE_MOSI (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  97. #define STM32_PIN_SPI_MASTER_MISO (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  98. #define STM32_PIN_SPI_SLAVE_MISO (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  99. #define STM32_PIN_CAN_TX (STM32_ALTERNATE | STM32_CNF_PUSH_PULL)
  100. #define STM32_PIN_CAN_RX (STM32_MODE_INPUT | STM32_PUPD_PULL_UP)
  101. /*
  102. * Reference manual (RM0008)
  103. * Section 25.3.1: Slave select (NSS) pin management
  104. *
  105. * Hardware NSS management:
  106. * - NSS output disabled: allows multimaster capability for devices operating
  107. * in master mode.
  108. * - NSS output enabled: used only when the device operates in master mode.
  109. *
  110. * Software NSS management:
  111. * - External NSS pin remains free for other application uses.
  112. *
  113. */
  114. /* Hardware master NSS output disabled */
  115. #define STM32_PIN_SPI_MASTER_NSS (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  116. /* Hardware master NSS output enabled */
  117. #define STM32_PIN_SPI_MASTER_NSS_OE (STM32_MODE_OUTPUT | \
  118. STM32_CNF_ALT_FUNC | \
  119. STM32_CNF_PUSH_PULL)
  120. #define STM32_PIN_SPI_SLAVE_NSS (STM32_MODE_INPUT | STM32_CNF_IN_FLOAT)
  121. #define STM32_PIN_USB (STM32_MODE_INPUT | STM32_CNF_IN_PUPD)
  122. #endif /* ZEPHYR_STM32_PINCTRLF1_H_ */