2018-03-23 12:59 AM
Hello everyone,
I am currently working on a STM32F103RBT6 MCU on the OLIMEXINO-STM32 board :
https://www.olimex.com/Products/Duino/STM32/OLIMEXINO-STM32/open-source-hardware
.So far, I am sending and receiving CAN messages, but I would like to parametrize a little bit more without changing the code (I want to be able to change the number of messages I want to send without recompiling everything, while the code is running on my board).
I first thought about reading those parameters in a file. Problem is that I can't find a way to access it from my MCU (while the file is still on my computer).
I then thought about directly sending the required informations from my computer via USB or a serial port, the issue here is that I have no idea on how to proceed... On the MCU side, I know how to look at data coming from an SP port (not with the USB yet, but I don't think it will be too hard to find), but on the computer side, I have absolutely no idea on how to send these informations ...
Do you know the way to proceed ? Or do you have an idea that would work better ?
2018-03-24 04:07 AM
Actually, using the USB in communication without reading up on the USB hardware and and it's underlying protocol is not so easy despite the apparent ease of use of USB in daily life. SPI, while easy to use, is not so useful when you want to interface with a PC unless you have a Raspberry PI or similar single board computer which has an SPI port.
I would recommend you use the UART/USART module for your current need. It is much easier to implement. As for the PC side of things you can use Putty (
) for Windows or Minicom if you happen to use any flavor of Linux OS.By the way, if you get stuck along the way in this 'mess' of things, leave a message here again and I will try to help again if possible and if you find my advice useful.
2018-03-26 03:01 AM
First of all, thank you for your answer.
I took a look at PuTTY and I can't really figure out how to use it, do you know if there is any documentation/tutorial available ?
On the USB part, my first thought was not to send data through USB, put just access a file via a path (as we would use C:/Program Files/ ..., but starting from the MCU), before I give up on this idea, I want to make sure that it is not possible (as it would be clearly the most efficient way regarding the different constraints I am facing (i.e : the MCU will be in a waterproof box, it should be easy to change CAN frames etc..).
Thank you for your future answer !
2018-03-26 12:55 PM
To be honest with you Mr. Clergue, I got a bit lazy in trying to find an appropriate online tutorial or simple document showing how Putty works at the basic level so I kind of wrote a small guide with images for you (please check the attachment). I hope it helps.
Additionally, you may want to check out this link -
https://learn.sparkfun.com/tutorials/terminal-basics/all#tera-term-windows
I suggest reading the first three sections (Serial Terminal Overview, What Is a Terminal?, Basic Terminology) and the section Tera Term (Windows). If you are in a hurry, reading the Basic Terminology and Tera Term (Windows) sections should be enough. Tera Term is a simpler tool compared to Putty, but specifically geared towards simple UART/USART communication.
Your reply contains some information on what you wish to do but it is not enough to form a complete picture. As such I can not claim to understand you system, but if you don't mind me assuming some things I would like to offer some advice. By your statement of accessing a file via a path I assume you mean that you wish to have a 'configuration' file on you PC and then access it, as needed, from the MCU. If I am correct, then the manner in which you connect your MCU to the PC (USB, USART, or even CAN - I checked and there are some USB to CAN converters for PCs) is completely irrelevant for the purpose of accessing that file. File access in this manner is software dependent, meaning the file access depends on how you implement the access protocol. This almost the same idea as accessing files on a NAS server from your PC. This also means that your protocol for accessing that configuration file can be configured to use any hardware interface for communication (USB, USART, CAN).
Please keep in mind that I have absolutely no idea how you can access directories on the PC via those hardware interfaces mentioned before using built in functionality in the Windows operating system. As I said, this is similar to the idea of accessing NAS storage, but I have no idea how to do this with an MCU.
If you are hell bent on using this method of access I would suggest you write some sort of simple server software for your PC which will listen for incoming commands on any chosen hardware interface. After the server accepts the incoming command with the path variable, it could open the file at the given location, and finally send back the configuration data. In this case it might be better to just write the server program to listen for a command that means 'request configuration' and then just sends back data (you could put your file in the same directory as the server executable is).
Final thing I would suggest is NOT using the MCU as the client (the MCU request configuration data) but rather using the MCU as the listener. In essence, program the MCU to listen for incoming data and if the data matches some pattern, use it as your configuration data. This will simplify and software written for the PC to 1) select interface 2) read config file 3) send config data as data stream to MCU.
I hope my reply will be helpful to you and I also apologize if I have overstepped my bounds.
With respect.
________________ Attachments : putty_guide.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hxri&d=%2Fa%2F0X0000000b1Y%2FgfIvNIJGYRLFMUxhptRQm7b.jEFaL.8rwq7cL65CQLQ&asPdf=false2018-03-27 05:26 AM
First of all, thank you for taking so much time helping me with the issue I am facing. I took a look at both your PDF file and the link you gave me and it helped me understanding a bit more what I will have to do.
To give a bit more insight on the project I am working on : I have to configure a MCU for it to send CAN frames in an automotive system. I need to find a way to easily configure the frames for the user to be able to change them without having to recompile the whole code and/or take the MCU out of its waterproof box. My supervisors suggested that using USB would be great for this (as the USB port can be easily 'waterproof sealed' and other similar devices on the market use USB). A USB or microUSB output is also user friendly (as customers all have a computer with USB port and won't need any additional adapter). However, I don't think it would be a problem to add a USB to UART adapter on my board so that I can have the USB connection, even if the protocol beneath it is UART (the CP2102N for example :
https://www.mouser.fr/ProductDetail/Silicon-Labs/CP2102N-MINIEK?qs=bYcAidFZG4gm0B6FZQu4VA==
).I, by myself, thought about using the USB connection to look at my configuration file, but as you said, it might be harder than what I thought.
I am still having some questions regarding the use of the UART as you suggest, especially the last part where you advise me on creating a 'simple server software', I think I will do as you say (i.e use the MCU as a listener and not as a client). I am completly new to this (software development), hence I really don't know where to start from... What language would you recommand ? (I can do C, C++, Matlab (even if I don't think it is very useful here) and I have notions of Python). About the way to do it, do you think it could be possible to run it/create it thanks to PuTTY or TeraTerm (I don't think so myself, but I just want to make sure beforehand), or would you suggest going through PuTTY source code and try to create a software tailored to my needs ?
If you have anything to add (tutorials, datasheets ...) or to ask, please feel free !
Thank you again for your help !
With respect.
2018-03-27 12:19 PM
Hello again Mr. Clergue. I appreciate you sharing your project information. This will allow me to be more specific when discussing ideas.
I understand now that you CAN interface is not being used by the user directly as I previously thought. Also, considering this is a commercial product I understand your desire, if possible, to use the USB interface. Indeed, I agree that this would serve as a convenient solution. If money is not an issue for the price of the final product, your idea of adding the USB to UART adapter is great, though it may be easier to expand your PCB design to include the IC considering that you have a 'complete' in-house solution. The 'standard' is the FT232 - for example
https://www.mouser.fr/ProductDetail/FTDI/FT232BL-REEL?qs=sGAEpiMZZMs5ceO8zL%252bTx9oJ8aiHRgCo
The electrical design is not that difficult actually and there are reference designs available in the datasheet of the device. On a side note, please consider using a USB type B panel mount connector (for examplehttps://www.sparkfun.com/products/11370
) instead of a micro USB connector if the device is intended to be operated outdoors and reused frequently. B type connectors are much more robust and durable compared to the micro connectors.On the other hand, if you supervisor insists on using the USB directly instead, I will have to apologize in advance because I will not be able to offer any advice in that regard considering I have not yet tried using the USB peripheral.
As far as the software part goes. If you have the time I suggest using Python for the initial development phase as it allows you to quickly write and test code. Python is, after all, an interpreted language. In the later development stage, the software logic developed in Python can be easily transferred to C or C++ if need be. Considering this is commercial product, it will most likely need a graphical interface in which case you might want to consider either sticking to Python or using C♯ unless you have some serious performance requirements. If software performance is an issue, you will have to sit down and grow a few white hairs while trying to learn how to use GUI libraries for C or C++. I am a little bit biased in this regard as I really like C++, but when it comes to GUI interfaces C♯ and Microsoft's Visual Studio are hard to beat in terms of ease of use. Please take a look at this link for more information under the 'Graphic user interface'. This list is not complete of course and other libraries are available, but it lists the commonly used open source libraries. My recommendations are either WxWidgets or Qt for use with C++ or GTK+ if you're comfortable with C (although C++ bindings exist for GTK+).
You are right that Matlab is of very little use here. I will tell you that it is possible to use Matlab for your task, though I cant overstate how foolish that would be considering the multitude of other options available.
Finally, I you want to go with the suggestion of making the MCU a listener (a server if you will) things will be slightly easier and your implementation could be done over Putty or TeraTerm though this is rather messy. If you chose Python for your development purposes you can use the PySerial module (
https://pythonhosted.org/pyserial/index.html
) to open up the required COM port on your PC, set the communication speed, flow control, etc. Rather easy. After you initial configuration of the COM port is done (assuming everything went correctly) it is just a matter of reading your configuration file and sending the data to the MCU. The MCU will have to handle the interpretation of the data. You could implement the reconfiguration of your CAN interface on the MCU in the software GUI instead of using a configuration file if the configuration options (as you intended them) are not numerous. Or, you could implement both approaches in the same software and let the user decide which one is more convenient.If you decide to use C♯ and Visual Studio, the Serial class is available and it will allow you to communicate over the serial port with ease, but on Windows. C♯ can function just fine on Linux, however Visual Studio is incompatible which will make development challenging.
C/C++ and the libraries I posted links to pretty much don't care even if you try to write and compile code on a toaster as long as that toaster has a serial port and display as needed for your project You may also be interested in this (
https://github.com/wjwwood/serial
). This is a serial COM port library for C++.I would not recommend looking too much through the source code of Putty or any other terminal program as this might confuse you more than it explains considering the large number of possible options offered by this software. My recommendation is that you approach this slowly from the beginning by writing code yourself as it will help you understand what you are doing.
To sum it up, if your requirements are:
- cross platform, ease of use: Python
- Windows only, ease of use: C♯ and Visual Studio
- cross platform, performance: C/C++
Hope this helps. Feel free to ask any other questions if you consider my advice helpful.
With respect.