Author Topic: Porting Code to M5229  (Read 16509 times)

Offline sefai

  • Newbie
  • *
  • Posts: 13
    • View Profile
Porting Code to M5229
« on: September 22, 2009, 01:24:59 PM »
Hi,

I have a working uTasker project for NE64. I am trying to convert this to KIRIN3 with no luck. I am adding my custom code from NE64 project, and configuring TaskConfig.h of the uTaskerV1.4_M522XX project to enable these new tasks. But it does not work. I cannot debug it either, if I put a breakpoint on first line of my application task and try to step over(F10),it never steps over to the next line, it stays on that line...

Can anybody help?

Best regards...

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Porting Code to M5229
« Reply #1 on: September 22, 2009, 01:44:39 PM »
Hi

Verify that the demo project runs correctly on your board first, before making any modifications.
When doing that, check carefully the watchdog operation since the Kirin3 watchdog doesn't allow debugging when it is active, or was activated at anytime after a power on. See the following for some details: http://www.utasker.com/forum/index.php?topic=505.0

Basically ensure that the watchdog is disabled, tnat you can successfully debug the demo project, and then add your new tasks. This may help identify why there is a difficulty.

Regards

Mark

Offline sefai

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Porting Code to M5229
« Reply #2 on: September 22, 2009, 01:55:08 PM »
Hi mark,

I did that, I ran the demo web application,uploaded the files(ftp), and tested the application, everything works fine (of course after _usHeaderLengthAndFlags bug is resolved)...

I configured PORT_TC_BIT1 to toggle when application task is called since I cannot debug (CW cannot place breakpoints and gives error that I cannot place more even if I dont have one and other errors!)... And when I run the code, LED2 is toggled only once, LED1 (watchdog) is toggled 15 times, and then board resets...

My code just opens a TCP port for communication and uses serial port to communicate to an external device, but I disabled the serial port...

Thanks in advance...


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Porting Code to M5229
« Reply #3 on: September 22, 2009, 05:27:19 PM »
Hi

It sounds as though your CW installation has the biggest problem. Have you tried re-installing or comparing performance on another development PC?

From your description it sounds as though your code is causing the board to reset after about 6 seconds. This also is about the time taken for the Ethernet connection to start - is it different when you don't have Ethernet connected?

Is it possible for you to test the project in the simulator? This may behave the same and thus allow debugging.
Also, you could try delaying the start of your own code (say 15s) to see whether the crash then also occurs this time later (to verify that it is really coming from the code operating).

Regards

Mark

Offline sefai

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Porting Code to M5229
« Reply #4 on: September 26, 2009, 10:16:00 PM »
Hi,

You were right, CW was the problem. I was using 7.1.2, and I also upgraded the firmware on two of my M52259DEMO boards, so 7.1.1 couldn't connect them.

Now I am using 7.1.1 with a new (not upgraded) demo board. I can program and debug the board, but here is what I do: I first unplug and then plug USB BDM, then I hold down SW2 switch while I am programming flash (Erase/Blank Check, Program/Verify). Otherwise it always fail with different errors, unable to verify, timed out, unable to read, etc...

I also commented out the INIT_WATCHDOG_DISABLE and WATCHDOG_DISABLE macros and enabled these (they were commented out):

#define INIT_WATCHDOG_DISABLE()    (PNQPAR &= ~(ALT_2_FUNCTION_Q << BIT_1_Q_SHIFT)) // ensure IRQ1 is an input (SW2 on demo board)
#define WATCHDOG_DISABLE()         (!(PORTIN_SETNQ & PORT_NQ_BIT1))  // pull this input down to disable watchdog

With this two macros I can also debug the board, the other two didn't work.

So I have two new questions.

1.Can I use the UARTs for rs485 connections; on NE64, there were two ports and one was configured by a jumper and two pins for rs485 communications?

2.Can I downgrade the two boards so that I can reuse them?

Thanks in advance...


Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Porting Code to M5229
« Reply #5 on: September 27, 2009, 02:39:19 PM »
Hi

I expect that the watchdog was causing some problems when loading - holding SW2 at power up (not reset, since the watchdog can only be deactivated at power up) disabled the watchdog.

However I don't understand why there should be a difference between CW 7.1.1 and CW 7.1.2. Further I thought that the debuggers could still erase and program FLASH even when the watchdog is active, so i am not sure what to advise here.

The M522XX have up to 3 UARTs, which have more features than the ones on the NE64. It may be that your NE64 board had also an (optional) RS-485 transceiver. As long as the electrical connection is correct the UARTs can also be used in RS-485 mode.

Regards

Mark

Offline sefai

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Porting Code to M5229
« Reply #6 on: September 28, 2009, 04:41:58 PM »
Mark,

I am trying to follow the http://www.utasker.com/docs/uTasker/uTaskerUART.PDF doc for RS485, but it does not match with V1.4 code, there is no TIMER_INTERRUPT_SETUP class defined, there is no definition for TIMER_INTERRUPT, TIMER_US_VALUE, TIMER_SINGLE_SHOT, it is not clear also if 52259 supports hardware controller RTS, and all the 485 support got mixed up with MODBUS support.

I am just trying to use a 485 device on UART2 on M52259DEMOKIT. I connected an SP485 to UART2; UTXD2/URXD2 to RO/DI, URTS2* to RE/DE...Tried the hardware support option first, but couldn't make it work, I turned to software support but its complicated...

Thanks in advance...

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Porting Code to M5229
« Reply #7 on: September 28, 2009, 07:33:08 PM »
Hi

The RS485 RTS timing in the UART document is general and doesn't exactly match the M522XX use since the M522XX can be specified to use PIT or DMA Timers to generate the delays (usually DMA timers).

There following thread explains how it can be configured for the M522XX (it is only the timer configuration detail which is special):
http://www.utasker.com/forum/index.php?topic=593.0 (I received confirmation from Neil that it works correctly for him now).

Regards

Mark





Offline sefai

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Porting Code to M5229
« Reply #8 on: September 29, 2009, 07:18:09 PM »
Mark I have read that one and the other threads of Neil. This is what I do:

Code: [Select]

void PP_OpenComm(void)
{
TTYTABLE tInterfaceParameters;                                       // table for passing information to driver

tInterfaceParameters.Channel = 0x02;                                    // set UART channel for serial use
    tInterfaceParameters.ucSpeed = SERIAL_BAUD_9600;                     // baud rate
    tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE;       // input buffer size
    tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE;       // output buffer size
    tInterfaceParameters.Task_to_wake = TASK_PP_RECEIVE;                    // wake self when messages have been received
    #ifdef SUPPORT_FLOW_HIGH_LOW
    tInterfaceParameters.ucFlowHighWater = 80;// set the flow control high and low water levels in %
    tInterfaceParameters.ucFlowLowWater = 20;
    #endif
    tInterfaceParameters.Config = (CHAR_8 + NO_PARITY + ONE_STOP + CHAR_MODE + RTS_CTS);
    tInterfaceParameters.Config |= INFORM_ON_FRAME_TRANSMISSION;
    #ifdef TEST_MSG_MODE
        tInterfaceParameters.usConfig |= (MSG_MODE);
        #if defined (TEST_MSG_CNT_MODE) && defined (SUPPORT_MSG_CNT)
            tInterfaceParameters.usConfig |= (MSG_MODE_RX_CNT);
        #endif
        tInterfaceParameters.usConfig &= ~USE_XON_OFF;
        tInterfaceParameters.ucMessageTerminator = '\r';
    #endif
   
    //#undef SERIAL_SUPPORT_DMA
   
    #ifdef SERIAL_SUPPORT_DMA
        tInterfaceParameters.ucDMAConfig = UART_TX_DMA;                  // activate DMA on transmission
    #endif
    if ((SerialPortID = fnOpen( TYPE_TTY, FOR_I_O, &tInterfaceParameters )) != 0) { // open or change the channel with defined configurations (initially inactive)
   
   
        fnDriver( SerialPortID, ( TX_ON | RX_ON ), 0 );                  // enable rx and tx
       
        fnDriver( SerialPortID, (MODIFY_CONTROL | CONFIG_RTS_PIN), 0 );
        fnDriver( SerialPortID, (MODIFY_CONTROL | CLEAR_RTS), 0 );   
    }
   
}

void fnTimer_0(void);

static DMA_TIMER_SETUP  timer_setup_RTS_negate;

void fnTimer_0(void)
{
TOGGLE_APP_LED_THIRD();
fnDriver(SerialPortID, (MODIFY_CONTROL | CLEAR_RTS), 0);
}

extern void fnUARTFrameTermination(QUEUE_HANDLE Channel)
{
if (Channel == 2) {

timer_setup_RTS_negate.int_type = DMA_TIMER_INTERRUPT;                       
timer_setup_RTS_negate.channel = 1;
timer_setup_RTS_negate.int_priority = DMA_TIMER1_INTERRUPT_PRIORITY;
timer_setup_RTS_negate.int_handler = fnTimer_0;                // enter timer call-back
timer_setup_RTS_negate.mode = (DMA_TIMER_INTERNAL_CLOCK | DMA_TIMER_SINGLE_SHOT_INTERRUPT);
timer_setup_RTS_negate.count_delay = DMA_TIMER_US_DELAY(1,1, 620);

TOGGLE_APP_LED_SECOND();

fnConfigureInterrupt(&timer_setup_RTS_negate); // start delay to RTS negation
}
}

void PP_WriteComm(unsigned short int usSize, unsigned char *pucOut)
{
.
.

  TOGGLE_APP_LED_FIRST();
 
  fnDriver(SerialPortID, (MODIFY_CONTROL | SET_RTS), 0); // driver RTS ‘1’
 
  fnWrite(SerialPortID, pucOut, usSize);
 
.
.
.
}


void fnTaskPPReceive(TTASKTABLE *ptrTaskTable)
{
.
.
.
}

I tried a lot of different combinations, negated RTS, changed count_delay, (for SP485)connected only RTS to RE*, connected both RTS to RE* and CTS to DE, connected CTS to ground, connected RTS to RE* and DE, used
Code: [Select]
fnDriver( PortID, (MODIFY_INTERRUPT | ENABLE_CTS_CHANGE), 0 ); , and many different combinations with no luck.

What can I do now, or maybe Neil can share some thoughts/experience with us?

Best regards...

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3237
    • View Profile
    • uTasker
Re: Porting Code to M5229
« Reply #9 on: September 29, 2009, 07:40:40 PM »
Hi

I think that the problem may be that you are setting the interface to RTS_CTS. This means that it is set to use RTS and CTS for automatic HW flow control mode. As stated in the document ".. the serial interface must not be configured for RTS/CTS flow control operation" when the RTS is to control RS485.

Ensure however that you have SUPPORT_HW_FLOW enabled in config.h since this adds the support for the control of the RTS line (otherwise it will never be controlled).

Note also that the M5225X has several different RTS possibilities depending on the UART used:
- UART0: RTS is always on UA2
- UART1: RTS can be on QS2 or UB2 (depending on the define UART1_ON_QS - see app_hw_m5223x.h)
- UART2: RTS is always on UC2 (but only exists on parts with more than 81 pins)

Regards

Mark