Serial port debugging is being used more and more in the project, and the shortage of serial port resources has become more prominent. Many of the people in this book have a deep understanding. There is no way to develop without a USB to serial port tool.
Understand the USB virtual serial port, in order to use this USB in the project, debugging is more convenient, the power supply can be directly supplied. The company's future product development is based on the STM32 platform, from contex_M3 to contex-M4. Regardless of speed, power consumption, price, and ease of purchase, they are competitive and do not want to be modified (unless it does not meet the requirements).
STM32 basically has a USB serial port. If you don't use it and add a USB to serial port unit, it will be too backward and a waste of resources. By the way, according to the company's situation, the right one is good. I used to use TI, from 430 to ARM to 28XX. This ST contains all the previous ones, TI's ARM speed is relatively slow, and its ordinary DSP speed is comparable to M4, some are still better than M4, power consumption is amazing, not to mention M4 with floating point than fixed point Some places are much faster. It's no wonder that TI deliberately slowed down the frequency when pushing M4, and DSP functions were reduced. I think every company has its own considerations. And ST put the CMOS sensor interface into it. Try to make a block of PCB when you are busy. The most unpleasant thing about ST is that its development routines are too shallow, such as SuperSpeed ​​USB 2.0, CMOS interface data is almost no, TCP / IP is also a short-lived, the web page is also designed to be the worst in the world, let people find a Chip, looking for a very tired information. In application, it is far worse than NXP. After all, there is a ZLG help. FREESCALE is the best in network communication applications. Seeing their TCP/IP source code is a pleasure. It seems that doing chips is the strength of ST, and the application is still to be strengthened.
Description:1. Skip the driver. Use low speed transmission. The maximum can be set to 921000 or 100KB/S. It should be almost the same. Only pass some simple things. Because the focus of our work is industrial control, no high speed is required, and we aim to accomplish the task. Instead of having to learn something, completing the task is the first important thing.
2. Since there is no operating system support in the routine, you may use keil's operating system later. Simpler, the most important thing is that ucOS does not support M4 floating point arithmetic. Of course, for M3 we can move the USB part to ucOS. For M4, we use KeilOS directly, and don't want to spend a lot of effort to do OS porting.
Always start with main
Set_System();///Setting system
Set_USBClock();///Set USB clock
USB_Interrupts_Config();///Configure USB interrupt
USB_Init();///USB initialization
While(1)
{
If((count_out!=0)&&(bDeviceState==CONFIGURED))
{
USB_To_USART_Send_Data(&buffer_out[0], count_out);//If there is data to send it to the serial port
Count_out=0;///// this clear after sending
}
}
At first glance, it is quite easy to understand, but since this example seems to be only sent, it is not received. I think its collection is about to be interrupted (that is, the process of serial port sending to USB, it is estimated to be carried out in the serial port interrupt, we can analyze it later, it may not need to add this part of the code, hope not to do this)
Let's take a look at it one by one. First look at the Set_System() function. If you don't guess correctly, you should set the clock.
Sure enough, let's take a look at the following one. It first allows the external crystal oscillator - here, the external crystal oscillator is 12M. The general development version uses 8M. So in the stm32f10x_conf.h file, change the external crystal frequency from 8000000 to 12000000.
Then, wait for the external crystal to get up. If the crystal is not soldered, you will die here. If you die as soon as you run, look for this place.
Then it does the following work:
Allow FLASH fetch buffer
FLASH clock is divided by 2 times ------- Does this mean that the FLASH clock is 36M? Remember that there is an article in ST that says FLASH can work under a 50M clock.
System frequency HCLK is configured as SYSCLK
The clock of APB2 is configured as SYSCLK without frequency division.
The clock of APB1 is configured to divide by 2. But pay attention to the timers 2, 3, 4 below it. . The frequency is still 72M due to multiplication
The ADC's clock is configured to divide by 6, which is 12MHz. Note that AD requires 13.5 clocks to complete, meaning that almost 1us can complete an AD conversion.
The PLL is configured to 9 times the frequency. 8X9=72MHz. Note that for 12MHz it can only be 6. Be sure to pay attention here.
Allow the PLL and wait for the PLL to be OK before doing anything else. - This is followed by the PLL instead of HSI.
Then we want to allow the clocks for the GPIOA, GPIOB and serial ports. Because we only use these resources. Of course USB is another, I think it will always be allowed somewhere. The following is not easy to understand:
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIO_DISCONNECT, ENABLE); This is called allowing the USB disconnect line. From the schematic diagram it seems to be controlled by PE7. Because PE7 is connected to a pull-up resistor controlled transistor on a DP+. Please refer to the schematic. But the strange thing is that there are the following definitions in platform_config.h:
#defineRCC_APB2Periph_GPIO_DISCONNECTRCC_APB2Periph_GPIOD
It sets this to port D. So who is controlling this USB disconnect pin has not been determined. Leave a question mark here and wait until later.
Next, configure the USB disconnect pin to be pulled up. This means that at the beginning, this pull-up resistor turns the transistor on, so that the DP pin is added with a 1.5K resistor and can be enumerated. Look at which foot is disconnected from the foot, it is not PD9 or PB14. There is no such thing as PE7 (schematic diagram). So here I don’t know why. Is this schematic conflicting with the program?
Next, configure PA10 as the input floating, and configure PA9 as the PP output. These two feet are serial ports. This is correct. All of our boards use UART0, which is the two feet. This part is over now.
Air Lift Mixer,Lifting Pneumatic Mixer,Pneumatic Lifting Mixer,Air Pneumatic Lifting Mixer
RUDONG HONGXIN MACHINERY CO.,LTD , https://www.rdhxmfr.com