[PSOC™] 【英飞凌PSOC 4000T DIY】串行通信接口之UART

[复制链接]
 楼主| 南来之风 发表于 2025-4-22 21:24 | 显示全部楼层 |阅读模式
PSOC™ 4000T有两路SCB即Serial Communication Block,可以被配置为SPI、I2C和UART。

这是一个全功能的UART,运行速度高达1mbps。此外,它还支持9位多处理器模式,允许通过普通RX和TX线路连接的外设寻址。该模块支持常见的UART功能,如奇偶校验、中断检测和帧错误。

从数据手册看到,P2.2,P2.3可以分别用于uart.rx与uart.tx。


硬件实物:

打开Modus IDE,点击New Application开始创建新的工程。

选择器件型号:

选择外设UART:

点击Device Configurator,进入图形化外设配置界面。

配置SCB 0为UART模式。TX P2.3, RX P2.2, 115200等参数。


实物照片:

核心代码:
  1. int main(void)
  2. {
  3.     cy_rslt_t result;
  4.     uint32_t read_data;
  5.     cy_en_scb_uart_status_t initstatus;

  6.     /* Turn off the USER LED */
  7.     Cy_GPIO_Write(CYBSP_LED1_PORT, CYBSP_LED1_NUM, LED_OFF);

  8.     /* Initialize the device and board peripherals */
  9.     result = cybsp_init() ;

  10.     /* Board init failed. Stop program execution */
  11.     if (result != CY_RSLT_SUCCESS)
  12.     {
  13.         CY_ASSERT(0);
  14.     }

  15.     /* Initialize the UART */
  16.     initstatus = Cy_SCB_UART_Init(CYBSP_UART_HW, &CYBSP_UART_config, &CYBSP_UART_context);

  17.     /* Initialization failed. Handle error */
  18.     if(initstatus!=CY_SCB_UART_SUCCESS)
  19.     {
  20.         handle_error();
  21.     }

  22.     /* Enable global interrupts */
  23.     __enable_irq();

  24.     Cy_SCB_UART_Enable(CYBSP_UART_HW);

  25.     /* Transmit Header to the Terminal */
  26.     Cy_SCB_UART_PutString(CYBSP_UART_HW, "\x1b[2J\x1b[;H");
  27.     Cy_SCB_UART_PutString(CYBSP_UART_HW, "***********************************************************\r\n");
  28.     Cy_SCB_UART_PutString(CYBSP_UART_HW, "PSoC 4 MCU UART transmit and receive\r\n");
  29.     Cy_SCB_UART_PutString(CYBSP_UART_HW, "***********************************************************\r\n\n");
  30.     Cy_SCB_UART_PutString(CYBSP_UART_HW, ">> Start typing to see the echo on the screen \r\n\n");

  31.    for (;;)
  32.     {
  33.         /* Check if there is a received character from user console */
  34.         if (0UL != Cy_SCB_UART_GetNumInRxFifo(CYBSP_UART_HW))
  35.         {
  36.             /* Re-transmit whatever the user types on the console */
  37.             read_data = Cy_SCB_UART_Get(CYBSP_UART_HW);
  38.             while (0UL == Cy_SCB_UART_Put(CYBSP_UART_HW,read_data))
  39.             {
  40.             }
  41.         }
  42.     }
  43. }


编译后,烧录:
  1. Started by GNU MCU Eclipse
  2. Open On-Chip Debugger 0.12.0+dev-5.7.0.3672 (2025-03-04-03:08)
  3. Licensed under GNU GPL v2
  4. For bug reports, read
  5.         http://openocd.org/doc/doxygen/bugs.html
  6. ********************************************************************************
  7. * !!! OBSOLETE target 'psoc4.cfg' - will be removed soon.                      *
  8. * Use 'infineon/psoc4.cfg' target instead.                                     *
  9. ********************************************************************************
  10. Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
  11. ** Auto-acquire enabled, use "set PSOC4_USE_ACQUIRE 0" to disable
  12. adapter speed: 2000 kHz
  13. Info : Using CMSIS-DAPv2 interface with VID:PID=0x04b4:0xf155, serial=0D04189E02272400
  14. Info : CMSIS-DAP: SWD supported
  15. Info : CMSIS-DAP: Atomic commands supported
  16. Info : CMSIS-DAP: FW Version = 2.0.0
  17. Info : CMSIS-DAP: Interface Initialised (SWD)
  18. Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
  19. Info : CMSIS-DAP: Interface ready
  20. Info : KitProg3: FW version: 2.70.1480
  21. Info : KitProg3: Pipelined transfers enabled
  22. Info : KitProg3: Asynchronous USB transfers enabled
  23. Info : VTarget = 3.317 V
  24. Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
  25. Info : clock speed 2000 kHz
  26. Info : SWD DPIDR 0x0bc11477
  27. Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
  28. Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
  29. *****************************************
  30. ** Silicon: 0x3612, Family: 0xC6, Rev.: 0x22 (B1)
  31. ** Detected Family: PSoC 4000T
  32. ** Detected Device: CY8C4046LQI-T452
  33. ** Detected Main Flash size, kb: 64
  34. ** Chip Protection: OPEN
  35. *****************************************
  36. Info : [psoc4.mem_ap] Examination succeed
  37. Info : [psoc4.cpu] Examination succeed
  38. Info : gdb port disabled
  39. Info : starting gdb server for psoc4.cpu on 3333
  40. Info : Listening on port 3333 for gdb connections
  41. Info : SWD DPIDR 0x0bc11477
  42. Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
  43. [psoc4.cpu] halted due to debug-request, current mode: Thread
  44. xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8
  45. ** Device acquired successfully
  46. Started by GNU MCU Eclipse
  47. Info : Listening on port 6666 for tcl connections
  48. Info : Listening on port 4444 for telnet connections
  49. Info : accepting 'gdb' connection on tcp/3333
  50. Info : New GDB Connection: 1, Target psoc4.cpu, state: halted
  51. Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
  52. Info : SWD DPIDR 0x0bc11477
  53. Error: Failed to read memory at 0x10000040
  54. semihosting is enabled
  55. Warn : No RTOS could be auto-detected!
  56. Warn : No RTOS could be auto-detected!
  57. Verifying region (0x00000000,      4712)... Mismatch
  58. Info : Data mismatch, proceeding with flash programming
  59. Info : Padding image section 0 at 0x00001268 with 24 bytes (bank write end alignment)
  60. Warn : Only mass erase available, erase skipped! (psoc4 mass_erase)

  61. [  5%] [#                               ] [ Programming ]
  62. [  8%] [##                              ] [ Programming ]
  63. [ 10%] [###                             ] [ Programming ]
  64. [ 13%] [####                            ] [ Programming ]
  65. [ 16%] [#####                           ] [ Programming ]
  66. [ 21%] [######                          ] [ Programming ]
  67. [ 24%] [#######                         ] [ Programming ]
  68. [ 27%] [########                        ] [ Programming ]
  69. [ 29%] [#########                       ] [ Programming ]
  70. [ 32%] [##########                      ] [ Programming ]
  71. [ 35%] [###########                     ] [ Programming ]
  72. [ 40%] [############                    ] [ Programming ]
  73. [ 43%] [#############                   ] [ Programming ]
  74. [ 45%] [##############                  ] [ Programming ]
  75. [ 48%] [###############                 ] [ Programming ]
  76. [ 51%] [################                ] [ Programming ]
  77. [ 54%] [#################               ] [ Programming ]
  78. [ 59%] [##################              ] [ Programming ]
  79. [ 62%] [###################             ] [ Programming ]
  80. [ 64%] [####################            ] [ Programming ]
  81. [ 67%] [#####################           ] [ Programming ]
  82. [ 70%] [######################          ] [ Programming ]
  83. [ 72%] [#######################         ] [ Programming ]
  84. [ 75%] [########################        ] [ Programming ]
  85. [ 81%] [#########################       ] [ Programming ]
  86. [ 83%] [##########################      ] [ Programming ]
  87. [ 86%] [###########################     ] [ Programming ]
  88. [ 89%] [############################    ] [ Programming ]
  89. [ 91%] [#############################   ] [ Programming ]
  90. [ 94%] [##############################  ] [ Programming ]
  91. [ 97%] [############################### ] [ Programming ]
  92. [100%] [################################] [ Programming ]
  93. Info : SWD DPIDR 0x0bc11477
  94. Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
  95. [psoc4.cpu] halted due to debug-request, current mode: Thread
  96. xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8, semihosting
  97. ** Device acquired successfully
  98. Info : SWD DPIDR 0x0bc11477
  99. Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
  100. [psoc4.cpu] halted due to debug-request, current mode: Thread
  101. xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8, semihosting
  102. ** Device acquired successfully
  103. Info : psoc4.cpu: bkpt @0x00000359, issuing SYSRESETREQ
  104. [psoc4.cpu] halted due to debug-request, current mode: Thread
  105. xPSR: 0x61000000 pc: 0x00000358 msp: 0x20002000, semihosting
  106. ===== arm v7m registers
  107. (0) r0 (/32): 0x40100004
  108. (1) r1 (/32): 0x00000359
  109. (2) r2 (/32): 0x00000000
  110. (3) r3 (/32): 0x00000000
  111. (4) r4 (/32): 0x20002000
  112. (5) r5 (/32): 0x08000000
  113. (6) r6 (/32): 0x0ffff060
  114. (7) r7 (/32): 0x00000000
  115. (8) r8 (/32): 0x200007e4
  116. (9) r9 (/32): 0x40290000
  117. (10) r10 (/32): 0x1fff2000
  118. (11) r11 (/32): 0x00000000
  119. (12) r12 (/32): 0x00400200
  120. (13) sp (/32): 0x20002000
  121. (14) lr (/32): 0x1000012d
  122. (15) pc (/32): 0x00000358
  123. (16) xpsr (/32): 0x61000000
  124. (17) msp (/32): 0x20002000
  125. (18) psp (/32): 0x40100110
  126. (20) primask (/1): 0x00
  127. (21) basepri (/8): 0x00
  128. (22) faultmask (/1): 0x00
  129. (23) control (/3): 0x00
  130. ===== Cortex-M DWT registers
  131. Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (2733 ms). Workaround: increase "set remotetimeout" in GDB
  132. Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (1418 ms). Workaround: increase "set remotetimeout" in GDB
  133. Error: [psoc4.cpu] not halted (gdb fileio)
  134. Polling target psoc4.cpu failed, trying to reexamine
  135. Info : SWD DPIDR 0x0bc11477
  136. Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
  137. Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
  138. Info : [psoc4.cpu] Examination succeed
  139. Info : [psoc4.cpu] external reset detected
  140. Polling target psoc4.cpu failed, trying to reexamine
  141. Info : SWD DPIDR 0x0bc11477
  142. Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
  143. Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
  144. Info : [psoc4.cpu] Examination succeed
  145. Info : [psoc4.cpu] external reset detected
  146. Polling target psoc4.cpu failed, trying to reexamine
  147. Info : SWD DPIDR 0x0bc11477
  148. Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
  149. Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
  150. Info : [psoc4.cpu] Examination succeed
  151. Info : [psoc4.cpu] external reset detected
  152. Polling target psoc4.cpu failed, trying to reexamine
  153. Info : SWD DPIDR 0x0bc11477
  154. Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
  155. Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
  156. Info : [psoc4.cpu] Examination succeed
  157. Info : [psoc4.cpu] external reset detected

打开串口助手,可以看到欢迎界面。在串口输入:“hello 21ic”,可以看到相同的内容被打印到屏幕上。







本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
Amazingxixixi 发表于 2025-4-24 16:18 | 显示全部楼层
学习一下
慢动作 发表于 2025-4-29 11:35 | 显示全部楼层
UART模块支持的高传输速率使得其在高速数据传输应用中非常实用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

69

主题

290

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部