|
Visual Studio Code and PlatformIOVisual Studio Code is an open-source IDE. It appears a lot like the Microsoft Visual Studio IDE. I do not know if they have code in common or just a name and appearance. PlatformIO describes itself as "Your Gateway to Embedded Software Development Excellence" and appears to be a suite of command line tools to support embedded projects. PlatformIO is available as a plugin for the Visual Studio IDE, and the combination forms a quite attractive alternative to the Arduino IDE for embedded projects on AVR processors and some ARM platforms. Installation:The PlatformIO homepage explains the process https://platformio.org/install/ide?install=vscode Install VS Code Find the Plugin manager Find and install the PlatformIO extension After that PlatformIO is supposed to take care of automatically downloading the resources needed to build a project. The process isn't completely automatic, the "platformio.ini" file serves as a project file, but it does need to be edited manually to add certain project options. This is an example of a platformio.ini file for a Digispark project:
The file can have multiple [env:<platform>] entries for different boards or different builds for the same board. The PlatformIO "Create Project" function makes a minimal platformio.ini file. This is a file for a attiny85 standalone project. Unlike the Digispark this is just the microcontroller, and a programmer will be required.
Caution: at this time I am not clear if this will work or not. Turns out that as I'm using an Arduino-based programmer the programmer type needs to be "arduino". Who knew? Also f_cpu is the frequency used by the Arduino framework for calculating delays and does not set the actual CPU speed, which appears to default to 1MHz. There's some evidence that the Arduino IDE is setting a clock of 8MHz as a program outputting an "analogue" PWM signal is using 60Hz in VSCode and 500Hz in Arduino. Also it has the programmer COM port value embedded in it, and this will quite likely change. I am using source control and if the port setting is stored with the source then it will have to be changed to move between computers. The simplest solution is probably to comment out the setting and set it using an environment variable instead. I believe it is possible to specify the programmer's port in a Windows environment variable https://docs.platformio.org/en/latest/envvars.html#envvar-PLATFORMIO_UPLOAD_PORT but I am not clear on the details. Converting an INO file to a CPP fileVScode appears to open and edit Arduino "ino" files but it complains as some IDE features expect CPP syntax. The main changes you will need to make are:
A declaration looks like the first line of the function up to just before the first curly bracket and ends in a semicolon. ATtiny85 fuse settings:
These match the datasheet defaults and would be expected to give an 8MHz clock frequency. Datasheet section: 6.2.7 Default Clock Source states that the oscillator clock of 8 MHz with longest start-up time and an initial system clock prescaling of 8, resulting in 1.0 MHz system clock. |