Thursday, May 21, 2020

Semihosting in the Eclipse Environment

Semihosting is a mechanism that enables code running on an ARM target (MCU like STM32F407) to communicate and use the Input/Output facilities on a host computer that's running a debugger.

Initializing this ability, and running your code in debug mode will allow you enable functions in the C library to print statements to the console in your IDE.


Seems useful!  It's very specific to setup so here it is for the Eclipse IDE for System Workbench 32 (STM32 MCU IDE)

Using: Eclipse Studio on Win10

Keywords: Semihosting
Notes: Only works when Eclipse IDE is in debug mode


  1. Apply Linker Argument Settings

    1. Right click on Project

    2. Properties

    3. C/C++ Build

    4. Settings

    5. MCU G++ Linker

    6. Miscellaneous

    7. In the Linker Flags box, type:

      -specs=rdimon.specs -lc -lrdimon

    8. At the bottom of the window, click “Apply”

    9. OK.

    10. While we’re here… if we try to print variables right now, we’ll break the compiler because we haven’t set up the floating point hardware. Change the floating point hardware to ‘No Unit’ Change the Floating-point ABI to Software: ‘soft’

    11. OK.

    12. Close


  1. Set Debug Configuration

    1. Clean, and Build your project so you get a binary file:

      1. Right click on project

      2. Build Project

      3. See binary file

    2. Right click on Project

    3. Debug As

    4. Debug Configurations

    5. Startup Tab

    6. Select the Binary File from the list (*Debug file)

    7. In the Run Commands box type:

      monitor arm semihosting enable

    8. Click Apply

  2. Set the Debug Configuration:
      1. Build your project so you get a binary file

      2. Right click on project

      3. Build Project

    1. Close.

  3. Open the application code for your project
    (eg main.c)

    1. Add to the file:

      extern void initialize_monitor_handles();

    2. ALSO make sure you #include <stdio.h>

    1. In the main function of the main file, add the initialization function (yep, we're British here):

      initialise_monitor_handles();

  1. Exclude sysmem.c from the build

    1. Go to the Project Tree

    2. Expand startup

    3. Right click on sysmem.c

    4. Resource Configuration

    5. Exclude from Build

    6. Debug and Release.  OK.

  2. Add a ‘printf’ statement to your code. 
    BE SURE TO END WITH “\n”

  3. Clean Project

  4. Build Project

  5. Debug

  6. Open the Console Tab


Tested, working!

Something to add or share? Glad to hear it - leave it below!

Wednesday, May 20, 2020

$12 Logic Analyzer from Amazon, and using it with PulseView!

I bought myself a new, pretty fast scope with decoding capabilities. The tradeoff - only two channels.  I2C is everything, right?  
But when some SPI work came up I needed a logic analyzer.

So, without further ado - setting up your $12 Amazon Logic Analyzer with open source signal analysis software suite from Sigrok - PulseView!



The Product(s):

The Setup:

In Windows Device Manager, it comes up:


Download and install Zadig to install USB drivers.
https://zadig.akeo.ie/


Open Zadig. Select unknown device (that’s your logic analyzer)

Install WinUSB(Microsoft) since I’m using a Win10 computer.

Doesn’t seem to let me rename the device. Oh well.


Download/Open PulseView - an open source signal analysis suite.  It’s very cool.

https://sigrok.org/wiki/Downloads


Pull down “Connect to Device” and select ‘fx2lafw (generic driver for FX2 based LAs)’


Scan for devices.


The program detects a Saleae Logic Analyzer attached.
Seems like this product may be using the USB VID/PID from Saleae.

Saleae is a company that builds really nice logic analyzers, and very nice software as well if you’re looking for a logic analyzer with some more features and functionality. I haven’t used it personally, but I’ve taken online classes where it’s being used and it seems great. https://www.saleae.com/ 

Pressing on...


Click the Decoder Selector yellow/green icon left of 24MHz, Pick the protocol (I’m using SPI)

Rename the relevant signals (if desired) and click the SPI signal line.  Assign the signals on the logic analyzer (LA) to the protocol signals

Bear in mind PulseView labels their Channels 0-7, my particular logic analyzer labels them CH1 - CH8, CLK and GND.  So PulseView’s CH0 is my analyzer’s CH1.  You can rename the channels in PulseView just by clicking on the channel and editing the ‘Name’ field.


**I’m not using the default CLK pin on the logic analyzer… not really sure what that does yet, actually.  Connect one of the channels (CH1-CH8) as the clock signal and use that, and of course make sure you connect your grounds (and the LA ground) appropriately.


Set Samples to maybe 500M, and change the frequency to maybe 24MHz.

That gave me 21 seconds of sample time, and enough resolution to see the SPI transfers:

The Hardware: STM32 Discovery, Arduino Uno, LA and an O-Scope with a decoder to verify.

 

Voila!  Setting up your $12 logic analyzer with open source PulseView.


Have some advice on settings and configurations?  Something to share?  Drop it in the comments!