view local.cmake @ 27:e1d8fe3e418a

Run PIOs at 1x with delays and sync. Can now use a single trigger to set both DAC & ctrl. DAC [still] jitters against the ctrl though..
author Daniel O'Connor <darius@dons.net.au>
date Wed, 26 Feb 2025 11:03:59 +1030
parents b9ec45077bff
children
line wrap: on
line source

function(bin2elf TARGET BINFILE)
    cmake_parse_arguments(bin2elf "" "OUTPUT_DIR" "" ${ARGN})
    set(FILENAME "${CMAKE_SOURCE_DIR}/${BINFILE}")
    set(ELFNAME "${CMAKE_CURRENT_BINARY_DIR}/${BINFILE}.o")
    #message("FILENAME ${FILENAME} ELFNAME ${ELFNAME}")

    # Not sure why but we can't depend directly, have to create this intermediary
    # Copied idea from pico_generate_pio_header
    get_filename_component(BIN_GEN_TARGET ${BINFILE} NAME_WE)
    set(BIN_GEN_TARGET "${TARGET}_${BIN_GEN_TARGET}")
    add_custom_target(${BIN_GEN_TARGET} DEPENDS ${ELFNAME})

    # Create symbol name for bin file
    string(MAKE_C_IDENTIFIER ${BINFILE} BIN_SYMNAME)
    #message("BINFILE ${BINFILE} BIN_SYMNAME ${BIN_SYMNAME}")

    # Get directory name of source file
    # ld will name the symbol based on the full path so we have to mangle it
    get_filename_component(BIN_SRC_DIR ${FILENAME} DIRECTORY)
    string(MAKE_C_IDENTIFIER ${BIN_SRC_DIR} SRC_DIRNAME_MANGLED)
    #message("SRC_DIRNAME_MANGLED ${SRC_DIRNAME_MANGLED}")

    # http://stupefydeveloper.blogspot.com/2008/08/cc-embed-binary-data-into-elf.html
    add_custom_command(OUTPUT ${ELFNAME}
      COMMAND arm-none-eabi-ld -r -b binary -o ${ELFNAME}
 --defsym=${BIN_SYMNAME}_start=_binary_${SRC_DIRNAME_MANGLED}_${BIN_SYMNAME}_start
 --defsym=${BIN_SYMNAME}_end=_binary_${SRC_DIRNAME_MANGLED}_${BIN_SYMNAME}_end
 --defsym=${BIN_SYMNAME}_size=_binary_${SRC_DIRNAME_MANGLED}_${BIN_SYMNAME}_size
 ${FILENAME}
        DEPENDS ${FILENAME})
    add_dependencies(${TARGET} ${BIN_GEN_TARGET})

    # Add object file to list of things to be linked
    target_link_libraries(${TARGET} ${CMAKE_CURRENT_BINARY_DIR}/${ELFNAME})
endfunction()