Dev academy BLE fundamentals lesson 4_exer3 not building

Good morning

Doing the BLE fundamentals course and cant seem to build lesson 4 ex 3.  Have picked up this thread BLE Fundamentals lesson 4 exercise 3 failure to build - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)  with no solution.

using the latest tool chain, nrf52840DK  2.02.

The errors in the function below im receiving are 

C:/ncs/v2.6.0/zephyr/include/zephyr/toolchain/gcc.h:87:36: error: static assertion failed: "pointer type mismatch in CONTAINER_OF"
87 | #define BUILD_ASSERT(EXPR, MSG...) _Static_assert(EXPR, "" MSG)

in this line 

  buf = CONTAINER_OF(aborted_buf, struct uart_data_t, data);

static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	ARG_UNUSED(dev);

	static size_t aborted_len;
	struct uart_data_t *buf;
	static uint8_t *aborted_buf;
	static bool disable_req;

	switch (evt->type) {
	case UART_TX_DONE:
		LOG_DBG("UART_TX_DONE");
		if ((evt->data.tx.len == 0) || (!evt->data.tx.buf)) {
			return;
		}

		if (aborted_buf) {
			buf = CONTAINER_OF(aborted_buf, struct uart_data_t, data);
			aborted_buf = NULL;
			aborted_len = 0;
		} else {
			buf = CONTAINER_OF(evt->data.tx.buf, struct uart_data_t, data);
		}

		k_free(buf);

		buf = k_fifo_get(&fifo_uart_tx_data, K_NO_WAIT);
		if (!buf) {
			return;
		}

		if (uart_tx(uart, buf->data, buf->len, SYS_FOREVER_MS)) {
			LOG_WRN("Failed to send data over UART");
		}

		break;

	case UART_RX_RDY:
		LOG_DBG("UART_RX_RDY");
		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
		buf->len += evt->data.rx.len;

		if (disable_req) {
			return;
		}

		if ((evt->data.rx.buf[buf->len - 1] == '\n') ||
		    (evt->data.rx.buf[buf->len - 1] == '\r')) {
			disable_req = true;
			uart_rx_disable(uart);
		}

		break;

	case UART_RX_DISABLED:
		LOG_DBG("UART_RX_DISABLED");
		disable_req = false;

		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf->len = 0;
		} else {
			LOG_WRN("Not able to allocate UART receive buffer");
			k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
			return;
		}

		uart_rx_enable(uart, buf->data, sizeof(buf->data), UART_WAIT_FOR_RX);

		break;

	case UART_RX_BUF_REQUEST:
		LOG_DBG("UART_RX_BUF_REQUEST");
		buf = k_malloc(sizeof(*buf));
		if (buf) {
			buf->len = 0;
			uart_rx_buf_rsp(uart, buf->data, sizeof(buf->data));
		} else {
			LOG_WRN("Not able to allocate UART receive buffer");
		}

		break;

	case UART_RX_BUF_RELEASED:
		LOG_DBG("UART_RX_BUF_RELEASED");
		buf = CONTAINER_OF(evt->data.rx_buf.buf, struct uart_data_t, data);

		if (buf->len > 0) {
			/* STEP 9.1 -  Push the data received from the UART peripheral into the fifo_uart_rx_data FIFO */
			k_fifo_put(&fifo_uart_rx_data, buf);
		} else {
			k_free(buf);
		}

		break;

	case UART_TX_ABORTED:
		LOG_DBG("UART_TX_ABORTED");
		if (!aborted_buf) {
			aborted_buf = (uint8_t *)evt->data.tx.buf;
		}

		aborted_len += evt->data.tx.len;
		buf = CONTAINER_OF(aborted_buf, struct uart_data_t, data);

		uart_tx(uart, &buf->data[aborted_len], buf->len - aborted_len, SYS_FOREVER_MS);

		break;

	default:
		break;
	}
}

I have tried to build the solution as well with the same outcome

Thanks in advance for any assistance.

Parents
  • Hello,

    Sorry for the late reply. I started looking into this last week, but I was out of office on Friday. 

    This task is mostly from the peripheral_uart sample found in NCS\nrf\samples\bluetooth\peripheral_uart. 

    It seems like there has been a change in Zephyr that has not yet reached the BLE fundamentals course. 

    Wherever you see the CONTAINER_OF() macro, make sure that you point to the first element of the buffer, instead of the buffer (like it is done in the peripheral_uart sample). 

    Here you can see the commit that changed the peripheral_uart sample:

    https://github.com/nrfconnect/sdk-nrf/commit/315bdb9d226fdbc983b23087a59704d1e7394e89

    So if you add a "[0]" after "data" in all the CONTAINER_OF lines, it should build.

    Thank you for reporting. I have forwarded this information to the DevAcademy group, so it will be patched soon.

    Best regards,

    Edvin

Reply
  • Hello,

    Sorry for the late reply. I started looking into this last week, but I was out of office on Friday. 

    This task is mostly from the peripheral_uart sample found in NCS\nrf\samples\bluetooth\peripheral_uart. 

    It seems like there has been a change in Zephyr that has not yet reached the BLE fundamentals course. 

    Wherever you see the CONTAINER_OF() macro, make sure that you point to the first element of the buffer, instead of the buffer (like it is done in the peripheral_uart sample). 

    Here you can see the commit that changed the peripheral_uart sample:

    https://github.com/nrfconnect/sdk-nrf/commit/315bdb9d226fdbc983b23087a59704d1e7394e89

    So if you add a "[0]" after "data" in all the CONTAINER_OF lines, it should build.

    Thank you for reporting. I have forwarded this information to the DevAcademy group, so it will be patched soon.

    Best regards,

    Edvin

Children
Related