How To: Visual Studio Code - NNDK 2.x on MacOS

Discussion to talk about software related topics only.
Post Reply
John.Ohl
Posts: 20
Joined: Mon Dec 03, 2012 7:00 pm

How To: Visual Studio Code - NNDK 2.x on MacOS

Post by John.Ohl »

I've been using VSCode for a while now for NetBurner development. Originally I followed the official tutorials (https://www.netburner.com/tag/visual-studio-code/) for the newer 3.x NNDK but it didn't work out of the box for one of our legacy products that uses the MOD5270.

Just in case anyone was interested in using VSCode for older devices here's an example makefile and configs that will get it up and running /w the 2.x NNDK for a MOD5270 /w the crypto libraries.

I use this on MacOS 12.5, though I don't think it would take much to get it working on Windows.

makefile

Code: Select all

NAME = $(PROJECT)
PATH := $(NBROOT)/gcc-m68k/bin:$(PATH)

CXXSRCS = $(shell find . -type f -name '*.cpp')
CSRCS = $(shell find . -type f -name '*.c')

ifneq ($(filter debug loaddebug,$(MAKECMDGOALS)),)
	_DEBUG=1
endif

CREATEDTARGS = htmldata.cpp

EXTRACFLAGS = -Os -I"$(shell pwd)" -I"$(shell pwd)/include"
EXTRADBCFLAGS = $(EXTRACFLAGS)

EXTRACXXFLAGS = $(EXTRACFLAGS)
EXTRADBCXXFLAGS = $(EXTRADBCFLAGS)

XTRALIB := $(NBROOT)/lib/cryptolib.a $(NBROOT)/lib/StdFFile.a
DBXTRALIB := $(NBROOT)/lib/DBcryptolib.a $(NBROOT)/lib/debugLibrary.a $(NBROOT)/lib/StdFFile.a

NBCOMPCODE = $(NBROOT)/pcbin/compcode
NBINCLUDE = "$(NBROOT)/include"

OBJDIR = Release
ifneq ($(_DEBUG),)
	OBJDIR = Debug
endif

include $(NBROOT)/make/main.mak

htmldata.cpp: $(wildcard html/*.*)
	$(shell mkdir -p $(OBJDIR))
	$(NBROOT)/pcbin/comphtml html -dindex.html -ohtmldata.cpp

$(NBROOT)/lib/cryptolib.a: lib
$(NBROOT)/lib/DBcryptolib.a: dblib
$(NBROOT)/lib/debugLibrary.a: lib
$(NBROOT)/lib/StdFFile.a: lib

.PHONY: all load debug loaddebug build-release build-debug lib dblib build-system-libs build-system-dblibs clean clean-build rebuild-system clean-system
all: build-release
load: build-release
debug: build-debug
loaddebug: build-debug

build-release:
	@cp $(TARGET) $(OBJDIR)/$(notdir $(TARGET))
	@cp $(TARGETAP) $(OBJDIR)/$(notdir $(TARGETAP))
	@rm htmldata.cpp

build-debug:
	@cp $(DBTARGET) $(OBJDIR)/$(notdir $(DBTARGET))
	@cp $(DBTARGETAP) $(OBJDIR)/$(notdir $(DBTARGETAP))
	@rm htmldata.cpp

lib: build-system-libs
build-system-libs:
	$(MAKE) -C $(NBROOT)/system libs

dblib: build-system-libs build-system-dblibs
build-system-dblibs:
	$(MAKE) -C $(NBROOT)/system debuglibs

# TODO: Add support for auto-patching libdep for Windows, currently it needs to be patched manually
ifneq ($(OS),Windows_NT)
dblib: patch-libdep
endif

# Patch the libdep.mak include path to fix missing targets MOD5270.a and DBMOD5270.a, it shouldn't be indented under dblib:
patch-libdep:
	$(shell sed -i '' "s/^[[:blank:]]\(.*\)libdep\.mak$$/\\1libdep.mak/" $(NBROOT)/make/last.mak)

clean: clean-build
clean-build:
	-@rm -r Release
	-@rm -r Debug

rebuild-system: clean-system lib dblib
clean-system:
	$(MAKE) -C $(NBROOT)/system cleanall

# The NB main.mak builds the s19 files in the $(NBROOT)/bin directory and the $(NAME).map file in $(OBJDIR) by default
# We need to add the flag to specify where the mapfile is located so compcode doesn't fail
$(TARGETAP): override COMPCODEFLAGS+=-M $(OBJDIR)/$(NAME).map
$(DBTARGETAP): override COMPCODEFLAGS+=-M $(OBJDIR)/$(NAME).map

# Fix missing IP for debug loads
loaddebug: override NBLOADCODE+=-I$(TARGETIP)
.vscode/c_cpp_properties.json

Code: Select all

{
    "configurations": [
        {
            "name": "Netburner MOD5270B",
            "customConfigurationVariables": {
                "PROJECT": "ExampleProjetName",
                "PLATFORM": "MOD5270B",
                "TARGETIP": "192.168.2.2"
            },
            "defines": [
                "MOD5270B",
                // "_DEBUG" Uncomment to let Intellisense know it should be in debug mode
            ],
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "browse": {
                "path": [
                    "${workspaceFolder}",
                    "${env:NBROOT}"
                ],
                "limitSymbolsToIncludedHeaders": false
            },
            "includePath": [
                "${workspaceFolder}",
                "${env:NBROOT}/include",
                "${env:NBROOT}/gcc-m68k/m68k-unknown-elf/include",
                "${env:NBROOT}/gcc-m68k/m68k-unknown-elf/include/c++/8.1.0",
                "${env:NBROOT}/gcc-m68k/m68k-unknown-elf/include/c++/8.1.0/m68k-unknown-elf",
                "${env:NBROOT}/gcc-m68k/m68k-unknown-elf/include/c++/8.1.0/backward",
                "${env:NBROOT}/gcc-m68k/m68k-unknown-elf/sys-include/**",
                "${env:NBROOT}/gcc-m68k/lib/gcc/m68k-unknown-elf/8.1.0/include",
                "${env:NBROOT}/gcc-m68k/lib/gcc/m68k-unknown-elf/8.1.0/include-fixed",
                "${env:NBROOT}/mod5270B/include"
            ],
            "compilerPath": "${env:NBROOT}/gcc-m68k/bin/m68k-elf-g++"
        }
    ],
    "version": 4
}
.vscode/launch.json

Code: Select all

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "NetBurner Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/Debug/DB${input:PROJECT}.elf",
            "args": [],
            "cwd": "${workspaceFolder}",
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "${env:NBROOT}/gcc-m68k/bin/m68k-elf-gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "text": "file '${workspaceFolder}/Debug/DB${input:PROJECT}.elf'"
                },
                {
                    "text": "set remotetimeout 10"
                },
                {
                    "text": "target remote ${input:TARGETIP}:2159"
                }
            ],
            "preLaunchTask": "Build Debug & Load Project"
        }
    ],
    "inputs": [
        {
            "id": "TARGETIP",
            "type": "command",
            "command": "cpptools.activeConfigCustomVariable",
            "args": "TARGETIP"
        },
        {
            "id": "PROJECT",
            "type": "command",
            "command": "cpptools.activeConfigCustomVariable",
            "args": "PROJECT"
        }
    ]
}
.vscode/tasks.json

Code: Select all

// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
{
    "version": "2.0.0",
    "options": {
        "env": {
            "NBROOT": "${env:NBROOT}",
            "PLATFORM": "${input:PLATFORM}",
            "PROJECT": "${input:PROJECT}",
            "TARGETIP": "${input:TARGETIP}"
        }
    },
    "tasks": [
        {
            "label": "Build Project",
            "type": "shell",
            "command": "make",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": "build",
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            }
        },
        {
            "label": "Build & Load Project",
            "type": "shell",
            "command": "make load",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Build Debug Project",
            "type": "shell",
            "command": "make debug",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            }
        },
        {
            "label": "Build Debug & Load Project",
            "type": "shell",
            "command": "make loaddebug",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            },
            "group": "build",
            "dependsOn": "Build Debug Project"
        },
        {
            "label": "Clean Project",
            "type": "shell",
            "command": "make clean",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            }
        },
        {
            "label": "Rebuild System Libraries",
            "type": "shell",
            "command": "make rebuild-system",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            }
        },
        {
            "label": "Run addr2line tool",
            "type": "shell",
            "command": "arm-eabi-addr2line -Cife obj/release/NetburnerBase.elf ${input:addr2line}",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": [
                    "relative",
                    "${workspaceFolder}"
                ]
            }
        }
    ],
    "inputs": [
        {
            "id": "addr2line",
            "type": "promptString",
            "description": "Enter the address to search"
        },
        {
            "id": "PLATFORM",
            "type": "command",
            "command": "cpptools.activeConfigCustomVariable",
            "args": "PLATFORM"
        },
        {
            "id": "PROJECT",
            "type": "command",
            "command": "cpptools.activeConfigCustomVariable",
            "args": "PROJECT"
        },
        {
            "id": "TARGETIP",
            "type": "command",
            "command": "cpptools.activeConfigCustomVariable",
            "args": "TARGETIP"
        }
    ]
}
Last edited by John.Ohl on Sun Jul 24, 2022 6:26 pm, edited 1 time in total.
User avatar
TomNB
Posts: 576
Joined: Tue May 10, 2016 8:22 am

Re: How To: Visual Studio Code - NNDK 2.x on MacOS

Post by TomNB »

Thank you for posting that John! We do see a lot of people using VSCode
Post Reply