Recording procedure using nrf52832 development kit with another module using MCU NRf52832.

good afternoon people.
I am developing a module, based on the electrical schematic of the development kit nRF52832(PCA10040).
The idea is just to use the electrical schematic of the BLE to communicate via UART with other products.

The module looks like this.

Como dize anteriormene apenas irei precisar o módulo BLE.
Coloquei também uma sáida para comunicação UART e para Gravação do código do módulo.

My question is as follows. I need to record the source code in the developed module and for that I am using the nRF52832 development kit, as shown in the image below.

one of the supports suggested me to use the following link to use the kit as a recorder

The source code I'm using is this one.

// Projeto Modulo BLE

//Libarys

#include <stdbool.h>
#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <random/rand32.h>
#include <sys/printk.h>
#include <sys/byteorder.h>

#include <zephyr.h>
#include <device.h>
#include <devicetree.h>

// Libary GPIO
#include <drivers/gpio.h>

// UART
#include <drivers/uart.h>

// Bluetooth
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/conn.h>
#include <bluetooth/uuid.h>
#include <bluetooth/gatt.h>
//#include <bluetooth/services/bas.h>


// Defines 

/* Defines Treadmill Measument Flags */

#define TD_MORE_DATA BIT(0)                               // resolution 0.01 km/h
#define TD_AVERAGE_SPEED_PRESENT BIT(1)                   // resolution 0.01 km/h
#define TD_TOTAL_DISTANCE_PRESENT BIT(2)                  // resolution 1 meter
#define TD_INCLINATION_RAMP_ANGLE_SETTING_PRESENT BIT(3)  // resolution 0.1 %
#define TD_ELEVATION_GAIN_PRESENT BIT(4)                  // resolution 0.1 m
#define TD_INSTANTANEOUS_PACE_PRESENT BIT(5)              // resolution 0.1 km/m
#define TD_AVERAGE_PACE_PRESENT BIT(6)                    // resolution 0.1 km/m
#define TD_EXPENDED_ENERGY_PRESENT BIT(7)                 // resolution 1 kcal
#define TD_HEART_RATE_PRESENT BIT(8)                      // resolution 1 bpm
#define TD_METABOLIC_EQUIVALENT_PRESENT BIT(9)            // resolution 0.1 mer
#define TD_ELAPSED_TIME_PRESENT BIT(10)                   // resolution of 1 sec
#define TD_REMAINING_TIME_PRESENT BIT(11)                 // resolution of 1 sec
#define TD_FORCE_ON_BELT_AND_POWER_OUTPUT_PRESENT BIT(12) // resolution of 1


//Defines LEDs
/* 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. */
#1 "Unsupported board: led0 devicetree alias is not defined"
#define LED0	""
#define PIN	0
#define FLAGS	0
#endif

//  Global Variables

//static uint16_t ble_speed = 0;
//tatic uint16_t ble_distance = 0;
//static uint16_t ble_inclination = 0;
//static uint16_t ble_cal = 0;
//static uint16_t ble_pulso = 0;
//static uint16_t ble_time = 0;



bool led1_is_on = false;

// Uart variables

static uint16_t uart_speed = 0;
static uint16_t uart_heart_rate = 0;

// Defines Times

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   1000

// Define UART

//Define the size of the receive buffer 
#define RECEIVE_BUFF_SIZE 20  //10

//Define the receiving timeout period 
#define RECEIVE_TIMEOUT 200

//Get the device pointers of the LEDs through gpio_dt_spec


//Get the device pointer of the UART hardware 
const struct device *uart= DEVICE_DT_GET(DT_NODELABEL(uart0));

//Define the transmission buffer, which is a buffer to hold the data to be sent over UART
static uint8_t tx_buf[] =   {"nRF Connect SDK Fundamentals Course\n\r"
                             "Press 1-3 on your keyboard to toggle LEDS 1-3 on your development kit\n\r"};


//Define the receive buffer
static uint8_t rx_buf[RECEIVE_BUFF_SIZE] = {0};

//static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
//static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(DT_ALIAS(led1), gpios);
//static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios);

/* Fitness Machine Service declaration */

static uint16_t speed; /* Speed */ 
static uint8_t heart_rate; /* Speed */ 

static bool tread_simulation;


//Define the callback function for UART
static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
	switch (evt->type) {

	case UART_RX_RDY:

		uart_speed = (evt->data.rx.buf[(evt->data.rx.offset)+1])*10;

	   	printk("UART_RX speed = %d\r\n ", uart_speed);


	break;
	case UART_RX_DISABLED:
		//printk("DiSABLED\r\n");
		uart_rx_enable(dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
		break;
		
	default:
		break;
	}
}


//  Attribute GATT 
static void treadmill_meas_ccc_cfg_changed(const struct bt_gatt_attr *attr,
				     uint16_t value)
{
	tread_simulation = value == BT_GATT_CCC_NOTIFY;
}


// Service GATT
BT_GATT_SERVICE_DEFINE(ftms_svc,
				BT_GATT_PRIMARY_SERVICE(BT_UUID_FTMS), // Service Fitness 
				BT_GATT_CHARACTERISTIC(BT_UUID_TREADMILL_MEASUREMENT, BT_GATT_CHRC_NOTIFY,  // Characteristic Treadmill
			       0x00, NULL, NULL, NULL),	
				BT_GATT_CCC(treadmill_meas_ccc_cfg_changed, // CCC Client Characteristic Configuration , Configuration changed callback
		    BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
				
);


// FTMS measurement
struct ftms_measurement{
	uint16_t flags;
	uint8_t data[];
};

struct treadmill_measurement{
	uint16_t speed;
	uint8_t heart_rate;
};

/// @brief  Measurement variables
/// @param conn 
/// @param speed 
/// @param heart_rate 

 
static void measurement_ftms (struct bt_conn *conn, uint16_t speed, uint8_t heart_rate){
	
	struct ftms_measurement *ftms;

	uint8_t buf[sizeof(*ftms) +
		    (speed ? sizeof(struct treadmill_measurement) : 0)+
			(heart_rate ? sizeof(struct treadmill_measurement) : 0)];

	uint16_t len = 0U; // 0 = The number 0 e U = unsigned constant

	ftms = (void *) buf;   // receive the lenght buffer
	ftms->flags = 0U;		// Point acess a variable flag
	
	if(speed){
		struct treadmill_measurement data;
		ftms -> flags |=0b00000000;
		data.speed = sys_cpu_to_le16(speed);
		

		memcpy(ftms->data, &data, sizeof(data));
		len +=sizeof(data);
	}

	bt_gatt_notify(NULL, &ftms_svc.attrs[1], buf, sizeof(buf));

};

// Reveive the values from uart

static void treadmill_simulation(void){

	bool ftms_speed = false;
	bool ftms_heart_rate = false;
	speed  = uart_speed;
	ftms_speed = true;

	heart_rate = uart_heart_rate;
	ftms_heart_rate = true;

	measurement_ftms (NULL, ftms_speed? speed : 0,ftms_heart_rate? heart_rate : 0);
}


// Connected BLE
static void connected(struct bt_conn *conn, uint8_t err)
{
	if (err) { 
		printk("Connection failed (err 0x%02x)\n", err);
	} else {
		printk("Connected\n");
		led1_is_on = 1; 
	}
}

// Desconnected
static void disconnected(struct bt_conn *conn, uint8_t reason)
{
	printk("Disconnected (reason 0x%02x)\n", reason);
	led1_is_on = 0; 
	
}

// Function Call
BT_CONN_CB_DEFINE(conn_callbacks) = {
	.connected = connected,
	.disconnected = disconnected,
};

// Bluetooth
static const struct bt_data ad[] = {
	BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR))
};


// check if had commnunication by bluetooth
static void bt_ready(void)
{
	int err;

	printk("Bluetooth initialized\n");

	err = bt_le_adv_start(BT_LE_ADV_CONN_NAME, ad, ARRAY_SIZE(ad), NULL, 0);
	if (err) {
		printk("Advertising failed to start (err %d)\n", err);
		return;
	}

	printk("Advertising successfully started\n");
}


// Main 
void main(void)
{
	int err;  // Vaiables debuger

	const struct device *dev;
	
	int ret;

	dev = device_get_binding(LED0);
	if (dev == NULL) {
		return;
	}

	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
	if (ret < 0) {
		return;
	}

	err = bt_enable(NULL);

	if (err) {
		printk("Bluetooth init failed (err %d)\n", err);
		return;
	}
    
	bt_ready();

/* STEP 4.2 - Verify that the UART device is ready */ 
	if (!device_is_ready(uart)){
		printk("UART device not ready\r\n");
		//return 1 ;
	}
/* STEP 8 - Register the UART callback function */
	ret = uart_callback_set(uart, uart_cb, NULL);
		if (ret) {   
			printk("Cannot Initialize UART Callback\r\n");
			//return 1; 
		}

/* STEP 9.2 - Send the data over UART by calling uart_tx() */
	ret = uart_tx(uart, tx_buf, sizeof(tx_buf), SYS_FOREVER_MS);
	
	if (ret) {
		printk("Cannot display welcome message (ret:%d)", ret);
		//return 1;
	}

/* STEP 10.3  - Start receiving by calling uart_rx_enable() and pass it the address of the receive  buffer */
	ret = uart_rx_enable(uart ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
	if (ret) {
		//return 1;
	}

	while (1) {

		gpio_pin_set(dev, PIN, (int)led1_is_on);

		if (tread_simulation) {
			treadmill_simulation();
		}	

	}
}
at the moment I just want to write the source code in the developed module. but when i try to do that only the development kit module is written and using the nrf Connect application it is only possible to find a ble module. The other one that was developed didn't look like it.
Related