Programmatic transformation of logic

Anything not related to STM32
Post Reply
valeriia
Posts: 4
Joined: Wed Feb 01, 2023 6:46 am

Programmatic transformation of logic

Post by valeriia »

Good afternoon everyone.
I'm new in STM. I have STM32f103c8t6 with arduino bootloader. I can upload code to STM32f103c8t6 via USB. Right now my code is to send a message to UART1(Serial1). I connected this STM32f103c8t6 to Raspberry Pi 4 (RP4). On RP4 I learned how to read UART using pyserial.
I have questions:
1.Can I upload code to STM32duino(STM32f103c8t6 with arduino bootloader) via RP4 via UART (RP4 has raspbian OS, ArduinoIDE installed)?
2.I want to use STM32f103c8t6 as a game controller. Is it possible to convert TTL to USB as code on RP4? or do you need a logic converter, like a separate chip?

I apologize in advance if the questions are stupid.
Thanks in advance for your reply and help!
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Programmatic transformation of logic

Post by GonzoG »

1. No. You can upload code using UART without software bootloader. STM32F103 has hardware UART bootloader, but you need to set BOOT pin and reset board. Uploading code from Aarduino IDE without using HID bootloader (USB) will erase any software bootloader.

2. You can program RPi to do almost anything, but there is one small issue - RPi is a host device (like every PC) and I think it won't be easy (if possible) to use it as a slave USB device. There's no USB port on RPi4 to connect it to another computer.

You can program STM32F103 as a game controller (mouse, keyboard, joystick, etc). It's not easy in Arduino IDE as there is no library for this, but there are other projects (written in C/C++) that are really easy to use. eg. Freejoy: https://github.com/FreeJoy-Team/FreeJoy
valeriia
Posts: 4
Joined: Wed Feb 01, 2023 6:46 am

Re: Programmatic transformation of logic

Post by valeriia »

Thanks for you answer! You helped me!

I realized that I can upload new code to STM32 via RPI4 and UART connection by changing the jumper. Can you tell me which development environment to choose? As far as I know RPi4 has ARM architecture and not all applications can work. For example, I did not find an installation file from STelectronics CubeMX. Or I googled badly.

I guess, the second question have been written incorrectly. I want to use the STM as a joystick and connect it to the Rpi4, but also via UART. And RPi should recognize the UART connection with STM32 device as a HID device. I saw that you need to write a descriptor for USB HID devices for STM. Is there something similar but via UART? And without the use of additional chips, such as CP2110.

I checked FreeJoy. It is onvenient and fast, but it works with USB-USB. And I would like it via UART, because I want to stop using USB ports on the RPi.

Perhaps what I want is generally impossible. I just would like to understand it and decide now.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Programmatic transformation of logic

Post by ag123 »

if you can get your Rpi to turn that uart into a /dev/ttySxx, you could probably use it as a serial port
there are various open sourced utilities e.g.
https://github.com/jsnyder/stm32loader
that you can try. it requires a linux serial port for that

to use this, you would need to build by selecting options without a bootloader. it needs to sit at 0x8000000
export the binary using Sketch > export compiled binary, the *.bin file would be left in your projject folder.
then you can try using those utilities (e.g. stm32loader) to program the stm32 chip over uart.
connect the wires appropriately, remember to set boot0 and press reset on the stm32.

HID isn't the same and normally, that goes by USB. This (USB) is considered 'advanced' topic and that it is 'beyond basic Arduino'.
For ordinary, uart that can work over the usual Serial ports.
valeriia
Posts: 4
Joined: Wed Feb 01, 2023 6:46 am

Re: Programmatic transformation of logic

Post by valeriia »

Thanks for the tips, I'll definitely try it!

Perhaps later I will describe how it turned out to be done in the end, if, of course, it works out.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Programmatic transformation of logic

Post by GonzoG »

valeriia wrote: Thu Feb 02, 2023 8:14 am I guess, the second question have been written incorrectly. I want to use the STM as a joystick and connect it to the Rpi4, but also via UART. And RPi should recognize the UART connection with STM32 device as a HID device. I saw that you need to write a descriptor for USB HID devices for STM. Is there something similar but via UART? And without the use of additional chips, such as CP2110.

I checked FreeJoy. It is onvenient and fast, but it works with USB-USB. And I would like it via UART, because I want to stop using USB ports on the RPi.

Perhaps what I want is generally impossible. I just would like to understand it and decide now.
The "HID" you are referring and is known from many computer systems, it's actually called USB-HID. So no, you cannot use UART to connect a HID device, as it need USB.

But you can make USB-HID like device that will use UART to transmit data to computer. You just need a driver/daemon that will be a virtual USB-HID device and will work with your UART connected STM. All this you probably will need to write by yourself.
There is no universal UART controller or monitor in system, so system won't recognize your device, it won't even know that you have connected something until some application/driver/daemon/etc will try to open UART communication and get some recognizable data.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: Programmatic transformation of logic

Post by ag123 »

long ago joysticks are analog, no usb whatever.
https://www.kernel.org/doc/Documentatio ... ystick.txt
they are pretty much 2 variable resistors/potentiometers for the x, y axis
https://lastminuteengineers.com/joystic ... rocessing/
i'd guess it is quite easy to make a little serial (uart) protocol for that.

the thing is there is no HID, so if the desktop app depends on HID joystick, then it won't work.
but if your desktop app is flexible and can be adapted to anything, then a simple serial protocol over com: port works just well.

in fact simple serial protocols are the easiest to implement just that they are non standard, anyone can make a new protocol.
valeriia
Posts: 4
Joined: Wed Feb 01, 2023 6:46 am

Re: Programmatic transformation of logic

Post by valeriia »

Hello again!

Perhaps someone found a tutorial or saw it somewhere, or even knows this thing:
via UART c STM32f103 I want to send data. I am creating a data buffer. On the RPI4, I want to open the serial port and convert this data as if it were a USB-HID device to display on the screen.

In my case, I have a keyboard with 9 buttons.
All button status data is sent via UART A9 A10. By connecting STM32 to RPI4 to GPIO, I read UART data on RPI4 using pyserial. But I need the device I plugged in to show up as a USB-HID.

Is it possible to organize this without adapters? if so, where can I read or find similar projects.

Thank you in advance!
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Programmatic transformation of logic

Post by GonzoG »

You need virtual HID device. There probably are quite few examples how to do it, just google it.
chrisharrison3456
Posts: 1
Joined: Sat Mar 18, 2023 10:08 am

Re: Programmatic transformation of logic

Post by chrisharrison3456 »

Programmatic transformation of logic refers to the process of modifying or transforming a computer program's logic or behavior using software tools or programming techniques. This process involves modifying the program's source code to achieve a desired outcome or behavior.

There are several reasons why a programmer may need to perform programmatic transformation of logic, including:

1. Optimization: To improve the performance of a program by optimizing the logic or algorithms used.

2. Refactoring: To improve the readability, maintainability, and structure of a program's codebase.

3. Feature enhancement: To add new features or functionality to an existing program by modifying its logic.

4. Bug fixing: To fix issues or bugs in the program's logic or behavior.[/list]

of logi can be achieved using a variety of techniques, including manual refactoring, automated code analysis and transformation tools, and program synthesis techniques. These techniques can help programmers to improve the quality, performance, and maintainability of their code, while also reducing the time and effort required for software development.
Post Reply

Return to “Off topic”