ECos stm32 Step by Step 8-manual serial port usart2 driver experiment ECOs interruption

Source: Internet
Author: User

I have been busy with other things recently. I haven't touched ECOs for a long time. These two days are a bit blank. I have to write a serial driver to play with it and verify the interrupted call of ECOs. LZ spent two days writing this driver, and encountered a few disgusting problems. later it was found that the previous Foundation was not well prepared. Fortunately, it was solved.


Although ECOs has already written the serial port driver, you only need to enable it in the configuration tool. However, after all, what others write is not their own, but it is easy to write and use. The main purpose of this test is to debug the ECOS interruption service and enable the serial port interruption to send and receive data.


The biggest problem encountered first is that in fact it has nothing to do with any serial port, that is, when debugging runs task delay, the debugging program receives the Stop command, and all registers cannot be correctly read. It took a long time to locate the cause. At first, I suspected that the thread was not correctly set. I used GDB to configure various threads. The time was good and bad, and it seems that it was not the root of the problem. Later, I suspected that there was a problem with the jlink simulator. I tried different versions and finally upgraded them to the latest version. Search for related errors on the Internet and there is no valuable content. Here, the network of tianchao is severely despised, and Google cannot use it. Bing is used to search English. Later, I accidentally saw that I could select the chip type when I opened the gdb server. The default value was cortexm3, And then I chose stm32f103ze. I didn't expect the problem to be solved. I have specified the chip signal command in the gdb server script. It seems that the command does not work. You must select the target chip model at the beginning. At this point, the program will not exit for no reason during debugging.


Here is a few digress. LZ used to use source insight to write code with slickedit. However, if the company didn't buy the source insight license, it won't be able to use it. Slickedit is a 10-year-old version of license. It should have no restrictions and still use the original company license. The result is that we recently had to read a large number of operating system source code for running ECOs, and we were so anxious if we didn't have any good tools. Later I found that slickedit is also a super easy-to-use code tool, but its location is not as convenient as that of source insight, but it is also very easy to use. Now I am used to editing and browsing code with slickedit, which is very convenient and is the most expensive editing tool.


After the Basic Debugging of GDB is completed, we have the experience of gpio driver, and it is very easy to write the serial driver. The code is basically written in the past. Just copy and paste it, and add the database file usart of St. Add the interrupt response function when configuring the serial port

static Cyg_ErrNo usart_set_config(cyg_io_handle_t handle, cyg_uint32 key, const void* buf, cyg_uint32 *len){        NVIC_InitTypeDef NVIC_InitStructure;    USART_InitTypeDef u_info;    Usart_Info_t *info = (Usart_Info_t *)buf;    USART_DeInit( USART2);    ConvertSerial2UartInfo(info->b, info->p, info->d, info->s , &u_info);    USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);    USART_Cmd(USART2, DISABLE);    USART_Init(USART2, (USART_InitTypeDef *)&u_info);    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;    NVIC_Init(&NVIC_InitStructure);        // create ISR & DSR<span style="color:#FF6666;">    cyg_interrupt_create(CYGNUM_HAL_INTERRUPT_UART2, 0x80, 0, &usart2_ISP, &usart2_DSR, &int_usart_handle, &int_usart);    cyg_interrupt_attach(int_usart_handle);    cyg_interrupt_unmask(CYGNUM_HAL_INTERRUPT_UART2);</span>    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);    USART_Cmd(USART2, ENABLE);    return ENOERR;}

static cyg_uint32 usart2_ISP(cyg_uint32 vector, CYG_ADDRWORD data){//cyg_interrupt_mask(vector);cyg_interrupt_acknowledge( vector );if ( USART_GetITStatus(USART2, USART_IT_RXNE) == SET )    {        USART_ClearITPendingBit(USART2, USART_IT_RXNE);        UART2RxISR();    }    if ( USART_GetITStatus(USART2, USART_IT_TXE) == SET )    {        USART_ClearITPendingBit(USART2, USART_IT_TC);        UART2TxISR();    }    //cyg_interrupt_unmask(vector);return (CYG_ISR_HANDLED);}

Other processes are similar to gpio. LZ encountered the problem of interrupt response but no data sending. Later, it was found that the reusable pin configuration during initialization was incorrect. Just check the configuration carefully.

The START process is always quite painful. You may encounter one problem or another, and sometimes you do not know how to solve it. However, as one problem is solved, you will gain a lot of practical experience, this is why different people have different work efficiency. Why are masters 5-10 times more efficient than general engineers? Apart from talent, it is more important to build on the basis of a large number of programming practices, those who only read books and do not operate will basically only talk on paper, which is why I have to interview software engineers for a computer question. I have read some cases recently, and I feel a little bit of emotion, empty talk about the country by mistake, and empty talk about the country by mistake.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.