Hi,
When using a program compiled and installed with zephyr everything works fine.
I want to use zephyr under PlatformIO.
The same program (blinky) works fine for the LED. But printk and printf do nothing.
I have tried with and without USB-CDC, it’s the same.
I get no error. Neither at compile time, nor at execution. But no output.
Where does it go?
What to do to have it on my MAC?
In fact, no device is created in /dev when I plug the device.
As soon as I compile under zephyr env, the device appears in /dev.
So I doesn’t seem to be a zephyr issue.
The device is a nRF52840 dongle from Nordic semiconductor.
For uploading I use the USB connector.
Here’s my platformio.ini:
[env]
platform = nordicnrf52
board = nrf52840_dk
framework = zephyr
board_build.zephyr.variant = nrf52840dongle_nrf52840
extra_scripts = dfu_upload.py
upload_protocol = custom
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
Here’s the zephyr/prj.conf
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
Here’s the dfu_upload.py
from os.path import basename
Import("env")
import os
platform = env.PioPlatform()
def dfu_upload(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
print("Upload to nrf52840 dongle.")
print("firmware_path = ",firmware_path)
print("firmware_name = ",firmware_name)
genpkg = "".join(["nrfutil-mac pkg generate --hw-version 52 --sd-req=0x00 --application ", firmware_path, " --application-version 1 firmware.zip"])
dfupkg = "nrfutil-mac dfu serial -pkg firmware.zip -p /dev/cu.usbmodemFA92DCD2F3641 -b 115200"
print( genpkg )
os.system( genpkg )
os.system( dfupkg )
print("Uploading done.")
# Custom upload command and program name
env.Replace(PROGNAME="firmware", UPLOADCMD=dfu_upload)
And finally here’s the src/main.c
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <stdio.h>
#include <device.h>
#include <devicetree.h>
#include <kernel.h>
#include <drivers/gpio.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 100
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0 ""
#define PIN 0
#define FLAGS 0
#endif
void main(void)
{
const struct device *dev;
bool led_is_on = true;
int ret;
printf("DEBUT\n");
dev = device_get_binding(LED0);
if (dev == NULL) {
return;
}
ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
if (ret < 0) {
return;
}
while (1) {
gpio_pin_set(dev, PIN, (int)led_is_on);
led_is_on = !led_is_on;
printk("LED state k: %s\n", led_is_on ? "ON" : "OFF");
printf("LED state f: %s\n", led_is_on ? "ON" : "OFF");
k_msleep(SLEEP_TIME_MS);
}
}
The led blinks well. If I change the sleep_time it changes on the board.
My problem is only with the printf and printk.
Can someone help me?
Thanks