# Programming

## {{@264#bkmrk-open-iot-and-iiot-ga}}

### Install IDE &amp; Programmer

Download and install [STM32CubeIDE](https://www.st.com/en/development-tools/stm32cubeide.html#get-software) for ability to creating own programs. For device programming, you must install [STM32CubeProgrammer](https://www.st.com/en/development-tools/stm32cubeprog.html). Follow the instructions located on the producer's site. Software is available on Windows, Linux and macOS. Of course, there is a possibility of using other IDEs, but Cube is dedicated to STM32 MCUs and provides a lot of compatible libraries.

### Connect the programmer

STM32 IoT and IIoT Gateways can be programmed only with the MCU producer's external hardware programmer - [ST LINK](https://www.st.com/en/development-tools/st-link-v2.html) - connected via the Tag-Connect connector to the board. After connecting it to the board and a PC, the device should be available in Device Manager as STM32 STLink in Universal Serial Bus devices.

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-02/scaled-1680-/Y3mimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-02/Y3mimage.png)

### Connect the power supply

The gateway works with 12-30V DC power supplies. Make sure your supply is properly set.

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-02/scaled-1680-/yKHimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-02/yKHimage.png)

### Create your own programs

After all of the above steps are done, the device should be ready to be programmed. Example scripts and repositories are available [here](https://doc.redisage.com/books/stm32-open-iot-and-iiot-gateways/chapter/examples).

### Build, flash and monitor the device

There are two options for building your program.


##### STM32CubeIDE

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/image.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/image.png)

Right click on your project and choose Debug As -&gt; STM32 C/C++ Application. It should generate the .elf file in the Debug folder in the project.

##### CMake

The project can also be built in STM32CubeIDE via CMake. For more information and instructions check the producer's [instructions](https://www.st.com/resource/en/application_note/an5952-how-to-use-cmake-in-stm32cubeide-stmicroelectronics.pdf).

#### Flash

There are two ways to flash the device.

##### STM32CubeProgrammer

It is the most recommended to use Programmer.

Open the software and connect it to the ST-Link programmer.

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/fCjimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/fCjimage.png)

After successful connect you should see the device memory with addresses on the screen.

Click on the down-arrow on the left side of the screen and browse for your file path.

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/iWgimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/iWgimage.png)

Find the .elf file (it should always be generated in the Debug folder in your project's path).

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/Ezsimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/Ezsimage.png)

Click "Open".

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/4gJimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/4gJimage.png)

Click "Start Programming".

If programming have been done successfully, you should see on the screen some messages in pop-up windows and Log console.

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/dUIimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/dUIimage.png)

[![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/Vivimage.png)](https://doc.redisage.com/uploads/images/gallery/2025-01/Vivimage.png)

The Gateway has been programmed.

##### Flashing in IDE

It is possible to flash your program directly from STM32CubeIDE. However, this method works only with some simple, small projects without using CMake. Just click on the ![image.png](https://doc.redisage.com/uploads/images/gallery/2025-01/scaled-1680-/MXCimage.png) icon in the IDE, and after a few seconds, the device should be programmed. If it doesn't work, use the previous method.

#### Monitoring

You can connect the device to your computer using a console and Serial connection. To do so, you need two USB cables and a USB -&gt; UART Converter (for example, [C37](https://redisage.com/usb-converter/c37-to-1x-uart-3v3-logic-ftdi)).  
If the connection is correct, the device will be visible as a USB Serial Port (COMx/ttyUSB). You can use any console terminal with the Serial option. The baudrate depends on USB UART settings in the project.