This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Check FSM state to debug

Other Parts Discussed in Thread: EK-TM4C123GXL, SEGGER, L293D

Hi all,


First of all, i am quite new on microcontroller programing. I am using Keil and a EK-TM4C123GXL.  I have just defined a Finite State Machine to control an old printer stepper motor. It seems to work fine but I want to check the state number of my FSM during execution that is stored in a variable. In real board debuging I have defined an array in my C code to check the state of my FSM every run of my main program, but now I want to export all the sequence of numbers to a txt file in my PC. Any idea, or indication on how to do it? I assume if I am able to do it with the FSM state number I will be able to do it also with the reading of some sensor or any data that the microcontroler is handling. Any idea on how to do it or indication where I can find some info?

Thanks in advance

Joan S.

  • Hello Joan,

    You can use the UART Com Port to send the FSM State Number (which is a variable) to a Serial COM Port Application on the PC Side. The same can be logged into a txt file. Now the only consideration to note is that the serial port works at a low speeds like 115200 bps and if the state machine gets updated very frequently that two successive transmissions is more than state update then it may be logged to sequential and then later processed out to the Com Port.

    Since the EK-TM4C123GXL does not have a SD Card, you could have logged it to SD Card.

    Lastly but not the least a USB Bulk Device can be used to transmit from the TM4C123 to a USB Side Bulk Host. The example for the same exist in the TivaWare.

    Regards
    Amit
  • Joan Sans said:
    ...now I want to export all the sequence of numbers to a txt file in my PC. Any idea, or indication on how to do it?

    As Amit has hinted - you don't provide any desired "rate" for (first) - such number sequence "capture" - and (second) that sequence's data transfer.     Both prove of interest - and likely will dictate key portions of your objective - will they not?

    If reduced execution time of such data logging is "of essence" you may consider writing into - and later extracting from - MCU's SRAM.      Now this method - while fastest - limits the amount of data which may be captured & transferred.      (before you exhaust the capacity of the SRAM)        And you must insure that you "guardband" the SRAM - so that "normal" MCU operation is not impeded.

    MCU you mention has a small SRAM - yet has a more capable, "big brother."      (129 family)       Should fast execution & extended periods between data transfers be important - that upgrade deserves consideration.

    Our "eagle eye" notes your control of, "old stepper motor" - beware that (by itself) the MCU is unlikely to achieve that (power level) objective.      You must impose proper power devices between the MCU and motor (even old ones) and beware that impulse noise most always is generated - and is known to (sometimes) confound MCU operations.

    As w/most (all) things in engineering & programming - final designs often involve "trade-offs" - which seek to meet multiple (and too often conflicting) objectives.      (love when that happens..... i.e. most always!....)

  • Let me add a third alternative for capturing the output. If you have a J-Link then you can use SWO as a high speed serial port (up to 32 of them in fact). Other adapters may support this as well but I know for sure that J-Link does. Segger has recently added another option (which I have not tried yet) to the J-Link that promises even faster output (and input1)).

    As a fourth alternative. IF you have some few GPIO you can use  those to provide a high speed look as the FSM.  The advantages are very high speed output and easily correlated to other behaviour in the system.  IE with a logic analyzer you can compare the state of the FSM to the actual motor drive.

    cb1_mobile said:
    Our "eagle eye" notes your control of, "old stepper motor" - beware that (by itself) the MCU is unlikely to achieve that (power level) objective.

    If, indeed, you are trying to run directly from the CPU take careful heed of this advice.  Even something like the ULN devices is better.

    Robert

    BTW, if you are not using something like the J-Link strongly consider getting one (or a similar device) and using it. Professional tools make a difference and the basic J-Link is inexpensive. If you qualify for the educational version then it's very inexpensive.

    1- SWO should provide input as well, but I've not yet seen a tool support it even though ARM's macros do provide for it.

  • If you are using J-Link.  Take a look at J-Scope (Option 5 ;))

    Robert

  • @Robert,

    Most excellent my friend - you/I have (seen too often) the (unwelcome/unwanted) results which MCU's direct attachment to motor/actuator (usually) causes.

    Unknown if poster has J-Link - but this reporter (& team) have multiple - and will rush now to learn of "faster output (and input!)"     (thanks much for that)

    Your suggestion of "free GPIO" to serve as fastest "FSM monitor" wins this thread's prize.   Three bits reveal 8 possible states - although we note that a clock line (GPIO #4) adds much clarity & "sure Sync."

    Never have I heard of SW(Output) providing input - unclear as to "how" that pin would be "turned around."    (learning never ends!)       Again thanks...

  • Hello cb1, Robert,

    Seems not considering it is a LaunchPad on the TM4C123 it rather difficult (cb1 may agree seeing the earlier snapshot of rigging a J-Link to the launchpad)

    Regards
    Amit
  • Hi Amit,

    Indeed.

    Amit & I underwent somewhat of an "ordeal" to (massage) J-Link's SWD into a 123 L-Pad.     (although1 signal/connection is eliminated via SWD)

    While this thread is (likely) J-Link "free" - others may benefit from the expanded listing of ways/means to (tease) data out...

  • cb1_mobile said:
    Most excellent my friend - you/I have (seen too often) the (unwelcome/unwanted) results which MCU's direct attachment to motor/actuator (usually) causes.

    I've seen enough issues when it's isolated through additional power electronics.  I shudder at the thought of exposing the micro's pins directly to a motor coil.

    cb1_mobile said:
    Unknown if poster has J-Link - but this reporter (& team) have multiple - and will rush now to learn of "faster output (and input!)"     (thanks much for that)

    Look for Real time Terminal.  It's quite a new addition and I've not worked with it yet.

    cb1_mobile said:
    Never have I heard of SW(Output) providing input - unclear as to "how" that pin would be "turned around."    (learning never ends!)       Again thanks...

    .

    I'm using a bit of shorthand.  I don't think they are actually using the SWO line in that case but other lines on the SWD interface to write to a buffer location.  I ran across it in the ARM CMSIS files.  And as I mentioned I've not see a tool environment that actually supports it. Maybe ARM's high end does?

    Robert

  • I'm surprised there isn't a standard JTAG/SWD interface on it.

    Vendor lock-in rearing it's ugly face again?

    Robert
  • Bit slow on the draw - are you not - Robert?     Suspect it's your clock which has "broken" Sync!

    And I had encountered "Real Time Terminal" - started to experiment - then higher priorities buried...

    Thanks for the inputs.     (and do "bump" your clock)

  • Robert Adsett said:
    Vendor lock-in rearing it's ugly face again?  

    Let the "forum world" note - such blasphemy did not spring from one cb1!    

  • I blame the fact that I'm actually debugging today.

    If you haven't yet, take a look at SWO Viewer and J-Scope as well. Slightly different capabilities. I leave multiple channels of SWO running sometimes and can hook up and monitor all or just one to narrow what I want to look at. I can't use it in the fastest loops but it still works for a fair variety.

    I've played a little with J-Scope. It needs global variables to work with but in some circumstances I can see it being a quite powerful (and visual) insight into an operating unit.

    Robert
  • "We'll just help you by removing the standard interfaces. We'll save you a $0.10 on the board".

    Cynical? Moi? Not possible.

    Robert
  • Robert Adsett said:
    "We'll just help you by removing the standard interfaces. We'll save you a $0.10 on the board".   

    The (forum) world may, "little note - nor long recall" - quick arrival of, "blashemy #2" (moments apart) - from the "on fire" pen of squire Adsett.      

    One here sure will...    and (simply love it when, "Vous parlez le francais...")      (no cards/letters, s'il vous plait!    Any French/grammar errors courtesy of flawed HS French teacher)

  • Amit,

    Thanks for your reply. Sorry my ignorance, but I supose I need a serial port in my laptop to be able to use the UART, isn't(which I do not have)? I like more the idea to use the USB port since it is already there. I have check the TIvaWare quickly and not find the example. I will spend some time more and see if I am able to figure out how to do it.
  • Hi,

    I know that I lack a lot of stuff and details, actually I have no idea on how to send data from the ucontroler towards the PC. My point is that I want to learn how to do it and all your comments help me to go in the right direction.

    I am using an L293D to power the old stepper motor. Now next step is to be able to read and store from my USB port (following Amit advice) the FSM state (or any other variable).
  • Robert,

    Thanks. I have no idea what a J-Link is. I will check and see if I can get one.

    As I replied previously, I am using a L293D to drive the stepper motor. Next step the data transmission...
  • Hello Joan,

    To help you accelerate the search

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c123gxl\usb_dev_bulk

    Regards
    Amit
  • Search for Segger J-Link. It sounds like your board has only a non-standard debug interface on it so you'd have to wire it up manually. More's the pity.

    Not having a standard debug connector really narrows your options.

    Robert
  • USB to serial adapters are readily available and inexpensive so that is an option as well. If you do use serial though, do yourself a favour and get something other than hyperterminal.

    Robert
  • Amit,

    I have been investigating. The movie I have created is as follows. I have to connect the USB cable to the debug connector in the launchpad and the other side to the PC. Then I can use UART0(after configuration it and bla bla bla...) to send data to the virtual COM created in the PC, right? Then I only need an application in the PC to read such COM port and do whatever with the data. I am right? The usb_dev_bulk example found in the documentation is doing something like this, right?

    In you previous post you were referring to this possibility or use a PC/Laptop with serial connector?

    Thanks in advance
  • Hello Joan

    The usb_dev_blk comes with Example code on the PC side. This can be used to create an Exe on the PC side which can read the data from the USB port and then can run processing on it.

    Regards
    Amit
  • Amit,

    I know and use it. I loaded example code towards the LaunchPad and installed drivers in PC to establish connection between two devices and I was able to send a string and receive it. Then I analyzed software and I saw a lot of references to UART that I did not understood, since I was expecting something related to USB as pointed out in documentation of USB module. So the main idea of my previous post is correct? Can I use UART0, and read data in the virtual COM port created when USB is pluged to the debug connector, right?

    Thanks in advance
  • Hello Joan,

    The UART is emulated over USB. So in fact it is a USB CDC class device. From an application perspective, you can log the output of the console to a txt file. Some applications like PuTTY may have some processing as well, TeraTerm has scripting (I have used that quite a long time back)

    Regards
    Amit