STM32F4-Discovery(STM32F429ZIT6)上的RS232(UART)与HAL库? [英] RS232 (UART) on STM32F4-Discovery (STM32F429ZIT6) with HAL library?

查看:631
本文介绍了STM32F4-Discovery(STM32F429ZIT6)上的RS232(UART)与HAL库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



这是我的一些背景,所以你的家伙可以知道我有什么相关知识或我没有。我完全是这种嵌入式系统的新手。我真的不知道电子产品,我是一个纯软件的人。



我唯一的嵌入式系统经验是Raspberry Pi,与STM32F4有很大的不同发现。



我可以通过使用Raspberry Pi上的标准Linux C库来实现UART读/写编程,该库连接到具有USB到RS232适配器的PC使用电压转换器IC。



我的设备和开发环境




  • 具有STM32F429ZIT6 MCU的STM32F429I-DISCO电路板

  • 在Raspberry Pi上工作得很好的USB-to-RS232电缆和电压转换器IC。

  • Keil uVision 5 IDE。



我想要实现



我想在STM32F429发现板上实现可以从PC发送/接收消息的编程。 (例如,发送字符串到PC,当从PC接收到一个字符串时,点亮板上的LED)



我现在所做的一切



现在我设置了我的Keil uVision IDE,并且可以编译/运行眨眼LED示例,我也可以编辑这个例子来控制LED我想要它。 (例如,当用户按钮被按下时打开LED,当按钮被释放时将其关闭)



所以LED部分已经完成了,缺少的部分如何使用RS232电缆与STM32F4 Discovery板进行通讯。



我的问题


  1. 首先,我想知道我是否正确理解了该主板的PIN定义。根据这个


  2. 当连接到Raspberry Pi时,我正在关注

    解决方案

    我已将此答案的代码推送到以下github地址。



    代码很简单,回答了问题,主要是由STM-Cube生成的。 .ioc文件也可供您修改。



    有许多其他外设可以使用,但未经测试,包括

      USB VCport 
    定时器为RC爱好伺服器设置,只需更改脉冲宽度500-1500
    DMA模式下的ADC
    SPI闪存等
    用于端口扩展的I2C或任何

    我分享了OP的沮丧许多天,几个星期和几个月的时间,争取让这些东西在旧的和新的图书馆上工作。 最终在2016年,似乎有一些来自ST的光,我可以继续为这些伟大的板做真正的应用程序。



    事实上,在执行此任务时,我必须重新安装我的多维数据集及其所有的库,才能正常工作,这可能会导致别人的痛苦。 >

    我将在这个模板中添加LCD和触摸屏,使一个很好的droidlet。



    我通常在其中一个UARTS上附加一个蓝牙模块,然后通过调试。



    Andy Brown Andy Brown 为某些ST提供了一些很棒的C ++库。它们似乎基于StdPeripheral库,需要更新,所以我们可以通过Cube和HAL在新的(和旧的)设备上使用它们。作为社区,我们可以更有效地做到这一点。任何想法和接受者?



    玩得开心。





    规范解决方案

     将您的Cube和HAL库更新为最新的
    生成多维数据集项目
    设置所有外设在对话框
    生成代码
    编译
    添加您的应用程序
    测试&调试
    优化
    发布

    您只需要注意类似的外设不同的家庭有不一致之处
    F0上的ADC与F1和F4不同。
    F3可能有16位ADC。



    除了RTFM,你可能正在做的一切正确。 (请阅读手册中的Fineprint)



    除非您想打扰UART,否则建议您实施使用标准USB电缆的Virtual Comport演示。让ST成为设备。



    获取一个STCube的副本,查看项目/外设目录中的USB和Virtual comport。 HAL库是一样的,也有这个代码。



    在任何Discovery板上工作时,启动一个STM32 Cube的副本(免费从ST ),并在那里创建您的配置。它显示您使用什么,什么是免费的,一个伟大的工具,并将设置USB作为奖金。



    然后使用代码生成器为KEIL项目创建一个框架。编译,运行添加你的应用程序代码: - )



    你可能想看这里 Embitz.org 他们有一个伟大的IDE,甚至更好的F429iDisco示例或 ST AC6 IDE ST页面了解更多示例。这些IDE不具有代码大小限制,您将遇到使用LCD,触摸等此设备。






    其余的答案



    不幸的是,STM有必要将这个发现的大部分引脚分配给LCD上的LCD,触摸和内存芯片。有非常少的Async功能 - 他们可能以为USB将会很好。



    Q1) - 这些通常标记的方式将需要通过连接交叉 Rx到TX,反之亦然。



    通过在UART引脚上布线loopback并检查LEDS来检查您的代码。



    Q2) STM Cube将为您生成一个有效的Keil项目。



    有演示代码将在
    stm32cube_fw_f4_v130\STM32Cube_FW_F4_V1.3.0\Projects\STM32F429I-Discovery\Examples\UART中编译并运行Keil项目(MDK-ARM)。您将需要更改为UART5 - 它配置为USART1 PA9(Tx)/ PA10(RX),一旦工作互换到UART5,或在本地测试USART1 - > UART5。



    通过在发现时将RX连接到Tx进行测试,设置Rx然后TX一个字符串应该工作,Rxbuffer应该反映出来。



    然后连接到适配器工作,LEDS应闪烁。



    如果没有,交换Tx和Rx。



    检查DB9上的环回。



    如果您在DB9上有一个调制解调器或PC,您需要管理调制解调器控制信号,然后再进行任何操作。 (RTC,CTS,DCD,DTR,DTE)请参阅此处。 Raspberry为您执行此操作。



    断开STM与适配器的连接,并从DB9上的PC上检查环回,然后在Tx Rx引脚上检查环回。



    如果你这么远,STM会闪烁一个LED,另一个LED,然后你有一个奇偶校验,波特率或字长问题。






    下面是407发现(原始发现) - 最初没有看到你有429 - 我们倾向于谈论F4Discovery和F429i-Discovery。现在还有其他基于F4的电路板。



    在F4发现板上 - UART5不可用,与PC12上使用CS43L422(麦克风)的I2S3D冲突。与F429相同的引脚重载问题



    其他UART和USART1也被使用。



    - 为USART2或USART3配置



    正面为USARTS 2和3内置RTS / CTS线,您可以使用。



    OR



    您需要在电路板上焊接/取消焊接跳线才能禁用麦克风。 >

    我在几个不同的STM32板上生成了许多使用USARTS的项目,它们都完美无缺。不幸的是,HAL程序员只提供有或没有超时的固定长度的驱动程序,没有Readline界面。


    Background

    Here is some of my background so that your guy could know what related knowledge I have or I don't have. I'm totally a newbie of this kind of embedded system. And I don't really know anything about electronics, I'm a pure software guy.

    My only experience of embedded system is Raspberry Pi, which is quite different from STM32F4 Discovery.

    I could implement a UART read / write programming by using standard Linux C library on Raspberry Pi, which is connected to a PC with an USB-to-RS232 adapter with a voltage converter IC.

    My Device and development environment

    • An STM32F429I-DISCO board with STM32F429ZIT6 MCU
    • An USB-to-RS232 cable and a voltage converter IC which works quite well on Raspberry Pi.
    • Keil uVision 5 IDE.

    What I would like to achieve

    I would like to implement a programming on STM32F429 Discovery board that could send / receive message to / from PC. (For example, send a string to PC. And when received an string from PC, light up the LED on board)

    What I have done right now

    Now I've setup my Keil uVision IDE, and could compile / run the blink LED example, I could also edit that example to control LED as the way I want it to be. (Ex, turn LED on when user button is pressed and turn it off when the button is released)

    So the LED part is pretty much done, the missing piece it how to communicate with STM32F4 Discovery board using RS232 cable.

    My Question

    1. First, I would like to know if I understand the PIN define of this board correctly. According to this datasheet, I should connect the TX pin on DB9 to PD2(UART5_RX), RX pin on DB9 to PC12(UART5_TX), VCC pin on DB9 to 3.3V, and GND on DB9 to GND. Is this connection correct?

    2. Is there any example code on how to use UART on new HAL library that come from the latest version of Keil uVision? I've searched on the web, but most sample code or tutorial are using a function called RCC_AHB1PeriphClockCmd which seems not exist in new HAL library that come from Keil uVision.

    Update

    1. My USB-to-Serial adapter is 067b:2303 Prolific Technology, Inc. PL2303 Serial Port and attached with a level shifter IC. Looks like this:

    2. When connected to Raspberry Pi, I was following this instruction, so the VCC / GND on the IC is connected to 3.3V / GND on Raspberry Pi, I'm not sure if this is needed or not.

    3. By "HAL" library, I mean this stm32f4xx_hal_usart.c file, according to license declaration in the comments, it seems come from STMicroelectronics. Although there are some instruction in this file, it's still quite hard for me to figure out how to use this driver. For example, I can't tell the difference between Enable USARTx interface clock and Enable the clock for USART GPIOs, and I don't know how can I achieve these function. So if there is an example code, it would be a great help as I could compare it with these instructions.

    解决方案

    I have pushed the Code for this answer to the following github address.

    The code is trivial, answers the question, and have mainly been generated by STM-Cube. The .ioc file is also available for you to modify.

    There are a number of other peripherals ready to be used, but untested including

    USB VCport 
    Timers set for RC hobby servos, just change pulse width 500-1500
    ADC  in DMA mode
    SPI  for flash etc
    I2C  for port expansion or whatever
    

    I share the frustration of the OP having spent many days, weeks and months fighting to get this stuff working on both the old and new libraries. Finally in 2016 there appears to be some light from ST and I can go on to do real apps for these great boards.

    In fact, in doing this task, I had to re-install my cube and all its libraries before it worked properly this may have caused anguish in others.

    I'll be adding LCD and touchscreen to this 'template' to make a great little 'droidlet'.

    I usually attach a bluetooth module to one of the UARTS and debug through there.

    Andy Brown Andy Brown has some great C++ libraries for some of the STs. They seem to be based on the StdPeripheral libs and need to be updated so we can use them via Cube and HAL on new (and old) devices. As a community we could do this more efficiently. Any ideas and takers?

    Have fun.


    The canonical Solution

    Update your Cube and HAL libraries to the latest
    Generate a cube project
    Setup all your peripherals in the dialogs
    Generate code
    Compile
    Add your application
    Test  & Debug
    Optimise
    Release
    

    You need only to take care that similar peripherals on different families have inconsistencies e.g. ADC on F0 is different from F1 and F4. F3 potentially has 16 bit ADC.


    You are probably doing everything correctly other than RTFM. (Read the Fineprint in the Manual)

    Unless you want to fight the UART, you are better advised to implement the Virtual Comport demo which uses a standard USB cable. Let the ST be the device.

    Get a copy of STCube, look in the projects/peripherals directory for USB and Virtual comport. The HAL library is the same and also has this code.

    When doing work on any of the Discovery boards, fire up a copy of STM32 Cube (free from ST), and create your configuration there. It shows you what is used and what is free, a great tool and will set up USB as a bonus.

    Then use the code generator to create a skeleton for KEIL project. Compile , run add your app code and :-)

    you may want to look here Embitz.org they have a great IDE and even better F429iDisco examples or the ST AC6 IDE and ST page for more examples. These IDE do not have code size limits, something you will run into using the LCD, touch etc on this device.


    The Rest of the Answer

    Unfortunately STM have of necessity assigned most of the pins on this discovery to the LCD, touch and memory chips onboard. There is very little Async function left - they probably thought the USB would be Ok.

    Q1) - The way these are normally marked you will need to 'crossover' by connecting Rx to TX and Vice versa.

    Check your code by wiring 'loopback' on the UART pins and check the LEDS.

    Q2) - STM Cube will generate a working Keil project for you.

    There's demo code that will compile and run in stm32cube_fw_f4_v130\STM32Cube_FW_F4_V1.3.0\Projects\STM32F429I-Discovery\Examples\UART with a Keil project (MDK-ARM). You will need to change to UART5 - it is configured for USART1 PA9(Tx) /PA10(RX), once working swap to UART5, or test locally USART1 -> UART5.

    Test by connecting RX to Tx on the discovery, setup Rx then TX a string all should work and the Rxbuffer should reflect this.

    Then connect to your adapter all should work., LEDS should flash.

    If not, swap Tx and Rx.

    Check loopback on the DB9.

    If you have a modem or PC on the DB9, you will need to manage the modem control signals before any of this works. (RTC, CTS, DCD, DTR, DTE) See here. Raspberry does this for you.

    Disconnect the STM from the adapter and check loopback from the PC on the DB9 then on Tx Rx pins.

    If you get this far, STM flashes one LED, remote the other, then you have a parity, baudrate or wordlength problem.


    Below is for the 407 discovery ( original discovery) - apologies initially didn't see you have the 429 - we tend to talk of F4Discovery vs F429i-Discovery. There are now other F4 based boards as well.

    On F4-Discovery board - UART5 is not available, conflicts with I2S3D which is used CS43L422 (microphone) on PC12. Same pin overloading problem as the F429

    The other UARTs and USART1 are also used.

    Either - Configure for USART2 or USART3

    The positive is USARTS 2 and 3 have built in RTS/CTS lines which you can use.

    OR

    You need to solder/ unsolder jumpers on the board to disable the Microphone.

    I've generated many projects with USARTS on a few different STM32 boards and they all work flawlessly. The HAL programmers unfortunately only provide drivers for fixed length with or without a timeout, there is no Readline interface.

    这篇关于STM32F4-Discovery(STM32F429ZIT6)上的RS232(UART)与HAL库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆