Skip to content

This repository has all the materials used to create the X-CUBE pack to use DA16K PMOD with various ST hardware.

License

Notifications You must be signed in to change notification settings

avnet-iotconnect/X-CUBE-IoTC-DA16k-PMOD

Repository files navigation

DA16k PMOD Firmware

To ensure compatability with this X-CUBE pack, matching DA16k-PMOD firmware has been included within it.

The image files can be found in the Repository e.g.

https://github.com/avnet-iotconnect/iotc-dialog-da16k-sdk/tree/main/images

Follow the instructions in the QuickStart Guide to flash the DA16k PMOD.

Supported Boards

The following boards are supported by this repository:

Note

Use the FW bundled with the X-CUBE .pack file in /pack_project_dir/Files instead of what is on Github.

For STM32N6570-DK board, please follow the instructions in the /doc folder.

Usage

  1. Download the Avnet-IOTCONNECT.X-CUBE-IoTC-DA16k-PMOD.1.0.0.pack
  2. Download and Launch STM32CubeIDE
  3. Create a CubeMX project
    • Select New project by MCU
    • Select the MCU part number from the drop-down list
    • Click Create Project at the top corner
  4. Click "Software Packs" in the "Pinout & Configuration" view and click “Manage Software Packs”
  5. Click on "From Local ..."
  6. Navigate to and select the .pack file
  7. Accept the license
  8. Close the window
  9. Now go to "Select Components"
  10. Check the box beside "Extension Board/iotc_da16k_pmod / subgroup"
  11. Select “single_thread” from the "Device Application" pull-down menu.
  12. Click "OK".
  13. Click "Connectivity" and select "USART3" (This is the Arduino connector)
  • Parameter Settings:
    • Mode: Asynchronous
    • Baud: 115200
    • Word Length: 8 bits (including Parity)
    • Parity: None
    • Stop Bits: 1
  • NVIC Settings:
    • Global Interrupt enabled
  • Optional DMA Settings:
    1. Click "Add".
    2. Select the "*TX" option from the "DMA Request" column.
  • GPIO Settings
    • Make sure the GPIO settings are correct for your board (TX and RX pins)
  1. In the "Pinout & Configutation" tab of the CubeMX view, select "I-CUBE-IoTC-DA16k-PMOD" from "Middlewares & Software Packs" on the left hand side.
  2. Check both the "Extension Board iotc da16k pmod" & "Device Application" boxes. This will make the "Platform Settings" tab available below.
  3. CubeMX will query the current setup and find the suitable serial ports that can be used with the pack. In "IPs or Components" select the type of serial port configured previously.
  4. Select the serial port previously configured from the "Found Solutions" pull-down menu.
  5. Enter the device and wifi credentials in the "Parameter Settings" tab.
  6. At the top of the CubeMX window click on the "Project Manager" tab.
  7. On the left hand side, click on the "Advanced Settings"
  8. On the right hand side, within the "Register Callback" pane, find the UART/USART/LPUART section to use and set the register callbacks to "ENABLE".
  9. Click "Project Manager" and Find the Drop-down next to "Toolchain / IDE" ensure it matches your IDE (e.g. Change this to "STM32CubeIDE" for STM boards)
  10. Save the setting ("Ctrl + s") and generate the code.
  11. Close the CubeMX

Open The Project from the CubeIDE 4. If you intend to send telemetry open up the project properties:

  • Navigate to C/C++ Build -> Settings
  • Set the "Runtime Library" to "Standard C"
  1. Upload the device certificate and key using the console port on the da16k:
    • Enter net into the terminal to switch to the network commands context.
    • Enter cert write cert1.
    • Paste the certificate into the terminal.
    • As instructed on the terminal enter CTRL+C to complete the process.
    • Enter cert write key1.
    • Paste the key into the terminal.
    • As instructed on the terminal enter CTRL+C to complete the process.

Next Steps

Once the code has been generated the next steps are:

Setup the debug console/uart for the host

Here are code snippets that may be present in a future version of the pack as an example. These will help setup a debug serial port. You can use the /* USER CODE BEGIN ... */ comments as locations to insert these snippets.

In main.c:

/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <stdbool.h>
/* USER CODE END Includes */

and

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
#define DEBUG_LINE_SIZE (256)
#define DEBUG_UART_P (&huart2)

typedef struct HEAD_TO_TAIL_BUF {
	volatile char buf[DEBUG_LINE_SIZE];
	int head, tail;
}headToTailBuf_t;

static struct HEAD_TO_TAIL_BUF rx_buf = {{0},0,0};

int head_to_tail_buf_write (struct HEAD_TO_TAIL_BUF * b, char data) {
	b->buf[b->head] = data;
		if(++b->head >= DEBUG_LINE_SIZE)
			b->head = 0;
	return 0;
}

int head_to_tail_buf_read (struct HEAD_TO_TAIL_BUF * b, char * data) {

	if(b->tail != b->head) {
		*data = (int)b->buf[b->tail];
		if(++b->tail >= DEBUG_LINE_SIZE)
			b->tail = 0;
		return 0;
	}
	else {
		return -1;
	}
}

static char rx_byte;

/*
 * Callback that occurs at the end of a transmission. Clears the txDmaInUse flag to allow subsequent transmissions.
 */
void HAL_DEBUG_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
	;
}

/*
 * Callback that happens when characters are received via interrupt one at a time. The function places each byte in a
 * buffer to be processed when the system can.
 */
void HAL_DEBUG_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
	if(huart == DEBUG_UART_P) {
		HAL_UART_Receive_IT(DEBUG_UART_P, (uint8_t *) &rx_byte, 1);
		head_to_tail_buf_write(&rx_buf, rx_byte);
	}
}

int __io_putchar(int ch) {
	int err=0;
	HAL_StatusTypeDef s;
	do
		s = HAL_UART_Transmit_IT(DEBUG_UART_P, (uint8_t *)&ch, 1);
	while(s != HAL_OK);

	return err;
}

int __io_getchar(void) {
	char c;

	while(0 != head_to_tail_buf_read(&rx_buf, &c));

	return (int)c;
}
/* USER CODE END 0 */

Within the code generated by CubeMX for your debug serial port, also in main.c:

  /* USER CODE BEGIN USART2_Init 2 */
#if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
    if(HAL_OK != HAL_UART_RegisterCallback(DEBUG_UART_P, HAL_UART_TX_COMPLETE_CB_ID,
        &HAL_DEBUG_UART_TxCpltCallback) ) {
        return false;
    }

    if(HAL_OK != HAL_UART_RegisterCallback(DEBUG_UART_P, HAL_UART_RX_COMPLETE_CB_ID,
        &HAL_DEBUG_UART_RxCpltCallback) ) {
        return false;
    }
#endif
    printf("\f\n\rPMOD Host Demo Start...\n\r");
  /* USER CODE END USART2_Init 2 */

Send Telemetry.

The user should be able to send telemetry by following the usual process of calling da16_create/send_msg*.

React to C2D commands

By default the code will output received commands to a debug output. This can be redirected by provided a "strong" version of the void da16k_cmd_handler(da16k_cmd_t * cmd) function.

About

This repository has all the materials used to create the X-CUBE pack to use DA16K PMOD with various ST hardware.

Resources

License

Stars

Watchers

Forks

Packages

No packages published