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等参数。
实物照片:
核心代码:- int main(void)
- {
- cy_rslt_t result;
- uint32_t read_data;
- cy_en_scb_uart_status_t initstatus;
- /* Turn off the USER LED */
- Cy_GPIO_Write(CYBSP_LED1_PORT, CYBSP_LED1_NUM, LED_OFF);
- /* Initialize the device and board peripherals */
- result = cybsp_init() ;
- /* Board init failed. Stop program execution */
- if (result != CY_RSLT_SUCCESS)
- {
- CY_ASSERT(0);
- }
- /* Initialize the UART */
- initstatus = Cy_SCB_UART_Init(CYBSP_UART_HW, &CYBSP_UART_config, &CYBSP_UART_context);
- /* Initialization failed. Handle error */
- if(initstatus!=CY_SCB_UART_SUCCESS)
- {
- handle_error();
- }
- /* Enable global interrupts */
- __enable_irq();
- Cy_SCB_UART_Enable(CYBSP_UART_HW);
- /* Transmit Header to the Terminal */
- Cy_SCB_UART_PutString(CYBSP_UART_HW, "\x1b[2J\x1b[;H");
- Cy_SCB_UART_PutString(CYBSP_UART_HW, "***********************************************************\r\n");
- Cy_SCB_UART_PutString(CYBSP_UART_HW, "PSoC 4 MCU UART transmit and receive\r\n");
- Cy_SCB_UART_PutString(CYBSP_UART_HW, "***********************************************************\r\n\n");
- Cy_SCB_UART_PutString(CYBSP_UART_HW, ">> Start typing to see the echo on the screen \r\n\n");
- for (;;)
- {
- /* Check if there is a received character from user console */
- if (0UL != Cy_SCB_UART_GetNumInRxFifo(CYBSP_UART_HW))
- {
- /* Re-transmit whatever the user types on the console */
- read_data = Cy_SCB_UART_Get(CYBSP_UART_HW);
- while (0UL == Cy_SCB_UART_Put(CYBSP_UART_HW,read_data))
- {
- }
- }
- }
- }
编译后,烧录:- Started by GNU MCU Eclipse
- Open On-Chip Debugger 0.12.0+dev-5.7.0.3672 (2025-03-04-03:08)
- Licensed under GNU GPL v2
- For bug reports, read
- http://openocd.org/doc/doxygen/bugs.html
- ********************************************************************************
- * !!! OBSOLETE target 'psoc4.cfg' - will be removed soon. *
- * Use 'infineon/psoc4.cfg' target instead. *
- ********************************************************************************
- Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
- ** Auto-acquire enabled, use "set PSOC4_USE_ACQUIRE 0" to disable
- adapter speed: 2000 kHz
- Info : Using CMSIS-DAPv2 interface with VID:PID=0x04b4:0xf155, serial=0D04189E02272400
- Info : CMSIS-DAP: SWD supported
- Info : CMSIS-DAP: Atomic commands supported
- Info : CMSIS-DAP: FW Version = 2.0.0
- Info : CMSIS-DAP: Interface Initialised (SWD)
- Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
- Info : CMSIS-DAP: Interface ready
- Info : KitProg3: FW version: 2.70.1480
- Info : KitProg3: Pipelined transfers enabled
- Info : KitProg3: Asynchronous USB transfers enabled
- Info : VTarget = 3.317 V
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
- Info : clock speed 2000 kHz
- Info : SWD DPIDR 0x0bc11477
- Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
- Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
- *****************************************
- ** Silicon: 0x3612, Family: 0xC6, Rev.: 0x22 (B1)
- ** Detected Family: PSoC 4000T
- ** Detected Device: CY8C4046LQI-T452
- ** Detected Main Flash size, kb: 64
- ** Chip Protection: OPEN
- *****************************************
- Info : [psoc4.mem_ap] Examination succeed
- Info : [psoc4.cpu] Examination succeed
- Info : gdb port disabled
- Info : starting gdb server for psoc4.cpu on 3333
- Info : Listening on port 3333 for gdb connections
- Info : SWD DPIDR 0x0bc11477
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
- [psoc4.cpu] halted due to debug-request, current mode: Thread
- xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8
- ** Device acquired successfully
- Started by GNU MCU Eclipse
- Info : Listening on port 6666 for tcl connections
- Info : Listening on port 4444 for telnet connections
- Info : accepting 'gdb' connection on tcp/3333
- Info : New GDB Connection: 1, Target psoc4.cpu, state: halted
- Warn : Prefer GDB command "target extended-remote :3333" instead of "target remote :3333"
- Info : SWD DPIDR 0x0bc11477
- Error: Failed to read memory at 0x10000040
- semihosting is enabled
- Warn : No RTOS could be auto-detected!
- Warn : No RTOS could be auto-detected!
- Verifying region (0x00000000, 4712)... Mismatch
- Info : Data mismatch, proceeding with flash programming
- Info : Padding image section 0 at 0x00001268 with 24 bytes (bank write end alignment)
- Warn : Only mass erase available, erase skipped! (psoc4 mass_erase)
- [ 5%] [# ] [ Programming ]
- [ 8%] [## ] [ Programming ]
- [ 10%] [### ] [ Programming ]
- [ 13%] [#### ] [ Programming ]
- [ 16%] [##### ] [ Programming ]
- [ 21%] [###### ] [ Programming ]
- [ 24%] [####### ] [ Programming ]
- [ 27%] [######## ] [ Programming ]
- [ 29%] [######### ] [ Programming ]
- [ 32%] [########## ] [ Programming ]
- [ 35%] [########### ] [ Programming ]
- [ 40%] [############ ] [ Programming ]
- [ 43%] [############# ] [ Programming ]
- [ 45%] [############## ] [ Programming ]
- [ 48%] [############### ] [ Programming ]
- [ 51%] [################ ] [ Programming ]
- [ 54%] [################# ] [ Programming ]
- [ 59%] [################## ] [ Programming ]
- [ 62%] [################### ] [ Programming ]
- [ 64%] [#################### ] [ Programming ]
- [ 67%] [##################### ] [ Programming ]
- [ 70%] [###################### ] [ Programming ]
- [ 72%] [####################### ] [ Programming ]
- [ 75%] [######################## ] [ Programming ]
- [ 81%] [######################### ] [ Programming ]
- [ 83%] [########################## ] [ Programming ]
- [ 86%] [########################### ] [ Programming ]
- [ 89%] [############################ ] [ Programming ]
- [ 91%] [############################# ] [ Programming ]
- [ 94%] [############################## ] [ Programming ]
- [ 97%] [############################### ] [ Programming ]
- [100%] [################################] [ Programming ]
- Info : SWD DPIDR 0x0bc11477
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
- [psoc4.cpu] halted due to debug-request, current mode: Thread
- xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8, semihosting
- ** Device acquired successfully
- Info : SWD DPIDR 0x0bc11477
- Info : kitprog3: acquiring device in Test Mode using 'PSOC 4' target and 'xres' reset...
- [psoc4.cpu] halted due to debug-request, current mode: Thread
- xPSR: 0xa1000000 pc: 0x10000040 msp: 0x20001fe8, semihosting
- ** Device acquired successfully
- Info : psoc4.cpu: bkpt @0x00000359, issuing SYSRESETREQ
- [psoc4.cpu] halted due to debug-request, current mode: Thread
- xPSR: 0x61000000 pc: 0x00000358 msp: 0x20002000, semihosting
- ===== arm v7m registers
- (0) r0 (/32): 0x40100004
- (1) r1 (/32): 0x00000359
- (2) r2 (/32): 0x00000000
- (3) r3 (/32): 0x00000000
- (4) r4 (/32): 0x20002000
- (5) r5 (/32): 0x08000000
- (6) r6 (/32): 0x0ffff060
- (7) r7 (/32): 0x00000000
- (8) r8 (/32): 0x200007e4
- (9) r9 (/32): 0x40290000
- (10) r10 (/32): 0x1fff2000
- (11) r11 (/32): 0x00000000
- (12) r12 (/32): 0x00400200
- (13) sp (/32): 0x20002000
- (14) lr (/32): 0x1000012d
- (15) pc (/32): 0x00000358
- (16) xpsr (/32): 0x61000000
- (17) msp (/32): 0x20002000
- (18) psp (/32): 0x40100110
- (20) primask (/1): 0x00
- (21) basepri (/8): 0x00
- (22) faultmask (/1): 0x00
- (23) control (/3): 0x00
- ===== Cortex-M DWT registers
- Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (2733 ms). Workaround: increase "set remotetimeout" in GDB
- Warn : keep_alive() was not invoked in the 1000 ms timelimit. GDB alive packet not sent! (1418 ms). Workaround: increase "set remotetimeout" in GDB
- Error: [psoc4.cpu] not halted (gdb fileio)
- Polling target psoc4.cpu failed, trying to reexamine
- Info : SWD DPIDR 0x0bc11477
- Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
- Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
- Info : [psoc4.cpu] Examination succeed
- Info : [psoc4.cpu] external reset detected
- Polling target psoc4.cpu failed, trying to reexamine
- Info : SWD DPIDR 0x0bc11477
- Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
- Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
- Info : [psoc4.cpu] Examination succeed
- Info : [psoc4.cpu] external reset detected
- Polling target psoc4.cpu failed, trying to reexamine
- Info : SWD DPIDR 0x0bc11477
- Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
- Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
- Info : [psoc4.cpu] Examination succeed
- Info : [psoc4.cpu] external reset detected
- Polling target psoc4.cpu failed, trying to reexamine
- Info : SWD DPIDR 0x0bc11477
- Info : [psoc4.cpu] Cortex-M0+ r0p1 processor detected
- Info : [psoc4.cpu] target has 4 breakpoints, 2 watchpoints
- Info : [psoc4.cpu] Examination succeed
- Info : [psoc4.cpu] external reset detected
打开串口助手,可以看到欢迎界面。在串口输入:“hello 21ic”,可以看到相同的内容被打印到屏幕上。
|