Setup custom targets in the "src/CMakeListst.txt" file. These include, the elf, hex, bin and an upload target.

This commit is contained in:
jakeg00dwin 2024-06-14 15:01:35 -07:00
parent d0809894ca
commit d4c3a251a2
2 changed files with 94 additions and 3 deletions

View File

@ -1,3 +1,41 @@
add_executable(main
add_executable(${PROJECT_NAME}
main.c
)
# Ensure the build rules are defined
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".elf")
if(NOT TARGET size)
# Set the size utility to display the size of the final binary
add_custom_target(size ALL
COMMAND ${CMAKE_SIZE} --format=avr --mcu=${AVR_MCU} ${CMAKE_PROJECT_NAME}.elf
DEPENDS ${CMAKE_PROJECT_NAME}.elf
)
endif()
if(NOT TARGET hex)
# Define how to convert ELF to HEX
add_custom_target(hex ALL
COMMAND ${CMAKE_OBJCOPY} -O ihex -R .eeprom ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.hex
DEPENDS ${CMAKE_PROJECT_NAME}.elf
)
endif()
if(NOT TARGET bin)
# Define how to convert ELF to BIN
add_custom_target(bin ALL
COMMAND ${CMAKE_OBJCOPY} -O binary -R .eeprom ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
DEPENDS ${CMAKE_PROJECT_NAME}.elf
)
endif()
if(NOT TARGET upload)
# Upload command (adjust according to your programmer)
add_custom_target(upload ALL
COMMAND avrdude -c usbtiny -p ${AVR_MCU} -U flash:w:${CMAKE_PROJECT_NAME}.hex
DEPENDS hex
)
endif()

View File

@ -1,8 +1,61 @@
#include "stdio.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>
//#############################
//Globals
//#############################
#define LED_PIN PB0
//#############################
//Prototypes
//#############################
void led_blink(void);
//#############################
//MAIN
//#############################
int main(int argc, char **argv)
{
printf("Hello!\n");
{
led_blink();
while(1) {
led_blink();
_delay_ms(500);
}
return 0;
}
//#############################
//FUNCTIONS
//#############################
/*
* Input: None
* Output: None
* Description: Toggles the pin for the LED indicator.
*/
void led_blink(void) {
//Set the DDR for output.
DDRC |= (1<<LED_PIN);
PORTC ^= (1<<LED_PIN);
_delay_ms(250);
PORTC ^= (1<<LED_PIN);
_delay_ms(250);
}