Stm32 usb to serial port program design analysis

Serial port debugging is becoming increasingly common in projects, and the scarcity of serial port resources has become more apparent. Many professionals in this field have a deep understanding of these challenges. Without a USB-to-serial tool, development would be nearly impossible. Understanding the USB virtual serial port is essential for integrating it into projects, making debugging more convenient and allowing direct power supply. The company's future product development is based on the STM32 platform, transitioning from Cortex-M3 to Cortex-M4. In terms of speed, power consumption, cost, and availability, these chips are competitive and we prefer not to make changes unless necessary. STM32 typically includes a built-in USB serial port. Not using it and adding an external USB-to-serial unit would be inefficient and wasteful. As per the company’s needs, choosing the right component is key. I previously used TI microcontrollers, from 430 to ARM and then to 28XX. However, ST offers all the features of previous models, with better performance in some areas. TI’s ARM cores are relatively slower, and their DSP performance is comparable to M4, sometimes even better. Power consumption is impressive, and in some cases, M4 with floating-point capabilities outperforms fixed-point versions. That’s why TI intentionally limited the frequency of its M4 core and reduced DSP functions. Every company makes trade-offs. ST also integrates a CMOS sensor interface, which is useful when designing PCBs. However, one downside is that the development environment is lacking. For example, SuperSpeed USB 2.0 support is minimal, the CMOS interface data is scarce, and TCP/IP implementation is not well-documented. Their web pages are difficult to navigate, making it hard to find information about the chip. Compared to NXP, ST’s application support is less mature. Even ZLG provides better assistance. FREESCALE excels in network communication applications, and their TCP/IP source code is clean and easy to work with. It seems that ST is strong in chip design but still needs to improve in application support. **Description:** 1. Skip the driver and use low-speed transmission. The maximum can be set to 921600 or 100KB/s. It should be similar in performance. We only need to transfer simple data. Since our focus is on industrial control, high speed isn't required. Completing the task efficiently is the priority, rather than spending time learning new tools. 2. Since there is no OS support in the standard library, we may consider using Keil’s OS later. It's simpler, and the most important thing is that uC/OS doesn’t support M4 floating-point arithmetic. For M3, we can move the USB part to uC/OS. But for M4, we use KeilOS directly, avoiding the effort of porting an OS. Always start with main: ```c Set_System(); // System setup Set_USBClock(); // Set USB clock USB_Interrupts_Config(); // Configure USB interrupts USB_Init(); // USB initialization while(1) { if((count_out != 0) && (bDeviceState == CONFIGURED)) { USB_To_USART_Send_Data(&buffer_out[0], count_out); // Send data to serial port count_out = 0; // Clear after sending } } ``` At first glance, the code seems simple, but it looks like it only sends data, not receives. I think the receiving part might involve interrupts—probably the process of sending serial data to USB is handled in the serial interrupt. We can analyze it later, and maybe this part isn’t needed. Let’s look at it step by step. First, the `Set_System()` function. If you guess correctly, it sets up the system clock. Indeed, the next step is to enable the external crystal oscillator—here it’s 12MHz. Most development boards use 8MHz, so in `stm32f10x_conf.h`, change the external crystal frequency from 8000000 to 12000000. Then wait for the external crystal to stabilize. If the crystal is not soldered, the program will hang here. If it crashes immediately, check this section. Next, the code enables the flash prefetch buffer, divides the flash clock by two, which means the flash clock is 36MHz. There’s an article from ST stating that flash can operate at up to 50MHz. The system clock (HCLK) is configured as SYSCLK. APB2 is set to SYSCLK without division, while APB1 is divided by two. However, the timers below APB1 (like TIM2, TIM3, TIM4) still run at 72MHz due to multiplication. The ADC clock is divided by six, resulting in 12MHz. Since ADC requires 13.5 clock cycles, an ADC conversion can be completed in approximately 1μs. The PLL is configured to multiply the input frequency by nine. At 12MHz, it would be 108MHz, but for 8MHz, it's 72MHz. Be careful here. After enabling the PLL, the code waits for it to stabilize before proceeding. Then, the system switches to the PLL clock. Finally, the code enables clocks for GPIOA, GPIOB, and the serial ports. It also enables the USB disconnect pin, which is controlled via PE7 according to the schematic. However, in `platform_config.h`, it’s defined as GPIOD, leading to confusion. It’s unclear which pin exactly controls the USB disconnect, and this discrepancy between the code and the schematic remains unresolved for now. The USB disconnect pin is configured as a pull-up, turning on the transistor to connect the DP+ pin with a 1.5kΩ resistor, allowing enumeration. But the specific pin isn’t clearly defined in the schematic, raising questions about potential conflicts between the schematic and the code. PA10 is set as an input floating, and PA9 as a push-pull output—this matches the UART0 pins on our board. This part is complete.

Front Hydrogel Films

The hydrogel Screen Protector has super ductility and shrinkage, has a strong and effective self-repair function, impact resistance, durability, better toughness, and has a certain buffering effect on sharp objects. The use of hydrogel film can adapt to the contours of any device, so it can be attached to curved screens and rounded edges. The full-coverage screen protector can perfectly fit your screen and provide maximum protection.

The 0.14mm ultra-thin thickness is more sensitive to the touch, and the ultra-thin design gives you a bare-metal experience. The oleophobic and waterproof coating prevents fingerprints and dust, makes the hydrogel screen protector easy to clean, and makes your phone look more beautiful.

Hd Clear Hydrogel Protector Sheet,Anti Blue-Ray Hydrogel Protector,Matte Hydrogel Film,Privacy Hydrogel Film

Shenzhen TUOLI Electronic Technology Co., Ltd. , https://www.tlhydrogelprotector.com