Environment for Embedded programming

There are many IDE solutions on the web which require payment and which are free of charge; some are good and some are bad, but there is no universally perfect IDE. I personally tried a lot of them.

There are many IDE solutions on the web which require payment and which are free of charge; some are good and some are bad, but there is no universally perfect IDE. I personally tried a lot of them: Atmel Studio, Visual Studio, Arduino IDE, ARM Keil… and yes, they all get the job done but I didn’t like them, therefore PlatformIO IDE integration with VSCode text editor was the way to go. Is it for everyone? No. Is it good for programming every single chip in the world? No… But it works for me. In all of my tutorials in the future, for embedded development, I will use the solution explained in this text.

VSCode setup

Adding PlatformIO extension

System setup

Figure 1

	#include "Arduino.h"


	#define led 13

	void setup()	{}
	void loop()	{
		bool state = false;
		pinMode(led, OUTPUT);

		while(1)	{
			digitalWrite(led, state);
			state = !state;
			delay(1000);
		}
	}

Figure 2

Figure 3

This will override bootloader on your chip!

	#include "avr/io.h"

	#include "util/delay.h"


	#define t_bit(PORTx, PINx)	PORTx ^= 1 << PINx

	int main(void)	{
		DDRB |= 1 << PORTB5;
		while(1)	{
			t_bit(PORTB, PIN5);
			_delay_ms(100);
		}
		return 0;
	}

Linux

	"/home/____USER____/.platformio/packages/tool-avrdude/avrdude" -C"/home/____USER____/.platformio/packages/tool-avrdude/avrdude.conf" -v -p____CHIP_____ -cusbasp -Pu sb -Uflash:w:.pioenvs/____BOARD____/firmware.hex:i

Windows

	"C:/Users/____USER____/.platformio/packages/tool-avrdude/avrdude" -C"C:/Users/____USER____/.platformio/packages/tool-avrdude/avrdude.conf" -v -p____CHIP_____ -cusbasp -Pu sb -Uflash:w:.pioenvs/____BOARD____/firmware.hex:i

____USER____ is the Linux/Windows user. In my case it is banez.

____CHIP_____ is the name of MCU defined by PlatformIO. In my case it is atmega328p

____BOARD____ is the board defined in project. In my case it is uno.

	#include "mbed.h"


	int main(void) {
		DigitalOut led(PC_13);
		while(1) {
			led.write(1);
			wait(1);
			led.write(0);
			wait(1);
		}
	}
Share on: