Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page will guide you on how to run bare-metal newlib printf demo on following target boards.

...

Startup code for cortex M4 MCUs CMSIS:

Source:

Building a semi-hosting printf demo for Nitrogen Board:

Make sure your gcc_arm.ld reflects memory layout of nitrogen board in MEMORY section.

You may use startup code either from startup_ARMCM4.S or startup_ARMCM4.c

Pre-requisite:

  • arm-none-eabi-gcc 

Sample demo code:

Code Block
languagecpp
#include <stdio.h>
int main()
{
    printf("Hello, world!");
	printf("\n");
	return 0;
}


#ifndef __NO_SYSTEM_INIT
void SystemInit()
{}
#endif

Build command line:

Code Block
languagetext
arm-none-eabi-gcc semihost.c startup_ARMCM4.S -mthumb -mcpu=cortex-m4  -ffunction-sections -fdata-sections --specs = rdimon.specs -lc -T gcc_arm.ld -o semihost-CM4.axf

Start openOCD connected to Nitrogen board via CMSIS-DAP:

Instructions to build openOCD from source can be found here:

Code Block
languagebash
./src/openocd -s tcl/ -f interface/cmsis-dap.cfg -c "transport select swd" -f target/nrf52.cfg

Run demo using GDB:

Start arm-none-eabi-gdb with Nitrogen board semihosting bare-metal demo

Code Block
languagebash
arm-none-eabi-gdb semihost-CM4.axf

Connect to OpenOCD GDB stub while OpenOCD is connected to Nitrogen board via CMSIS-DAP

Code Block
languagebash
target extended-remote :3333

Send command to OpenOCD to enable arm semihosting via gdb monitor command

Code Block
languagebash
monitor arm semihosting enable

Load executable to the tagert

Code Block
languagebash
load

Run demo and you will see semihosting printf output on OpenOCD console

Code Block
languagebash
run

Enable OpenOCD semihosting_filio to view printf output on gdb console

Code Block
languagebash
monitor arm semihosting_fileio enable

...

Make sure following configuration is applied to openOCD source to enable bare-metal debugging on Beaglebone Black.

Pre-requisite:

  • arm-none-eabi-gcc 

Sample demo code:

...

languagecpp

...

This page will guide you on how to run bare-metal newlib printf demo on following target boards.

Anchor
Nitro
Nitro
Nitrogen Cortex-M4 target:

Startup code for cortex M4 MCUs CMSIS:

Source:

Building a semi-hosting printf demo for Nitrogen Board:

Make sure your gcc_arm.ld reflects memory layout of nitrogen board in MEMORY section.

You may use startup code either from startup_ARMCM4.S or startup_ARMCM4.c

Pre-requisite:

  • arm-none-eabi-gcc 

Sample demo code:

Code Block
languagecpp
#include <stdio.h>
int main()
{
    printf("Hello, world!");
	printf("\n");
	return 0;
}

Build command line:


}


#ifndef __NO_SYSTEM_INIT
void SystemInit()
{}
#endif

Build command line:

Code Block
languagetext
arm-none-eabi-gcc semihost.c startup_ARMCM4.S -mthumb -mcpu=cortex-m4  -ffunction-sections -fdata-sections --specs = rdimon.specs -lc -T gcc_arm.ld -o semihost-CM4.axf

Start openOCD connected to Nitrogen board via CMSIS-DAP:

Instructions to build openOCD from source can be found here:

Code Block
languagebash
./src/openocd -s tcl/ -f interface/cmsis-dap.cfg -c "transport select swd" -f target/nrf52.cfg

Run demo using GDB:

  • Start arm-none-eabi-gdb with Nitrogen board semihosting bare-metal demo

    Code Block
    languagebash
    arm-none-eabi-gdb semihost-CM4.axf


  • Connect to OpenOCD GDB stub while OpenOCD is connected to Nitrogen board via CMSIS-DAP

    Code Block
    languagebash
    target extended-remote :3333


  • Send command to OpenOCD to enable arm semihosting via gdb monitor command

    Code Block
    languagebash
    monitor arm semihosting enable


  • Load executable to the tagert

    Code Block
    languagebash
    load


  • Run demo and you will see semihosting printf output on OpenOCD console

    Code Block
    languagebash
    run


  • Enable OpenOCD semihosting_filio to view printf output on gdb console

    Code Block
    languagebash
    monitor arm semihosting_fileio enable



Anchor
BBB
BBB
Beaglebone Black Arm cortex A8 target:

Make sure following configuration is applied to openOCD source to enable bare-metal debugging on Beaglebone Black.

Pre-requisite:

  • arm-none-eabi-gcc 

Sample demo code:

Code Block
languagecpp
#include <stdio.h>
int main()
{
    printf("Hello, world!");
	printf("\n");
	return 0;
}

Build command line:

Code Block
languagebash
arm-none-eabi-gcc --specs=rdimon.specs -Xlinker -Ttext-segment=0x80000000 -Xlinker --defsym=__stack=0x80040000 -o arm-test-rdimon sample_demo.c

Start openOCD connected to Beaglebone Black via flyswatter2 debug adapter:

Instructions to build openOCD from source can be found here:

Code Block
languagebash
./src/openocd -s tcl/ -f interface/ftdi/flyswatter2.cfg -f board/ti_beaglebone_black.cfg

Run demo using GDB:

  • Start arm-none-eabi-gdb with Beaglebone Black board semihosting bare-metal demo

    Code Block
    languagebash
    arm-none-eabi-gdb arm-test-rdimon


  • Connect to OpenOCD GDB stub while OpenOCD is connected to Beaglebone Black via flyswatter2 debug adapter

    Code Block
    languagebash

...

arm-none-eabi-gcc --specs=rdimon.specs -Xlinker -Ttext-segment=0x80000000 -Xlinker --defsym=__stack=0x80040000 -o test-rdimon sample_demo.c

Start openOCD connected to Beaglebone Black via flyswatter2 debug adapter:

...

  • target extended-remote :3333


  • Send command to OpenOCD to enable arm semihosting via gdb monitor command

    Code Block
    languagebash
    monitor arm semihosting enable


  • Load executable to the tagert

    Code Block
    languagebash
    load


  • Run demo and you will see semihosting printf output on OpenOCD console

    Code Block
    languagebash
    run


  • Enable OpenOCD semihosting_filio to view printf output on gdb console

    Code Block
    languagebash

...

  • monitor arm semihosting_fileio enable


Note: You might have to connect/disconnect GDB with target a couple of times to ensure target is in stable connected state with openOCD.


Anchor
Hikey
Hikey
Hikey 96Board AArch64 cortex A53 target:

Make sure following configuration is applied to openOCD source to enable bare-metal debugging on Hikey.

Pre-requisite:

  • AArch64aarch64-elf-gcc 
Note

Note: You may also need Newlib sisroot and in that case have to build newlib for aarch64 targets

Sample demo code:

Code Block
languagecpp
#include <stdio.h>
int main()
{
    printf("Hello, world!");
	printf("\n");
	return 0;
}

...

h>
int main()
{
    printf("Hello, world!");
	printf("\n");
	return 0;
}

Build command line:

Code Block
languagebash
aarch64-elf-gcc -g -O0 -I${newlib-install}/aarch64-elf/include --sysroot=${newlib-install}/aarch64-elf/ -Xlinker --defsym=__stack=0x05D00000 --specs=rdimon.specs -o aarch64-test-rdimon sample_demo.c

Start openOCD connected to Hikey Board via BusBlaster v2 debug adapter:

Instructions to build openOCD from source can be found here:

Code Block
languagebash
aarch64-elf-gcc -g -O0 -I${newlib-install}/aarch64-elf/include --sysroot=${newlib-install}/aarch64-elf/ -Xlinker --defsym=__stack=0x05D00000 --specs=rdimon.specs -o aarch64-test-rdimon sample_demo.c

Start openOCD connected to Hikey Board via BusBlaster v2 debug adapter:

...

./src/openocd -s tcl/ -f interface/ftdi/dp_busblaster.cfg -f board/lemaker_hikey.cfg

Run demo using GDB:

  • Start AArch64-elf-gdb with Hikey board semihosting bare-metal demo

    Code Block
    languagebash
    aarch64-elf-gdb aarch64-test-rdimon


  • Connect to OpenOCD GDB stub while OpenOCD is connected to Hikey via BusBlaster v2 debug adapter

    Code Block
    languagebash
    target extended-remote :3333


  • Send command to OpenOCD to enable arm semihosting via gdb monitor command

    Code Block
    languagebash
    monitor arm semihosting enable


  • Load executable to the tagert

    Code Block
    languagebash
    load


  • Run demo and you will see semihosting printf output on OpenOCD console

    Code Block
    languagebash

...

  • run


  • Enable OpenOCD semihosting_filio to view printf output on gdb console

    Code Block
    languagebash
    monitor arm semihosting_fileio enable


Note

Note: You might have to connect/disconnect GDB with target a couple of times to ensure target is in stable connected state with openOCD.