diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-04-11 14:31:45 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-04-11 14:31:45 +0200 |
commit | a2cd704ca2690d77d0ad05e2f1b97d8bbb2305d7 (patch) | |
tree | b528969571d6dcad20a8c6600c52733989daec9e /microblaze-vitis/hello_world | |
parent | a1f490fccb27f1b886840269403f84cf5eb0ba3b (diff) |
Diffstat (limited to 'microblaze-vitis/hello_world')
-rw-r--r-- | microblaze-vitis/hello_world/.gitignore | 17 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/CMakeLists.txt | 61 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/Hello_worldExample.cmake | 9 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/UserConfig.cmake | 157 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/app.yaml | 3 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/lscript.ld | 211 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/src/main.c | 46 | ||||
-rw-r--r-- | microblaze-vitis/hello_world/vitis-comp.json | 18 |
8 files changed, 522 insertions, 0 deletions
diff --git a/microblaze-vitis/hello_world/.gitignore b/microblaze-vitis/hello_world/.gitignore new file mode 100644 index 0000000..9b16e22 --- /dev/null +++ b/microblaze-vitis/hello_world/.gitignore @@ -0,0 +1,17 @@ +# Ignore build output directory +/build + + +# Ignore object files and dependent files +.o +.d + +#Ignore logs folder and log files +/logs +.log + +#Ignore lock files +.lock + +.bin +.pdi
\ No newline at end of file diff --git a/microblaze-vitis/hello_world/src/CMakeLists.txt b/microblaze-vitis/hello_world/src/CMakeLists.txt new file mode 100644 index 0000000..a8b7a49 --- /dev/null +++ b/microblaze-vitis/hello_world/src/CMakeLists.txt @@ -0,0 +1,61 @@ +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: MIT +cmake_minimum_required(VERSION 3.16) + +include(${CMAKE_CURRENT_SOURCE_DIR}/Hello_worldExample.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/UserConfig.cmake) +set(APP_NAME hello_world) +project(${APP_NAME}) + +enable_language(C ASM CXX) +find_package(common) +collect(PROJECT_LIB_DEPS xilstandalone) +collect(PROJECT_LIB_DEPS xil) +collect(PROJECT_LIB_DEPS xiltimer) + + + + + + + + + + +collect(PROJECT_LIB_DEPS gcc) +collect(PROJECT_LIB_DEPS c) + +collect (PROJECT_LIB_SOURCES main.c) +collector_list (_sources PROJECT_LIB_SOURCES) +foreach (source ${_sources}) + get_filename_component(ext ${source} EXT) + list(APPEND src_ext ${ext}) +endforeach() + +find_project_type ("${src_ext}" PROJECT_TYPE) + +if("${PROJECT_TYPE}" STREQUAL "c++") +collect(PROJECT_LIB_DEPS stdc++) +endif() +collector_list (_deps PROJECT_LIB_DEPS) +list (APPEND _deps ${USER_LINK_LIBRARIES}) + +if("${PROJECT_TYPE}" STREQUAL "c++") +string (REPLACE ";" ",-l" _deps "${_deps}") +endif() +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() +linker_gen("${CMAKE_CURRENT_SOURCE_DIR}/linker_files/") +string(APPEND CMAKE_C_FLAGS ${USER_COMPILE_OPTIONS}) +string(APPEND CMAKE_CXX_FLAGS ${USER_COMPILE_OPTIONS}) +string(APPEND CMAKE_C_LINK_FLAGS ${USER_LINK_OPTIONS}) +string(APPEND CMAKE_CXX_LINK_FLAGS ${USER_LINK_OPTIONS}) +set_source_files_properties(${_sources} OBJECT_DEPENDS "${CMAKE_LIBRARY_PATH}/*.a") +add_executable(${APP_NAME}.elf ${_sources}) +set_target_properties(${APP_NAME}.elf PROPERTIES LINK_DEPENDS ${CMAKE_SOURCE_DIR}/lscript.ld) +target_link_libraries(${APP_NAME}.elf -Wl,-T -Wl,\"${CMAKE_SOURCE_DIR}/lscript.ld\" -L\"${CMAKE_SOURCE_DIR}/\" -L\"${CMAKE_LIBRARY_PATH}/\" -L\"${USER_LINK_DIRECTORIES}/\" -Wl,--start-group,-l${_deps} -Wl,--end-group) +target_compile_definitions(${APP_NAME}.elf PUBLIC ${USER_COMPILE_DEFINITIONS}) +target_include_directories(${APP_NAME}.elf PUBLIC ${USER_INCLUDE_DIRECTORIES}) +print_elf_size(CMAKE_SIZE ${APP_NAME}) diff --git a/microblaze-vitis/hello_world/src/Hello_worldExample.cmake b/microblaze-vitis/hello_world/src/Hello_worldExample.cmake new file mode 100644 index 0000000..7aa8be4 --- /dev/null +++ b/microblaze-vitis/hello_world/src/Hello_worldExample.cmake @@ -0,0 +1,9 @@ +set(DDR lmb_bram_0) +set(lmb_bram_0 "0x50;0x7fb0") +set(TOTAL_MEM_CONTROLLERS "lmb_bram_0") +set(MEMORY_SECTION "MEMORY +{ + lmb_bram_0 : ORIGIN = 0x50, LENGTH = 0x7fb0 +}") +set(STACK_SIZE 0x400) +set(HEAP_SIZE 0x400) diff --git a/microblaze-vitis/hello_world/src/UserConfig.cmake b/microblaze-vitis/hello_world/src/UserConfig.cmake new file mode 100644 index 0000000..58cc778 --- /dev/null +++ b/microblaze-vitis/hello_world/src/UserConfig.cmake @@ -0,0 +1,157 @@ +# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: MIT +cmake_minimum_required(VERSION 3.16) + +### USER SETTINGS START ### +# Below settings can be customized +# User need to edit it manually as per their needs. +### DO NOT ADD OR REMOVE VARIABLES FROM THIS SECTION ### +# ----------------------------------------- +# Add any compiler definitions, they will be added as extra definitions +# Example adding VERBOSE=1 will pass -DVERBOSE=1 to the compiler. +set(USER_COMPILE_DEFINITIONS +"" +) + +# Undefine any previously specified compiler definitions, either built in or provided with a -D option +# Example adding MY_SYMBOL will pass -UMY_SYMBOL to the compiler. +set(USER_UNDEFINED_SYMBOLS +"__clang__" +) + + +# Add any directories below, they will be added as extra include directories. +# Example 1: Adding /proj/data/include will pass -I/proj/data/include +# Example 2: Adding ../../common/include will consider the path as relative to this component directory. +# Example 3: Adding ${CMAKE_SOURCE_DIR}/data/include to add data/include from this project. + +set(USER_INCLUDE_DIRECTORIES +) + +# ----------------------------------------- + +# Turn on all optional warnings (-Wall) +set(USER_COMPILE_WARNINGS_ALL -Wall) + +# Enable extra warning flags (-Wextra) +set(USER_COMPILE_WARNINGS_EXTRA -Wextra) + +# Make all warnings into hard errors (-Werror) +set(USER_COMPILE_WARNINGS_AS_ERRORS ) + +# Check the code for syntax errors, but don't do anything beyond that. (-fsyntax-only) +set(USER_COMPILE_WARNINGS_CHECK_SYNTAX_ONLY ) + +# Issue all the mandatory diagnostics listed in the C standard (-pedantic) +set(USER_COMPILE_WARNINGS_PEDANTIC ) + +# Issue all the mandatory diagnostics, and make all mandatory diagnostics into errors. (-pedantic-errors) +set(USER_COMPILE_WARNINGS_PEDANTIC_AS_ERRORS ) + +# Suppress all warnings (-w) +set(USER_COMPILE_WARNINGS_INHIBIT_ALL ) + +# ----------------------------------------- + +# Optimization level "-O0" [None] , "-O1" [Optimize] , "-O2" [Optimize More], "-O3" [Optimize Most] or "-Os" [Optimize Size] +set(USER_COMPILE_OPTIMIZATION_LEVEL -O0) + +# Other flags related to optimization +set(USER_COMPILE_OPTIMIZATION_OTHER_FLAGS ) + +# ----------------------------------------- + +# Debug level "" [None], "-g1" [Minimum], "g2" [Default], "g3" [Maximim] +set(USER_COMPILE_DEBUG_LEVEL -g3) + +# Other flags releated to debugging +set(USER_COMPILE_DEBUG_OTHER_FLAGS ) + +# ----------------------------------------- + +# Enable Profiling (-pg) (This feature is not supported currently) +# set(USER_COMPILE_PROFILING_ENABLE ) + +# ----------------------------------------- + +# Verbose (-v) +set(USER_COMPILE_VERBOSE ) + +# Support ANSI_PROGRAM (-ansi) +set(USER_COMPILE_ANSI ) + +# Add any compiler options that are not covered by the above variables, they will be added as extra compiler options +# To enable profiling -pg [ for gprof ] or -p [ for prof information ] +set(USER_COMPILE_OTHER_FLAGS ) + +# ----------------------------------------- + +# Linker options +# Do not use the standard system startup files when linking. +# The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used. (-nostartfiles) +set(USER_LINK_NO_START_FILES ) + +# Do not use the standard system libraries when linking. (-nodefaultlibs) +set(USER_LINK_NO_DEFAULT_LIBS ) + +# Do not use the standard system startup files or libraries when linking. (-nostdlib) +set(USER_LINK_NO_STDLIB ) + +# Omit all symbol information (-s) +set(USER_LINK_OMIT_ALL_SYMBOL_INFO ) + + +# ----------------------------------------- + +# Add any libraries to be linked below, they will be added as extra libraries. +# User need to update USER_LINK_DIRECTORIES below with these library paths. +set(USER_LINK_LIBRARIES +) + +# Add any directories to look for the libraries to be linked. +# Example 1: Adding /proj/compression/lib will pass -L/proj/compression/lib to the linker. +# Example adding Adding ../../common/lib will consider the path as relative to this directory. and will pass the path to -L option. +set(USER_LINK_DIRECTORIES +) + +# ----------------------------------------- + +set(USER_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/lscript.ld") + +# Add linker options to be passed, they will be added as extra linker options +# Example : adding -s will pass -s to the linker. +set(USER_LINK_OTHER_FLAGS +) + +# ----------------------------------------- + +### END OF USER SETTINGS SECTION ### +### DO NOT EDIT BEYOND THIS LINE ### + +set(USER_COMPILE_OPTIONS + " ${USER_COMPILE_WARNINGS_ALL}" + " ${USER_COMPILE_WARNINGS_EXTRA}" + " ${USER_COMPILE_WARNINGS_AS_ERRORS}" + " ${USER_COMPILE_WARNINGS_CHECK_SYNTAX_ONLY}" + " ${USER_COMPILE_WARNINGS_PEDANTIC}" + " ${USER_COMPILE_WARNINGS_PEDANTIC_AS_ERRORS}" + " ${USER_COMPILE_WARNINGS_INHIBIT_ALL}" + " ${USER_COMPILE_OPTIMIZATION_LEVEL}" + " ${USER_COMPILE_OPTIMIZATION_OTHER_FLAGS}" + " ${USER_COMPILE_DEBUG_LEVEL}" + " ${USER_COMPILE_DEBUG_OTHER_FLAGS}" + " ${USER_COMPILE_VERBOSE}" + " ${USER_COMPILE_ANSI}" + " ${USER_COMPILE_OTHER_FLAGS}" +) +foreach(entry ${USER_UNDEFINED_SYMBOLS}) + list(APPEND USER_COMPILE_OPTIONS " -U${entry}") +endforeach() + +set(USER_LINK_OPTIONS + " ${USER_LINKER_NO_START_FILES}" + " ${USER_LINKER_NO_DEFAULT_LIBS}" + " ${USER_LINKER_NO_STDLIB}" + " ${USER_LINKER_OMIT_ALL_SYMBOL_INFO}" + " ${USER_LINK_OTHER_FLAGS}" +) diff --git a/microblaze-vitis/hello_world/src/app.yaml b/microblaze-vitis/hello_world/src/app.yaml new file mode 100644 index 0000000..8b9d32d --- /dev/null +++ b/microblaze-vitis/hello_world/src/app.yaml @@ -0,0 +1,3 @@ +domain_path: /home/loek/dl/week4vitis/platform/export/platform/sw/standalone_microblaze_0 +app_src_dir: /mnt/e/Xilinx/Vitis/2023.2/data/embeddedsw/lib/sw_apps/hello_world +template: hello_world diff --git a/microblaze-vitis/hello_world/src/lscript.ld b/microblaze-vitis/hello_world/src/lscript.ld new file mode 100644 index 0000000..0e0fce6 --- /dev/null +++ b/microblaze-vitis/hello_world/src/lscript.ld @@ -0,0 +1,211 @@ +/****************************************************************************** +* Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved. +* SPDX-License-Identifier: MIT +******************************************************************************/ + +_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400; +_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x400; + +MEMORY +{ + lmb_bram_0 : ORIGIN = 0x50, LENGTH = 0x7fb0 +} + +/* Specify the default entry point to the program */ + +ENTRY(_start) + +/* Define the sections, and where they are mapped in memory */ + +SECTIONS +{ +.vectors.reset 0x0 : { + KEEP (*(.vectors.reset)) +} + +.vectors.sw_exception 0x8 : { + KEEP (*(.vectors.sw_exception)) +} + +.vectors.interrupt 0x10 : { + KEEP (*(.vectors.interrupt)) +} + +.vectors.hw_exception 0x20 : { + KEEP (*(.vectors.hw_exception)) +} + +.text : { + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.note.gnu.build-id) +} > lmb_bram_0 + +.init : { + KEEP (*(.init)) +} > lmb_bram_0 + +.fini : { + KEEP (*(.fini)) +} > lmb_bram_0 + +.ctors : { + __CTOR_LIST__ = .; + ___CTORS_LIST___ = .; + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + ___CTORS_END___ = .; +} > lmb_bram_0 + +.dtors : { + __DTOR_LIST__ = .; + ___DTORS_LIST___ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + PROVIDE(__DTOR_END__ = .); + PROVIDE(___DTORS_END___ = .); +} > lmb_bram_0 + +.drvcfg_sec : { + . = ALIGN(8); + __drvcfgsecdata_start = .; + KEEP (*(.drvcfg_sec)) + __drvcfgsecdata_end = .; + __drvcfgsecdata_size = __drvcfgsecdata_end - __drvcfgsecdata_start; +} > lmb_bram_0 + +.rodata : { + __rodata_start = .; + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + __rodata_end = .; +} > lmb_bram_0 + +.sdata2 : { + . = ALIGN(8); + __sdata2_start = .; + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + . = ALIGN(8); + __sdata2_end = .; +} > lmb_bram_0 + +.sbss2 : { + __sbss2_start = .; + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + __sbss2_end = .; +} > lmb_bram_0 + +.data : { + . = ALIGN(4); + __data_start = .; + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + __data_end = .; +} > lmb_bram_0 + +.got : { + *(.got) +} > lmb_bram_0 + +.got1 : { + *(.got1) +} > lmb_bram_0 + +.got2 : { + *(.got2) +} > lmb_bram_0 + +.eh_frame : { + *(.eh_frame) +} > lmb_bram_0 + +.jcr : { + *(.jcr) +} > lmb_bram_0 + +.gcc_except_table : { + *(.gcc_except_table) +} > lmb_bram_0 + +.sdata : { + . = ALIGN(8); + __sdata_start = .; + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + __sdata_end = .; +} > lmb_bram_0 + +.sbss (NOLOAD) : { + . = ALIGN(4); + __sbss_start = .; + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + . = ALIGN(8); + __sbss_end = .; +} > lmb_bram_0 + +.tdata : { + __tdata_start = .; + *(.tdata) + *(.tdata.*) + *(.gnu.linkonce.td.*) + __tdata_end = .; +} > lmb_bram_0 + +.tbss : { + __tbss_start = .; + *(.tbss) + *(.tbss.*) + *(.gnu.linkonce.tb.*) + __tbss_end = .; +} > lmb_bram_0 + +.bss (NOLOAD) : { + . = ALIGN(4); + __bss_start = .; + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(4); + __bss_end = .; +} > lmb_bram_0 + +_SDA_BASE_ = __sdata_start + ((__sbss_end - __sdata_start) / 2 ); + +_SDA2_BASE_ = __sdata2_start + ((__sbss2_end - __sdata2_start) / 2 ); + +/* Generate Stack and Heap definitions */ + +.heap (NOLOAD) : { + . = ALIGN(8); + _heap = .; + _heap_start = .; + . += _HEAP_SIZE; + _heap_end = .; +} > lmb_bram_0 + +.stack (NOLOAD) : { + _stack_end = .; + . += _STACK_SIZE; + . = ALIGN(8); + _stack = .; + __stack = _stack; +} > lmb_bram_0 + +_end = .; +} diff --git a/microblaze-vitis/hello_world/src/main.c b/microblaze-vitis/hello_world/src/main.c new file mode 100644 index 0000000..e202c4a --- /dev/null +++ b/microblaze-vitis/hello_world/src/main.c @@ -0,0 +1,46 @@ +#include "xparameters.h" +#include "xil_printf.h" +#include "xgpio.h" +#include "xil_types.h" + +// Get device IDs from xparameters.h +#define BTN_ID XPAR_AXI_GPIO_BUTTONS_DEVICE_ID +#define LED_ID XPAR_AXI_GPIO_LED_DEVICE_ID +#define BTN_CHANNEL 1 +#define LED_CHANNEL 1 +#define BTN_MASK 0x0000ffff +#define LED_MASK 0x0000ffff + +void show_buttons(u32 buttons) { + for (int i = 0; i < 16; i++) { + xil_printf("%s ", ((buttons >> 15) & 1) > 0 ? "1" : "0"); + buttons <<= 1; + } + xil_printf("\r\n"); + return; +} + +int main() { + xil_printf("boot'd\r\n"); + XGpio_Config *cfg_ptr; + XGpio led_device, btn_device; + + cfg_ptr = XGpio_LookupConfig(XPAR_AXI_GPIO_LEDS_BASEADDR); + XGpio_CfgInitialize(&led_device, cfg_ptr, cfg_ptr->BaseAddress); + cfg_ptr = XGpio_LookupConfig(XPAR_AXI_GPIO_BUTTONS_BASEADDR); + XGpio_CfgInitialize(&btn_device, cfg_ptr, cfg_ptr->BaseAddress); + XGpio_SetDataDirection(&btn_device, BTN_CHANNEL, BTN_MASK); + XGpio_SetDataDirection(&led_device, LED_CHANNEL, 0); + + + u32 data, old_data; + while (1) { + data = XGpio_DiscreteRead(&btn_device, BTN_CHANNEL); + data &= BTN_MASK; + XGpio_DiscreteWrite(&led_device, LED_CHANNEL, data); + + if (data != old_data) show_buttons(data); + + old_data = data; + } +}
\ No newline at end of file diff --git a/microblaze-vitis/hello_world/vitis-comp.json b/microblaze-vitis/hello_world/vitis-comp.json new file mode 100644 index 0000000..c929718 --- /dev/null +++ b/microblaze-vitis/hello_world/vitis-comp.json @@ -0,0 +1,18 @@ +{ + "name": "hello_world", + "type": "HOST", + "platform": "/home/loek/dl/week4vitis/platform/export/platform/platform.xpfm", + "domain": "standalone_microblaze_0", + "cpuInstance": "microblaze_0", + "cpuType": "microblaze", + "os": "standalone", + "configuration": { + "componentType": "HOST", + "hostToolchainConfigurations": [] + }, + "domainRealName": "standalone_microblaze_0", + "applicationFlow": "EMBEDDED", + "previousBuildStatusMap": { + "hw": "SUCCESS" + } +}
\ No newline at end of file |