Code Monkey home page Code Monkey logo

Comments (4)

everskies avatar everskies commented on June 7, 2024 1

Hi, thank you for your prompt reply :) See here my CMakeLists.txt that I made for a NRF51:

set(PROJECT_NAME FusionRemote)

set(NRF_SDK "C:/Users/marci/tmp/nrf")
set(OPENOCD "C:/Users/marci/tmp/openocd")

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 98)

set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-c++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)

set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf51.ld")

set(COMMON_FLAGS "-DBOARD_PCA10028 -DSOFTDEVICE_PRESENT -DNRF51  -D__HEAP_SIZE=0  -DS130 -DBLE_STACK_SUPPORT_REQD   -DSWI_DISABLE0 -DBSP_UART_SUPPORT  -DNRF51422 -DNRF_SD_BLE_API_VERSION=2 ")

add_definitions(${COMMON_FLAGS})

set(CMAKE_C_FLAGS "${COMMON_FLAGS} -DARM_MATH_CM4 -mcpu=cortex-m0 -mthumb -mabi=aapcs -O3 -g3 -mfloat-abi=soft -ffunction-sections -fdata-sections -fno-strict-aliasing -fno-builtin --short-enums")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS}")
set(CMAKE_ASM_FLAGS "${COMMON_FLAGS} -x assembler-with-cpp")
set(CMAKE_EXE_LINKER_FLAGS "-mthumb -mabi=aapcs -L ${NRF_SDK}/components/toolchain/gcc -T${NRF5_LINKER_SCRIPT} -mcpu=cortex-m0 -mcpu=cortex-m0  -u _printf_float -u _scanf_float -Wl,--gc-sections --specs=nano.specs -lc -lnosys")
set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -o <TARGET>")
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_C_COMPILER} <LINK_FLAGS> <OBJECTS> -lstdc++ -o <TARGET>")

list(APPEND SDK_SOURCE_FILES
        ${NRF_SDK}/components/softdevice/common/softdevice_handler/softdevice_handler.c
        ${NRF_SDK}/components/toolchain/system_nrf51.c
        ${NRF_SDK}/components/toolchain/gcc/gcc_startup_nrf51.S
        ${NRF_SDK}/components/libraries/log/src/nrf_log_backend_serial.c
        ${NRF_SDK}/components/libraries/log/src/nrf_log_frontend.c
        ${NRF_SDK}/components/libraries/button/app_button.c
        ${NRF_SDK}/components/libraries/util/app_error.c
        ${NRF_SDK}/components/libraries/util/app_error_weak.c
        ${NRF_SDK}/components/libraries/fifo/app_fifo.c
        ${NRF_SDK}/components/libraries/timer/app_timer.c
        ${NRF_SDK}/components/libraries/util/app_util_platform.c
        ${NRF_SDK}/components/libraries/hardfault/hardfault_implementation.c
        ${NRF_SDK}/components/libraries/util/nrf_assert.c
        ${NRF_SDK}/components/libraries/util/sdk_errors.c
        ${NRF_SDK}/components/boards/boards.c
        ${NRF_SDK}/components/drivers_nrf/clock/nrf_drv_clock.c
        ${NRF_SDK}/components/drivers_nrf/common/nrf_drv_common.c
        ${NRF_SDK}/components/drivers_nrf/gpiote/nrf_drv_gpiote.c
        ${NRF_SDK}/components/libraries/bsp/bsp.c
        ${NRF_SDK}/components/libraries/bsp/bsp_btn_ble.c
        ${NRF_SDK}/components/libraries/bsp/bsp_nfc.c
        ${NRF_SDK}/external/segger_rtt/RTT_Syscalls_GCC.c
        ${NRF_SDK}/external/segger_rtt/SEGGER_RTT.c
        ${NRF_SDK}/external/segger_rtt/SEGGER_RTT_printf.c
        ${NRF_SDK}/components/ble/common/ble_advdata.c
        ${NRF_SDK}/components/ble/common/ble_conn_params.c
        ${NRF_SDK}/components/ble/ble_db_discovery/ble_db_discovery.c
        ${NRF_SDK}/components/ble/common/ble_srv_common.c
        ${NRF_SDK}/components/ble/ble_services/ble_nus_c/ble_nus_c.c
        ${NRF_SDK}/components/softdevice/common/softdevice_handler/softdevice_handler.c
        ${NRF_SDK}/components/drivers_nrf/adc/nrf_drv_adc.c
        ${NRF_SDK}/components/drivers_nrf/twi_master/nrf_drv_twi.c
        ${NRF_SDK}/components/libraries/gpiote/app_gpiote.c
        ${NRF_SDK}/components/drivers_nrf/timer/nrf_drv_timer.c
        src/main.c
        src/remote/comm.c
        src/remote/data_manager.c
        src/remote/buffer.c
        src/display/display_driver.c
        src/display/display.c
        src/utills.c
        )

include_directories(

        ${NRF_SDK}/components/softdevice/common/softdevice_handler
        ${NRF_SDK}/components/drivers_nrf/comp
        ${NRF_SDK}/components/drivers_nrf/twi_master
        ${NRF_SDK}/components/ble/ble_services/ble_ancs_c
        ${NRF_SDK}/components/ble/ble_services/ble_ias_c
        ${NRF_SDK}/components/softdevice/s130/headers
        ${NRF_SDK}/components/libraries/pwm
        ${NRF_SDK}/components/libraries/usbd/class/cdc/acm
        ${NRF_SDK}/components/libraries/usbd/class/hid/generic
        ${NRF_SDK}/components/libraries/usbd/class/msc
        ${NRF_SDK}/components/libraries/usbd/class/hid
        ${NRF_SDK}/components/libraries/log
        ${NRF_SDK}/components/ble/ble_services/ble_gls
        ${NRF_SDK}/components/libraries/fstorage
        ${NRF_SDK}/components/drivers_nrf/i2s
        ${NRF_SDK}/components/libraries/gpiote
        ${NRF_SDK}/components/drivers_nrf/gpiote
        ${NRF_SDK}/components/libraries/fifo
        ${NRF_SDK}/components/boards
        ${NRF_SDK}/components/drivers_nrf/common
        ${NRF_SDK}/components/ble/ble_advertising
        ${NRF_SDK}/components/drivers_nrf/adc
        ${NRF_SDK}/components/softdevice/s130/headers/nrf51
        ${NRF_SDK}/components/ble/ble_services/ble_bas_c
        ${NRF_SDK}/components/ble/ble_services/ble_hrs_c
        ${NRF_SDK}/components/libraries/queue
        ${NRF_SDK}/components/ble/ble_dtm
        ${NRF_SDK}/components/toolchain/cmsis/include
        ${NRF_SDK}/components/ble/ble_services/ble_rscs_c
        ${NRF_SDK}/components/ble/common
        ${NRF_SDK}/components/ble/ble_services/ble_lls
        ${NRF_SDK}/components/drivers_nrf/wdt
        ${NRF_SDK}/components/libraries/bsp
        ${NRF_SDK}/components/ble/ble_db_discovery
        ${NRF_SDK}/components/ble/ble_services/ble_bas
        ${NRF_SDK}/components/libraries/experimental_section_vars
        ${NRF_SDK}/components/ble/ble_services/ble_ans_c
        ${NRF_SDK}/components/libraries/slip
        ${NRF_SDK}/components/libraries/mem_manager
        ${NRF_SDK}/external/segger_rtt
        ${NRF_SDK}/components/libraries/usbd/class/cdc
        ${NRF_SDK}/components/drivers_nrf/hal
        ${NRF_SDK}/components/ble/ble_services/ble_nus_c
        ${NRF_SDK}/components/drivers_nrf/rtc
        ${NRF_SDK}/components/ble/ble_services/ble_ias
        ${NRF_SDK}/components/libraries/usbd/class/hid/mouse
        ${NRF_SDK}/components/drivers_nrf/ppi
        ${NRF_SDK}/components/ble/ble_services/ble_dfu
        ${NRF_SDK}/components/drivers_nrf/twis_slave
        ${NRF_SDK}/components
        ${NRF_SDK}/components/libraries/scheduler
        ${NRF_SDK}/components/ble/ble_services/ble_lbs
        ${NRF_SDK}/components/ble/ble_services/ble_hts
        ${NRF_SDK}/components/drivers_nrf/delay
        ${NRF_SDK}/components/libraries/crc16
        ${NRF_SDK}/components/drivers_nrf/timer
        ${NRF_SDK}/components/libraries/util
        ${NRF_SDK}/components/drivers_nrf/pwm
        ${NRF_SDK}/components/libraries/csense_drv
        ${NRF_SDK}/components/libraries/csense
        ${NRF_SDK}/components/drivers_nrf/rng
        ${NRF_SDK}/components/libraries/low_power_pwm
        ${NRF_SDK}/components/libraries/hardfault
        ${NRF_SDK}/components/ble/ble_services/ble_cscs
        ${NRF_SDK}/components/libraries/hci
        ${NRF_SDK}/components/libraries/usbd/class/hid/kbd
        ${NRF_SDK}/components/drivers_nrf/spi_slave
        ${NRF_SDK}/components/drivers_nrf/lpcomp
        ${NRF_SDK}/components/libraries/timer
        ${NRF_SDK}/components/drivers_nrf/power
        ${NRF_SDK}/components/libraries/usbd/config
        ${NRF_SDK}/components/toolchain
        ${NRF_SDK}/components/libraries/led_softblink
        ${NRF_SDK}/components/drivers_nrf/qdec
        ${NRF_SDK}/components/ble/ble_services/ble_cts_c
        ${NRF_SDK}/components/drivers_nrf/spi_master
        ${NRF_SDK}/components/ble/ble_services/ble_nus
        ${NRF_SDK}/components/ble/ble_services/ble_hids
        ${NRF_SDK}/components/drivers_nrf/pdm
        ${NRF_SDK}/components/libraries/crc32
        ${NRF_SDK}/components/libraries/usbd/class/audio
        ${NRF_SDK}/components/ble/peer_manager
        ${NRF_SDK}/components/drivers_nrf/swi
        ${NRF_SDK}/components/ble/ble_services/ble_tps
        ${NRF_SDK}/components/ble/ble_services/ble_dis
        ${NRF_SDK}/components/device
        ${NRF_SDK}/components/ble/nrf_ble_qwr
        ${NRF_SDK}/components/libraries/button
        ${NRF_SDK}/components/libraries/usbd
        ${NRF_SDK}/components/drivers_nrf/saadc
        ${NRF_SDK}/components/ble/ble_services/ble_lbs_c
        ${NRF_SDK}/components/ble/ble_racp
        ${NRF_SDK}/components/toolchain/gcc
        ${NRF_SDK}/components/libraries/fds
        ${NRF_SDK}/components/libraries/twi
        ${NRF_SDK}/components/drivers_nrf/clock
        ${NRF_SDK}/components/ble/ble_services/ble_rscs
        ${NRF_SDK}/components/drivers_nrf/usbd
        ${NRF_SDK}/components/softdevice/common/softdevice_handler
        ${NRF_SDK}/components/ble/ble_services/ble_hrs
        ${NRF_SDK}/components/libraries/log/src
        ${NRF_SDK}/components/drivers_nrf/twi_master
        src/config
        src/remote
        src/display
        src/
        src/display/fonts
)
set_property(SOURCE ${NRF_SDK}/components/toolchain/gcc/gcc_startup_nrf51.S PROPERTY LANGUAGE C)


add_executable(${PROJECT_NAME} ${SDK_SOURCE_FILES} ${SOURCE_FILES})

set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".out")
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-Wl,-Map=${PROJECT_NAME}.map")

add_custom_command(TARGET ${PROJECT_NAME}
        POST_BUILD
        COMMAND arm-none-eabi-size ${PROJECT_NAME}.out
        COMMAND arm-none-eabi-objcopy -O binary ${PROJECT_NAME}.out "${PROJECT_NAME}.bin"
        COMMAND arm-none-eabi-objcopy -O ihex ${PROJECT_NAME}.out "${PROJECT_NAME}.hex"
        COMMENT "post build steps for ${PROJECT_NAME}")

add_custom_target("FLASH_${PROJECT_NAME}" ALL
        COMMAND ${OPENOCD}/bin/openocd.exe -d2 -f ${OPENOCD}/share/openocd/scripts/board/ble_nano.cfg -s ${OPENOCD}/share/openocd/scripts/ -c "reset halt; program ${PROJECT_NAME}.hex verify; reset run; exit" 2>&1
        COMMENT "Flashing Firmware"
        USES_TERMINAL
        )

And the linker file for NRF51822 + S130 SoftDevice

/* Linker script to configure memory regions. */

SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)

MEMORY
{
  FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
  RAM (rwx) :  ORIGIN = 0x20001eb0, LENGTH = 0x6150
}

SECTIONS
{
  .fs_data :
  {
    PROVIDE(__start_fs_data = .);
    KEEP(*(.fs_data))
    PROVIDE(__stop_fs_data = .);
  } > RAM
  .pwr_mgmt_data :
  {
    PROVIDE(__start_pwr_mgmt_data = .);
    KEEP(*(.pwr_mgmt_data))
    PROVIDE(__stop_pwr_mgmt_data = .);
  } > RAM
} INSERT AFTER .data;

INCLUDE "nrf5x_common.ld"

The project itself is based on an UART example that comes with the SDK that i built upon.

My problem lies with -iex "monitor program $<TARGET_FILE:$${PROJECT_NAME}.elf>.
I can only write the .hex file that I get after objcopy to the NRF51. I don't understand the technicalities behind why a .hex file will work and the elf file won't, but flashing the .elf results in a hard fault.

from clion-embedded-arm.

elmot avatar elmot commented on June 7, 2024

Passing hex to gdb as a symbol file does not make any sense. Moreover, most probably it won't work. I pass .elf file to gdb. If you look at the cmake template https://github.com/elmot/clion-embedded-arm/blob/master/resources/xyz/elmot/clion/cubemx/tmpl_CMakeLists.txt, you can see, .elf is the target, and there is a separate custom_command to generate .hex and .bin. Btw, i am interested in nrf chips, can you, please, share your project as a example?

from clion-embedded-arm.

elmot avatar elmot commented on June 7, 2024

Because they are different formats. elf is generic object/executable with some extra info, .hex - just binary data. I will try NRF when I get a board, and for now try to adapt my template to your project.
Another option is to use remote gdb and openocd. But the setup is a little bit tricky.

from clion-embedded-arm.

everskies avatar everskies commented on June 7, 2024

All right, thank you!
I'm currently using GDB + OpenOCD which works fine. Just need pass the .out/.elf file as the symbol file.

from clion-embedded-arm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.