I am trying to send a short message via UDP as a broadcast message. However my call to netconn_new returns a null. I traced it through and it fails in Chibios sys_arch.c line 189 which is the check to see if the mbox is valid.
Code: Select all
int sys_mbox_valid(sys_mbox_t *mbox) {
return *mbox != SYS_MBOX_NULL;
}
and the *mbox comes from the address of a static variable mbox tcpip.c which is in the lwip code.
Code: Select all
if (sys_mbox_valid(&mbox)) {
msg.type = TCPIP_MSG_API;
msg.msg.apimsg = apimsg;
sys_mbox_post(&mbox, &msg);
sys_arch_sem_wait(&apimsg->msg.conn->op_completed, 0);
return apimsg->msg.err;
}
So it checks to see if mbox is a valid memory location. As far as I can see mbox is declared in tcpip.c as:
Code: Select all
static sys_mbox_t mbox;
Since mbox is static, should that not automatically make it valid? Eclipse shows mbox as this:
mbox 0x2000702c
*mbox 0x00000000
mb_buffer 0x20000400
mb_top 0x080001b1
mb_wrptr 0x080002e1
I am on an OLIMEX STM32F4-E407.
Any ideas what my error might be?
Warmest regards, Mike.
Code: Select all
/*
*
*
*/
#include "ch.h"
#include "hal.h"
#include "chprintf.h"
#include <chstreams.h>
#include <string.h>
#include <lwip/ip_addr.h>
#include <lwip/api.h>
#include <lwip/udp.h>
//#include <lwip/memp.h>
//#include <lwip/arch.h>
//#include <lwip/opt.h>
//#include <lwip/def.h>
//#include <lwip/debug.h>
//#include <lwip/mem.h>
#include <lwip/init.h>
#include "lwipopts.h"
#include "lwipthread.h"
static SerialConfig sc;
#define WOOFIE_UDP_PORT 50000
int main(void)
{
halInit();
chSysInit();
lwip_init();
sc.speed = 38400;
sc.cr1 = 0;
sc.cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN;
sc.cr3 = 0;
sdStart(&SD6, &sc);
chprintf((BaseSequentialStream*)&SD6, "Hello World!\n\r");
//memp_init();
struct netconn *conn = netconn_new(NETCONN_UDP);
if(conn == NULL)
{
chprintf((BaseSequentialStream*)&SD6, "Connection failed\n\r");
}
/*
netconn_bind(conn, IP_ADDR_ANY, WOOFIE_UDP_PORT);
struct netbuf *buf = netbuf_new();
char *msg = "This is the UDP message\n";
char *data = netbuf_alloc(buf, sizeof(msg));
MEMCPY(data, msg, sizeof(msg));
netconn_send(conn, buf);
netbuf_delete(buf);*/
while(TRUE)
{
int i;
for(i = 100; i < 1000; i += 100)
{
palTogglePad(GPIOC, GPIOC_LED);
chThdSleepMilliseconds(i);
}
}
return 0;
}