Odd behaviour with Zephyr and CONFIG_ASSERT

Hi,

I bought a HiFive 1 Rev B about a month ago, and I’ve been learning to use it.

I’m using Platform IO (under VSCode), and created a project using the templates, choosing Zephyr as the ‘framework’ (i.e. OS).

I’ve run a few of the Zephyr examples from here:

but found that I had to make a few changes, to include paths, defines for accessing GPIO etc., so it seems as though the version of zephyr at the link above is out of step with the version that Platform IO installed (I believe that’s 2.2.0)

The curious behaviour, however, come with this example (basic threads):

It builds and runs OK (with the usual couple of tweaks, as above) but if I set CONFIG_ASSERT=n in prj.conf, then attempt to build and debug, it gets ‘lost’ somewhere between SECTION_FUNC(vectors, __start) (I assume that’s where the bootloader vectors to) and main(), so presumably somewhere in the C startup code.

Does anyone have any idea why that might be?

To further confuse me, if I comment out the line:
k_fifo_put(&printk_fifo, mem_ptr);
then it builds and runs successfully, regardless of the state of CONFIG_ASSERT (to clarify, obviously no data is put into the FIFO in this case, but everything else works as expected)

Can anyone help me to understand what’s going on?

Regards,

Ian Lewis.

-------Code-----------------------

#include <zephyr.h>
#include <device.h>
#include <kernel.h>
#include <drivers/gpio.h>
//#include <misc/printk.h>
#include <sys/__assert.h>
#include <string.h>

/* size of stack area used by each thread */
#define STACKSIZE 1024

/* scheduling priority used by each thread */
#define PRIORITY 7

/* Change this if you have an LED connected to a custom port */
#ifndef LED0_GPIO_CONTROLLER
#define LED0_GPIO_CONTROLLER 	DT_ALIAS_LED0_GPIOS_CONTROLLER
#endif
#ifndef LED1_GPIO_CONTROLLER
#define LED1_GPIO_CONTROLLER 	DT_ALIAS_LED1_GPIOS_CONTROLLER
#endif

#define PORT0	 LED0_GPIO_CONTROLLER
#define PORT1	 LED1_GPIO_CONTROLLER


/* Change this if you have an LED connected to a custom pin */
#define LED0    DT_GPIO_LEDS_LED_0_GPIOS_PIN
#define LED1    DT_GPIO_LEDS_LED_1_GPIOS_PIN

struct printk_data_t {
	void *fifo_reserved; /* 1st word reserved for use by fifo */
	u32_t led;
	u32_t cnt;
};

K_FIFO_DEFINE(printk_fifo);

void blink(const char *port, u32_t sleep_ms, u32_t led, u32_t id)
{
	int cnt = 0;
	struct device *gpio_dev;

	gpio_dev = device_get_binding(port);
	__ASSERT_NO_MSG(gpio_dev != NULL);

	gpio_pin_configure(gpio_dev, led, GPIO_OUTPUT);

	while (1) {
		gpio_pin_set(gpio_dev, led, cnt % 2);
		
		struct printk_data_t tx_data = { .led = id, .cnt = cnt };

		size_t size = sizeof(struct printk_data_t);
		char *mem_ptr = k_malloc(size);
		__ASSERT_NO_MSG(mem_ptr != 0);

		memcpy(mem_ptr, &tx_data, size);

		k_fifo_put(&printk_fifo, mem_ptr);

		k_sleep(sleep_ms);
		cnt++;
	}
}

void blink1(void)
{
	blink(PORT0, 200, LED0, 0);
}

void blink2(void)
{
	blink(PORT1, 1000, LED1, 1);
}

void uart_out(void)
{
	while (1) {
		struct printk_data_t *rx_data = k_fifo_get(&printk_fifo, K_FOREVER);
		printk("Toggle USR%d LED: Counter = %d\n", rx_data->led, rx_data->cnt);
		k_free(rx_data);
	}
}

K_THREAD_DEFINE(blink1_id, STACKSIZE, blink1, NULL, NULL, NULL,
		PRIORITY, 0, K_NO_WAIT);
K_THREAD_DEFINE(blink2_id, STACKSIZE, blink2, NULL, NULL, NULL,
		PRIORITY, 0, K_NO_WAIT);
K_THREAD_DEFINE(uart_out_id, STACKSIZE, uart_out, NULL, NULL, NULL,
		PRIORITY, 0, K_NO_WAIT);