This section describes how you would typically write code in Microchip Studio, independent of a software configuration tool or framework, i.e., bare-metal. This description is covered both as a video (linked below) and a hands-on document. The main focus is on the relevant programming references, how each is accessed, and their use. The project context is to turn ON an LED, then blink with a delay. Although using the ATtiny817 Xplained Pro, the principles are general enough to use with any kit in Microchip Studio, though the principles apply to most devices supported in Microchip Studio.
Video: I/O View and Bare-metal programming references
The list below is an overview of the typically used programming references. Particular emphasis is placed on the I/O view, which provides a way to navigate the data sheet register descriptions when editing or debugging and understanding the current configuration when debugging. This second use of the I/O view when using debugging to test new register configurations.
This topic is closely related to both Debugging 3: I/O View Memory View and Watch as well as Editor: Writing and Re-Factoring Code (Visual Assist).
#include <avr/io.h> #define F_CPU 3333333 #include <util/delay.h> int main(void) { PORTB.DIR = PIN4_bm; while (1) { _delay_ms(500); PORTB.OUTTGL = PIN4_bm; } }
Microchip Studio allows easy access to the data sheet register descriptions by clicking F1 on the relevant register description. The HTML version of the data sheet opens online (by default). The data sheet will open in the context of the relevant register description.
Button | Functionality | Keyboard Shortcut |
---|---|---|
Start Debugging and Break | Alt + F5 | |
Attach to Target | ||
Start Debugging | F5 | |
Break All | Ctrl + Alt + Break | |
Start Without Debugging | Ctrl + F5 |
Specifically, in the video related to this section, the editor is used for the following.
Through the Goto Definition functionality of the editor, it is easy to access the MCU device header files, i.e., by clicking on any register and then clicking on the goto button or typing Alt+G. Writing PORTB gives a suggestion list of potential registers from the PORT structure, shown in figure Suggestion lists and the MCU device header files. For more information about how the AVR header files are structured, see AVR1000.
Silkscreen Text | ATtiny817 GPIO Pin |
---|---|
LED0 | PB4 |
SW0 | PB5 |
0
' when pushed and as '1
' when released,
if the ATtiny817 internal pull-up is enabledAll the references covered to this point are just as relevant for SAM as for AVR. However, as the name suggests, this one is specific to AVR. AVR Libc is a Free Software project whose goal is to provide a high-quality C library for use together with GCC on AVR microcontrollers. Together, avr-binutils, avr-gcc, and avr-libc form the heart of the Free Software toolchain for the AVR microcontrollers. Further, they are accompanied by projects for in-system programming software (avrdude), simulation (simulavr), and debugging (avr-gdb, AVaRICE).
The library reference is usually a quick interface into AVR Libc, as shown in Figure 10. One can quickly search the page for a relevant library. The module name indicates the relevant header files added to the project. For example searching for 'interrupts', the relevant include will be #include <avr/interrupt.h>. A list of available functions and relevant interrupt callbacks shows when clicking into the module. See also Figure 11.
Atmel START is a web-based software configuration tool for various software frameworks, which help you get started with MCU development. Starting from either a new project or an example project, Atmel START allows you to select and configure software components (from ASF4 and AVR Code), such as drivers and middleware to tailor your embedded application in a usable and optimized manner. Once doing an optimized software configuration, you can download the generated code project and open it in the IDE of your choice, including Microchip Studio, MPLAB X, IAR Embedded Workbench, Keil μVision, or set up a make-file.
Although Atmel START is a tool for MCU and software configuration, it can still be helpful even in bare-metal development, i.e., writing code from scratch using the list of programming references described in this section. Creating a new project for the kit you are using can be a helpful alternative to the board schematic, using the PINMUX view. In addition, the CLOCKS view can be of use to check the default clocks of a device. Furthermore, viewing the configuration code, pieces of use can be pasted back into your project. For example, the AVR Libc delay functions require that the clock frequency is defined, as shown in Figure 14. For the ATtiny817, this default value would be: #define F_CPU 3333333.