<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Bare metal programming on the nRF9160</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92877/bare-metal-programming-on-the-nrf9160</link><description>I have purchased the nRF9160 Development Kit and are just getting started with the device and the nRF Connect SDK. 
 I intend to use the supplied LTE-M modem firmware for my project along with my own application firmware. However, it seems like all the</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Oct 2023 11:10:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92877/bare-metal-programming-on-the-nrf9160" /><item><title>RE: Bare metal programming on the nRF9160</title><link>https://devzone.nordicsemi.com/thread/450520?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2023 11:10:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:418e57b9-855d-4529-9aeb-e202e3a3b375</guid><dc:creator>nleday</dc:creator><description>&lt;p&gt;This post just saved me a few hours, thanks a lot ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bare metal programming on the nRF9160</title><link>https://devzone.nordicsemi.com/thread/391530?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 20:13:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26aef95a-3ffd-43e5-a828-8278c10b3e29</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;Have a look here &lt;a href="https://github.com/IOsonata/IOsonata/tree/master/ARM/Nordic"&gt;https://github.com/IOsonata/IOsonata/tree/master/ARM/Nordic&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bare metal programming on the nRF9160</title><link>https://devzone.nordicsemi.com/thread/391525?ContentTypeID=1</link><pubDate>Wed, 19 Oct 2022 18:37:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6192efb5-bff6-4d4b-b862-6bdd92d1f01b</guid><dc:creator>PVH</dc:creator><description>&lt;p&gt;Thanks, Sigurd :-)&lt;/p&gt;
&lt;p&gt;I have now created a makefile that can build a &amp;quot;blinky&amp;quot; example without Zephyr. I have only tested this with the &lt;span style="font-family:courier new, courier;"&gt;nrfx.h&lt;/span&gt; header, but I guess that it is possible to add C files from the nrfx library to the object list in the makefile, if one wishes to use the nrfx library for more than just easy register access.&lt;/p&gt;
&lt;p&gt;Example output when building and flashing:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Creating directory build
[CC] main.c --&amp;gt; build/main.o
Creating directory build/cmsis
[AS] /opt/nrfx-2.9.0/mdk/gcc_startup_nrf9160.S --&amp;gt; build/cmsis/startup.o
[CC] /opt/nrfx-2.9.0/mdk/system_nrf9160.c --&amp;gt; build/cmsis/system.o
[LD] build/blinky.axf
[OBJCOPY] ./build/blinky.axf --&amp;gt; ./build/blinky.hex
[OBJCOPY] ./build/blinky.axf --&amp;gt; ./build/blinky.bin

   text	   data	    bss	    dec	    hex	filename
   2144	    108	     36	   2288	    8f0	./build/blinky.axf

Flashing ./build/blinky.hex
Parsing image file.
Verifying programming.
Verified OK.
Applying system reset.
Run.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;It actually works and makes the LEDs light up on the board :-)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;main.c&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Bare metal nRF9160 DK &amp;quot;Blinky&amp;quot; example                     PVH, October 2022
#include &amp;quot;nrfx.h&amp;quot;

int main()
{
    // LED1..4 on the nRF9160 DK are connected to P0.02..P0.05 and are active 
    // high, so we first configure these pins on P0 as outputs
    NRF_P0-&amp;gt;DIRSET |= (1&amp;lt;&amp;lt;5) | (1&amp;lt;&amp;lt;4) | (1&amp;lt;&amp;lt;3) | (1&amp;lt;&amp;lt;2);

    while (1)
    {
        // In the main loop, we make each of the LEDs light up one at a time
        for (uint32_t i = 0; i &amp;lt; 4; ++i)
        {
            NRF_P0-&amp;gt;OUTSET |= 1&amp;lt;&amp;lt;(i+2);
            
            // Some delay
            volatile uint32_t j = 1000000;
            while (j &amp;gt; 0)
                --j;
            
            NRF_P0-&amp;gt;OUTCLR |= 1&amp;lt;&amp;lt;(i+2);
        }    
    }
    
    return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Makefile&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;# Makefile for nRF9160 bare metal programming                 PVH, October 2022

# Arm GNU toolchain can be found here (look for gcc-arm-none-eabi)
# https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain
# nrfx is available at https://github.com/NordicSemiconductor/nrfx
# CMSIS can be found at https://github.com/ARM-software/CMSIS_5

# Paths to toolchain and SDK
TOOLSPATH = /opt/gcc-arm-none-eabi-9-2020-q2-update
NRFXPATH = /opt/nrfx-2.9.0
CMSISPATH = /opt/CMSIS_5/CMSIS

# Specify project name, object files, headers (DEPS) and linker script
PROJECT = blinky
OBJ = main.o
DEPS =
LDSCRIPT = ${NRFXPATH}/mdk/nrf9160_xxaa.ld
BUILDDIR = ./build

# Startup and system code
ASTART = ${NRFXPATH}/mdk/gcc_startup_nrf9160.S
SYSSRC = ${NRFXPATH}/mdk/system_nrf9160.c

# Common flags for CC, AS and LD
FLAGS = -mcpu=cortex-m33 -mthumb -mfloat-abi=hard -mabi=aapcs  
FLAGS += -mfpu=fpv5-sp-d16 -DNRF9160_XXAA
FLAGS += -DCONFIG_GPIO_AS_PINRESET -DFLOAT_ABI_HARD

# Shortcuts for various tools
CC = ${TOOLSPATH}/bin/arm-none-eabi-gcc
AS = ${TOOLSPATH}/bin/arm-none-eabi-gcc
LD = ${TOOLSPATH}/bin/arm-none-eabi-gcc
OBJCOPY = ${TOOLSPATH}/bin/arm-none-eabi-objcopy
SIZETOOL = ${TOOLSPATH}/bin/arm-none-eabi-size

# Compiler flags
CFLAGS = ${FLAGS} -std=c99 -Wall -Werror
CFLAGS += -I&amp;quot;${NRFXPATH}/templates&amp;quot; -I&amp;quot;${NRFXPATH}/mdk&amp;quot;
CFLAGS += -I&amp;quot;${NRFXPATH}&amp;quot; -I&amp;quot;${CMSISPATH}/Core/Include&amp;quot;
CFLAGS += -I&amp;quot;${NRFXPATH}/hal&amp;quot; -I&amp;quot;${NRFXPATH}/drivers/include&amp;quot;

# Assembler flags
AFLAGS = ${FLAGS} -x assembler-with-cpp

# Linker flags
LDFLAGS = ${FLAGS} -T &amp;quot;$(LDSCRIPT)&amp;quot; -Xlinker
LDFLAGS += --gc-sections -Xlinker -Map=&amp;quot;$(BUILDDIR)/$(PROJECT).map&amp;quot; 
LDFLAGS += --specs=nano.specs
LDFLAGS += -L&amp;quot;${NRFXPATH}/mdk/&amp;quot;
LIBS = -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group

# Check whether to optimize or build for debugging
DEBUG ?= 0
ifeq ($(DEBUG), 1)
	CFLAGS += -O0 -g3 -gdwarf-2
	AFLAGS += -g3 -gdwarf-2
	LDFLAGS += -g3
else
	CFLAGS += -O3
endif

# Substitute the correct path for the object filenames
_OBJ = $(patsubst %,$(BUILDDIR)/%,$(OBJ))

# Define operations
define COMPILE
	@echo &amp;quot;[CC] $&amp;lt; --&amp;gt; $@&amp;quot;
	@$(CC) $(CFLAGS) -c -o $@ $&amp;lt;
endef

define ASSEMBLE
	@echo &amp;quot;[AS] $&amp;lt; --&amp;gt; $@&amp;quot;
	@$(AS) $(AFLAGS) -c -o $@ $&amp;lt;
endef

define OBJECTCOPY
	@echo &amp;quot;[OBJCOPY] $(2)$(3) --&amp;gt; $(2)$(4)&amp;quot;
	@$(OBJCOPY) $(1) $(2)$(3) $(2)$(4)
endef

define CREATEDIR
	@echo &amp;quot;Creating directory $@&amp;quot;
	@mkdir -p $@
endef

# Build the project

$(BUILDDIR)/$(PROJECT).axf: $(_OBJ)  \
    $(BUILDDIR)/cmsis/startup.o $(BUILDDIR)/cmsis/system.o
# Link
	@echo &amp;quot;[LD] $@&amp;quot;
	@$(LD) $(LDFLAGS) -o $(BUILDDIR)/$(PROJECT).axf \
	$(BUILDDIR)/cmsis/startup.o \
	$(BUILDDIR)/cmsis/system.o \
	$(addprefix $(BUILDDIR)/, $(OBJ)) $(LIBS)
# Generate hex and bin files
	$(call OBJECTCOPY,-O ihex,$(BUILDDIR)/,&amp;quot;$(PROJECT).axf&amp;quot;,&amp;quot;$(PROJECT).hex&amp;quot;)
	$(call OBJECTCOPY,-O binary,$(BUILDDIR)/,&amp;quot;$(PROJECT).axf&amp;quot;,&amp;quot;$(PROJECT).bin&amp;quot;)
# Run the size tool
	@echo &amp;quot;&amp;quot;
	@$(SIZETOOL) $(BUILDDIR)/&amp;quot;$(PROJECT).axf&amp;quot;
	@echo &amp;quot;&amp;quot;
	
all: $(BUILDDIR)/$(PROJECT).axf

$(BUILDDIR):
	$(call CREATEDIR)

$(BUILDDIR)/cmsis: 	
	$(call CREATEDIR)
	
$(BUILDDIR)/cmsis/startup.o: $(ASTART) | $(BUILDDIR)/cmsis
	$(call ASSEMBLE)
    	
$(BUILDDIR)/cmsis/system.o: $(SYSSRC) | $(BUILDDIR)/cmsis
	$(call COMPILE)

$(BUILDDIR)/%.o: %.c $(DEPS) | $(BUILDDIR)
	$(call COMPILE)
	
# Remove builded stuff
clean:
	rm -dfr $(BUILDDIR)

# Flash the program
flash: $(BUILDDIR)/$(PROJECT).axf
	@echo Flashing $(BUILDDIR)/$(PROJECT).hex
	@nrfjprog -f nrf91 --program $(BUILDDIR)/$(PROJECT).hex --sectorerase \
	--verify --reset

erase:
	@echo Erasing all flash
	@nrfjprog -f nrf91 --eraseall&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The makefile is a bit messy and may contain errors or suboptimal settings or flags, so any suggestions are welcome, but so far, so good :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bare metal programming on the nRF9160</title><link>https://devzone.nordicsemi.com/thread/390991?ContentTypeID=1</link><pubDate>Mon, 17 Oct 2022 12:21:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ca187d7c-6ab3-4559-aa1b-83a204e5484a</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;See this post:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/79573/development-on-nrf9160-dk-without-zepyhr"&gt;Development on nrf9160 DK without zepyhr&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>