2020-05-21 11:29 AM
Hello,
I have a problem. My program doesn't send value in UDP packet and program crash. I try everything, But I didn't find anything.
Some variables and constants
typedef struct UDPsender {
struct netconn *udp_sender_server;
struct netbuf *udp_send_buf;
} UDPsender;
QueueHandle_t udp_sender_queue = NULL;
ip4_addr_t global_udp_ip_address;
int32_t global_udp_port;
volatile UDPsender *local_udp_ctx = NULL;
void udp_poll(TickType_t timeout);
Init UDP and task for FreeRTOS
int32_t udp_sender_init(UDPsender *udp_ctx, const char *udp_sender_ip_address, const uint16_t udp_sender_port) {
memset(udp_ctx, 0, sizeof(*udp_ctx));
udp_ctx->udp_send_buf = netbuf_new();
local_udp_ctx = udp_ctx;
udp_sender_queue = xQueueCreate(1, sizeof(uint16_t));
inet_pton(AF_INET, udp_sender_ip_address, &global_udp_ip_address);
global_udp_port = udp_sender_port;
xTaskCreate(udp_sender_task, "UDP_Sender", 500, NULL, 3, NULL);
return 0;
}
Task
void udp_sender_task(void *pvParameters) {
for (;;) {
udp_poll(10);
}
}
Receive integer value from queue
void udp_poll(TickType_t timeout) {
static uint16_t value = 0;
if (xQueuePeek(udp_sender_queue, &value, 0) == pdTRUE) {
while (xQueueReceive(udp_sender_queue, &value, timeout) == pdTRUE) {
udp_data_send(&value);
}
}
vTaskDelay(5);
}
And function for sending value.
int32_t udp_data_send(const uint16_t *azimuth) {
local_udp_ctx->udp_sender_server = netconn_new(NETCONN_UDP);
if (FALSE == IsPtrValid((void*) local_udp_ctx->udp_sender_server)) {
return (-1);
}
if (ERR_OK != netbuf_ref(local_udp_ctx->udp_send_buf, azimuth, sizeof(uint16_t))) {
netconn_close(local_udp_ctx->udp_sender_server);
netconn_delete(local_udp_ctx->udp_sender_server);
return (-1);
}
if (netconn_sendto(local_udp_ctx->udp_sender_server, local_udp_ctx->udp_send_buf, &global_udp_ip_address, global_udp_port) != ERR_OK) {
netconn_close(local_udp_ctx->udp_sender_server);
netconn_delete(local_udp_ctx->udp_sender_server);
return (-1);
}
netconn_delete(local_udp_ctx->udp_sender_server);
return 0;
}
And function for queue (for sending value)
void Send_uint16_to_udp(uint16_t value) {
xQueueSend(udp_sender_queue, &value, 0);
}
2020-05-30 03:51 AM
> I try everything
No, you haven't - you are not learning from the past and are still using ST's non-working bloatware, which on H7 is incomparably more broken than on any of the older series.
https://community.st.com/s/question/0D50X0000C6eNNSSQ2/bug-fixes-stm32h7-ethernet
In other words it does not work and will not work in a foreseeable future, because the intellectual capability of HAL/Cube developers is too low to even understand these problems.
Compiling from your older topics...
> Can anyone generate a bin file, with some test program? For example: Ping, some web page,......
> I have STM32F767 - Nucleo kit.
Well, take that Nucleo and check out my demo: