VS code is one of the most used IDEs and configuring it to program a msp430 was easier as I expected. So let start blink a led from from vs code.
- Take any blink.c either from the net or from our older posts and copy it to you working folder.
- Configure the c/c++, so mainly it has to find your msp gcc compiler. This is an example configuration:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/opt/msp430-gcc/bin/msp430-elf-gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
- Test it by trying to find the definition of a symbol.
- Let’s build the blinker using cmake For this we need following files
- CMakePresets.json
{
"version": 8,
"configurePresets": [
{
"name": "msp430preset",
"displayName": "Configure preset using toolchain file",
"description": "Sets Ninja generator, build and install directory",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/msp430-gcc.cmake",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}"
}
}
]
}
- toolchain.cmake
set(MSP430_MCU "msp430f5438a")
set(MSP430_CFLAGS "")
set(MSP430_LFLAGS "")
#let cmake find our compiler
find_program(MSP430-ELF-GCC msp430-elf-gcc)
#set it
set(CMAKE_C_COMPILER ${MSP430-ELF-GCC})
function(msp430_add_executable EXECUTABLE)
set(EXECUTABLE_ELF "${EXECUTABLE}.elf")
# main target for the executable depends of elf
add_custom_target(${EXECUTABLE} ALL DEPENDS ${EXECUTABLE_ELF})
# compile and link elf file
add_executable(${EXECUTABLE_ELF} ${ARGN})
set_target_properties(${EXECUTABLE_ELF} PROPERTIES
COMPILE_FLAGS "-mmcu=${MSP430_MCU}")
endfunction(msp430_add_executable)
- CMakeLists.txt
cmake_minimum_required(VERSION 3.19)
message("Building blinker...")
project(blinker C)
msp430_add_executable(blinker blink.c)
and that is it… for now. Next step we need to ship the elf to the mcu 😉
Subscribe to get last updates.