Skip to content

Commit

Permalink
Add a command to run in QEMU (without debug)
Browse files Browse the repository at this point in the history
- Reformat code
- Documentation
  • Loading branch information
lucasdietrich committed Jun 27, 2022
1 parent abe5e68 commit 0ef0a9b
Show file tree
Hide file tree
Showing 33 changed files with 1,024 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enable_language(C CXX ASM)
# set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/avr6-atmega2560.cmake)
# include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/avr6-atmega2560.cmake)

set(QEMU OFF)
set(QEMU ON)

# set(F_CPU 16000000UL)
# set(MCU atmega2560)
Expand Down
5 changes: 4 additions & 1 deletion cmake/avr6-atmega2560.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ function(target_prepare_env target)
# generate launch.json file
configure_file(${CMAKE_CURRENT_FUNCTION_LIST_DIR}/qemu-avr-launch.json.in ${CMAKE_CURRENT_BINARY_DIR}/launch.${target}.json @ONLY)

# generate custom target for qemu
# generate custom target for debug in qemu
add_custom_target(qemu_${target}
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/launch.${target}.json ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../.vscode/launch.json
COMMAND qemu-system-avr -M ${QEMU_MCU} -bios ${ELF_PATH} -s -S -nographic)

# generate custom target for run in qemu
add_custom_target(run_${target}
COMMAND qemu-system-avr -M ${QEMU_MCU} -bios ${ELF_PATH} -nographic)

# disassembly
add_custom_command(TARGET ${target} POST_BUILD
Expand Down
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ The hardware timer used can be configured with CONFIG_KERNEL_SYSLOCK_HW_TIMER co
As [qemu](https://github.com/qemu/qemu) support [avr architecture](https://github.com/qemu/qemu/tree/master/target/avr), any program built using this RTOS can be emulated in qemu and debugged using GDB.
Use of `_delay_ms`, `sleep_cpu` is deprecated in QEMU.
### Overhead
- In term of flash, the overhead is approximately 3KB
- In term of RAM :
Expand Down Expand Up @@ -599,5 +601,17 @@ Priority *COOPERATIVE* :

## CMake

It's now possible to build the project with CMake.
- Install `CMake Tools` extension for VS Code, or simply execute `make build && cd build && make`

- When all samples are compiled for the given target, you can either :
- flash the program using `upload_sample_xxx`
- or run the program in `QEMU` with `run_sample_xxx`
- or even debug the program in `QEMU` with `qemu_sample_xxx` and then `Ctrl + F5` (VS Code)
- Then `Ctrl-A`+ `X` to exit `QEMU`

**Note: When running on QEMU, make sure to have compiled the sample with `__QEMU__` defined.**

### TODo
- Move ARCH, MCU, PORT, F_CPU, QEMU out of the general .cmake toolchain file
- Synchronize platformio.ini and CMakeLists.txt flags -> enhance python script `pio_export_defflags.py`
Loading

0 comments on commit 0ef0a9b

Please sign in to comment.