Hardware - how to start?

Introduction

The first problem when it comes to programming robots is what hardware should I use and how to set up everything?

The easiest solution is to use Arduino which is pretty user-friendly and on the Internet, there are thousands of tutorials about it. However, sometimes Arduino is not powerful enough (usually is more than enough). But you need to use something with more capabilities? Or you just want to be more "professional" than using a simple Arduino. The commonly-known and willingly chosen solutions are STM32 microchips and boards. With HAL library and STM32 Cube IDE gives tons of possibilities without being too overwhelming (nevertheless, this is a significant step-up of complexity referring to the Arduino). Fortunately, there are many resources and guides on this topic - in my opinion, this is the way to start.

But if you want to step deeper and don't want to use functions that you don't understand, here comes STM32 and programming on registers. This is much more complex and requires a lot of manual reading. However, that gives a better understanding of what is going on under the hoodie of HAL functions, and for me, it was what I was looking for. 

I started with the Nucleo board (L053R8) and that was great at the beginning but after the first iteration of the drone, I realize that I need something more powerful. Next, I was looking for an F4 board, but I didn't like the size of the Nucleo. Also, the idea of connecting external modules (IMU, FLASH...)  with gold pins and all these cables lying around was not so encouraging. Then I thought, why not use the existing FC and program it with my own software? On these boards, there are IMU, flash modules, pinouts for PWMs and much more well-thought design in a small package (about 30x30 [mm] or even smaller). So it was my next step. Moreover, when I'm using real FC my drone seems to be more professional, so it gives +10 to confidence. 

But here is the first question: how to program FC if you only know how to connect the Nucleo to your computer?

If you ever programmed Nucleo board: you just plug USB into the computer, turn on IDE (STM32CubeIDE, Keil, System Workbench for STM32, PlatformIO, or anything you like), select your board and start programming. 


Luckily, for any other boards based on STM32, this is no more complicated! Every STM32 microprocessor can be programmed via ST-link. To do this, you need to find a pinout for SWCLK, SWDIO, any GND and VCC. Then you connect those pins to the STM32 programmer. It can be a ST-Link v2 programmer or any Nucleo board (how to use Nucleo as a programmer).


There is a small catch, usually, the RESET pin is not provided on embedded systems, so you have to set software reset instead of hardware reset in your IDE. Now you can program your FC as a traditional Nucleo board. 
If you don't want to use any IDE and go deeper into a compilation, building, and debugging microprocessors, there will be a post about the configuration of Visual Studio Code for STM32 development.

How to find out what and how is connected to my board?

Since I am using a board that has permanently connected modules. Specific pins of microprocessor need to be programmed for specific functionality, there is a problem: which pins are for what?
Fortunately, a few things can help to find this information:
  1. In the beginning, it is worth checking the Betaflight GitHub repository. There, you can find all boards that are supported and the software that they're using. For example, my board (MAMBA F405 MK2) uses FURYF4OSD - so I can find the header file where most of the connections are described - FURYF4OSD pinout.
  2. Next, you can check everything with a multimeter - just use probe mode and look for connections. It is not very convenient, but those boards are not too complicated and even beginners (like me) after some time will find out the electronic scheme. Also, it is very interesting to learn a design of such a board.
You don't have to find a layout of every pin at once. Start with LEDs and as you will grow your program you will add new features.

















Comments

Popular posts from this blog

USB with STM32

Filters - Theory