xref: /aosp_15_r20/external/pigweed/pw_sys_io_stm32cube/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1.. _module-pw_sys_io_stm32cube:
2
3-------------------
4pw_sys_io_stm32cube
5-------------------
6
7``pw_sys_io_stm32cube`` implements the ``pw_sys_io`` facade over UART using
8the STM32Cube HAL to support an assortment of boards from STMicroelectronics.
9
10The UART baud rate is fixed at 115200 (8N1).
11
12Setup
13=====
14This module requires relatively minimal setup:
15
161. Write code against the ``pw_sys_io`` facade.
172. Specify the ``dir_pw_sys_io_backend`` GN global variable to point to this
18   backend.
193. Call ``pw_sys_io_Init()`` during init so the UART is properly initialized
20   and configured.
21
22For devices other than the STM32F429I-DISC1, this module will need to be
23configured to use the appropriate GPIO pins and USART peripheral.
24
25Module Configuration Options
26============================
27The following configurations can be adjusted via compile-time configuration of
28this module, see the
29:ref:`module documentation <module-structure-compile-time-configuration>` for
30more details.
31
32.. c:macro:: PW_SYS_IO_STM32CUBE_USART_NUM
33
34  The USART peripheral number to use. (1 for USART1, 2 for USART2, etc.)
35
36.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_PORT
37
38  The port that the USART peripheral TX/RX pins are on. (e.g. to use A9/A10
39  pins for TX and RX, respectively, set this to A)
40
41.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_TX_PORT
42
43  The port for the USART peripheral TX pin, if different from
44  PW_SYS_IO_STM32CUBE_GPIO_PORT.
45
46.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_RX_PORT
47
48  The port for the USART peripheral RX pin, if different from
49  PW_SYS_IO_STM32CUBE_GPIO_PORT.
50
51.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_TX_PIN
52
53  The pin index to use for USART transmission within the port set by
54  ``PW_SYS_IO_STM32CUBE_GPIO_PORT``.
55
56.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_RX_PIN
57
58  The pin index to use for USART reception within the port set by
59  ``PW_SYS_IO_STM32CUBE_GPIO_PORT``.
60
61.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_AF
62
63  The alternate function index to use for USART reception within the port set by
64  ``PW_SYS_IO_STM32CUBE_GPIO_PORT``.
65
66.. c:macro:: PW_SYS_IO_STM32CUBE_GPIO_REMAP
67
68  Remap alternate function for USART reception (either ENABLE or DISABLE). It
69  only applies to the stm32f1xx family.
70
71.. c:macro:: PW_SYS_IO_STM32CUBE_USART_PREFIX
72
73  The peripheral name prefix (either UART or USART) for the peripheral selected
74  by ``PW_SYS_IO_STM32CUBE_USART_NUM``. Defaults to USART.
75
76Module usage
77============
78After building an executable that utilizes this backend, flash the
79produced .elf binary to the development board. Then, using a serial
80communication terminal like minicom/screen (Linux/Mac) or TeraTerm (Windows),
81connect to the device at a baud rate of 115200 (8N1). If you're not using a
82STM32F429I-DISC1 development board, manually connect a USB-to-serial TTL adapter
83to pins ``PA9`` (MCU TX) and ``PA10`` (MCU RX), making sure to match logic
84levels (e.g. 3.3V versus 1.8V).
85
86Sample connection diagram
87-------------------------
88
89.. code-block:: text
90
91   --USB Serial--+    +-----STM32F429 MCU-----
92                 |    |
93              TX o--->o PA10/USART1_RX
94                 |    |
95              RX o<---o PA9/USART1_TX
96                 |    |
97   --------------+    +-----------------------
98