OpenUart Write causes reset


#1

Hi people, i’m doing a small app on FXT, the goal is to open UART1 to communicate with an external device. I’ve done this successfully using FCM but i need to re-implement it using OpenUart APIs, because my final goal is to drive a microSD RS232 FAT16 drive interface, and i need to do this (in pseudo-code):

Open uartX;
Write command to uartX;
Disable watchdog;
for(i=0;i<512;i++)
{
  Read buffer from FAT16 drive;
}
Write command to uartX;
for(i=0;i<512;i++)
{
  Read buffer from FAT16 drive;
}
Enable watchdog;
... 
etc...

Driving the microSD using FCM become a little bit hard to handle in my pre-existent code.

So, i have the following code:

#include "adl_global.h"
#include "adl_OpenDevice.h"
#include "wm_uart.h"
#include "adl_wd.h"

static const sGCbDesc_t uart1CbTab[] =
{
/* user data */ /* callbacks */
{ (void*)-1L, NULL },
{ (void*)-1L, NULL },
{ (void*)-1L, NULL },
{ (void*)-1L, NULL },
{ (void*)-1L, NULL },
{ (void*)-1L, NULL }
};

const u16 wm_apmCustomStackSize = 1024*3;
static psGItfCont_t uart_if;
static sGItfCont_t uart_itf;
static s32 uart1_hdl;
//-------------------------------------------------------------------------------
void Init_uDrive_uSD_G1()
{
	adl_atCmdCreate("at+wmfm=0,1,1", FALSE, NULL, NULL);
	adl_atCmdCreate("at+ifc=0,0", ADL_AT_PORT_TYPE(ADL_PORT_UART1, FALSE), NULL, NULL);
	adl_atCmdCreate("at+ipr=9600", ADL_AT_PORT_TYPE(ADL_PORT_UART1, FALSE), NULL, NULL);
}
//-------------------------------------------------------------------------------
s32 uart1_open( eUartRate_t speed )
{
	s32 handle;
	sUartSettings_t Settings;
	psGItfCont_t pinterface;
	sUartEvent_t events;
	sUartLc_t lc;
	sUartFlowCtrl_t Fc;

	/* Device */
	Settings.identity = "UART1";
	Settings.role = UART_ROLE_NM;

	/* Events */
	events.user_data = (void*)0;
	events.valid_cb = UART_CB_ON_TX_COMPLETE|UART_CB_ON_ERROR|UART_CB_ON_SIG_STATE_CHANGE|UART_CB_ON_RX_COMPLETE;//UART_CB_ON_ALL;
	memcpy((u8*)events.cb_list, (u8*)uart1CbTab, 6*sizeof(sGCbDesc_t));
	Settings.event_handlers = &events;
	Settings.capabilities = NULL;

	/* To retrieve the UART SP Interface */
	Settings.interface = &pinterface;

	/* Line Coding */
	lc.op = G_IOC_OP_SET;
	lc.valid_fields = UART_LC_ALL;
	lc.rate = speed;
	lc.stop = UART_STOP_BIT_1;
	lc.parity = UART_PARITY_NONE;
	lc.data = UART_DATALENGTH_8;

	Settings.line_coding = &lc;

	/*------------------*/
	/* open UART device */
	/*------------------*/
	handle = adl_OpenDevice( DF_UART_CLID, &Settings);
	if( handle > 0 )
	{

	/* Locally store the uart1 interface */
	uart_itf = *pinterface;
	uart_if = pinterface;

	/* Flow control IO control setting */
	Fc.op = G_IOC_OP_SET;
	Fc.type = UART_FC_NONE;

	if( uart_itf.io_control( handle, IOC_UART_FC, (void*) &Fc) )
	{
		uart_itf.close( handle );
		handle = 0;
	}
}

return handle;
}
//-------------------------------------------------------------------------------
void adl_main ( adl_InitType_e  InitType )
{
	//Init_uDrive_uSD_G1();

	uart1_hdl = uart1_open(UART_RATE_9600);

	if (uart1_hdl == 0)
	{
		return;
	}
	else
	{
		eChStatus_t res;
		ascii * cmd = "U";
		res = uart_itf.write(uart1_hdl, cmd, 1);
                //res = uart_if->write(uart1_hdl, cmd, 1);

		if (res == CH_STATUS_NORMAL)
		{
			// OK
		}
		else if (res == CH_STATUS_ERROR)
		{
		}
}
//-------------------------------------------------------------------------------

The code

uart1_hdl = uart1_open(UART_RATE_9600);

works well returning a valid handle, so the UART1 is open. But when i try to write anything with

uart_itf.write(uart1_hdl, cmd, 1);

or with

uart_if->write(uart1_hdl, cmd, 1);

the module resets itself.

I’ve tried also to set

Settings.event_handlers = NULL;

without success.

Any suggestion ?
Thanks a lot.


#2

I think you missed:

events.op = G_IOC_OP_SET;

in function that opens uart.
Rudolf


#3

Thanks Rudolf but the problem is still present.