Author Topic: Any tips on making a logic analyzer with STM32F446ZE  (Read 7072 times)

0 Members and 1 Guest are viewing this topic.

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Any tips on making a logic analyzer with STM32F446ZE
« on: January 18, 2019, 08:17:22 am »
I have a Nucleo (144) board with a STM32F446ZE on it.
The plan is to make a Z80 in-circuit emulator with it.
In order to get the timings right, I thought I would first make a purpose built logic analyzer that records running a real Z80 in my circuit.

The idea is to grab the state of all pins on each clock pos-edge and neg-edge transition.
An interrupt might be best for this.
After I have the pin-state I thought I would put that into a buffer and blast the buffer over USB to the PC in the main loop...
I can vary the Z80 clock speed to practically any value - max is 20MHz.

This will be my first real STM32 project (other than flashing leds) so any tips and suggestions are welcome.
I was planning on using CubeMX to get everything setup quickly.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline lucazader

  • Regular Contributor
  • *
  • Posts: 221
  • Country: au
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #1 on: January 18, 2019, 09:42:47 am »
You could setup the required pins as GPIOs on the same bus (eg PF0-15) and then use a memory to memory DMA transfer triggered on the rising or falling edge of the clock signal.

The reference manual GPIO section will give you the correct memory address from which to copy the GPIO ports input data register (https://www.st.com/resource/en/reference_manual/dm00135183.pdf somewhere around pg.189 is where it talks about the Input Data Register for the GPIO ports).

This would allow you to copy the contents of the input data registers into a large array which you could then either save to local flash of the F446, or you could stream this to the PC either via USB, or something else.

Should be 'Pretty Easy'(tm) to set this all up with or without the stmcube.
 

Offline JVR

  • Regular Contributor
  • *
  • Posts: 201
  • Country: be
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #2 on: January 18, 2019, 12:09:06 pm »
Start slow, work your way up to the speed you need. Slow is easy, as you just read the IO pins and report their states to a PC. Fast, that depends on if you want time or state based analysis.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3137
  • Country: ca
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #3 on: January 18, 2019, 03:44:12 pm »
Instead of MCU, look at FT232H. One of the interfaces - FT1248 - is practically a clocked bus, exactly what you need. They claim 30 MBytes/s, so 20 MHz should be fine.

https://www.ftdichip.com/Products/ICs/FT232H.htm
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #4 on: January 19, 2019, 06:49:11 am »
I looked into DMA, but I need to do more reading because Cube did not let me configure the way I thought it would work.

In the spirit of start slow (and simple) I may leave DMA out of the picture for now. Maybe refactor the code a bit later when I need/want more speed. Basically all I need to do is to run all Z80 instructions at least once - I don't mind if that takes all night.
I'm also planning on supporting the non-documented instructions.

I really want to stick with the hardware I've got. I know there are more optimal solutions possible, but this is more a (my first little) STM32 project - if anything else.

I ordered some connectors for it to connect together. Could not find any DIP40 cable sockets (DIP40 plug to flat cable) so I rigged something up. She'll be right.

Currently chopping away at the disassembling part that will run on the PC.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline blacksheeplogic

  • Frequent Contributor
  • **
  • Posts: 532
  • Country: nz
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #5 on: January 19, 2019, 08:36:38 am »
You could setup the required pins as GPIOs on the same bus (eg PF0-15) and then use a memory to memory DMA transfer triggered on the rising or falling edge of the clock signal.

You need use the clock and sample between the edges.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3321
  • Country: nl
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #6 on: January 23, 2019, 01:58:52 am »
Why not simply buy a logic analyser?

You can get a "24MHz 8ch" box from Ali / Ebay / China for less than EUR 10 and these work great with Sigrok / Pulseview.

Any development board with a Cypress CY7C68013A on it will also work. See the Sigrok site for more documentation.

There are some (very small) drawbacks though:
Some old versions of this chip have a high current consumption and get warm when the USB is not initialized (after first plug in).
The cheap boxes from China tend to be quite dirty inside and have agressive flux residues. So open the box and clean it with a bit of water, soap and a toothbrush.

Sigrok is gaining more popularity. I've seen a british shop selling the same "salaea" clone for specific use with Sigrok, and even Sparkfun is selling similar boxes nowadays:
https://www.sparkfun.com/products/15033
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #7 on: January 23, 2019, 06:41:10 am »
Yeah I know, I have one, but I want to monitor all 40 pins of the Z80 - well 38 not counting VCC and GND...

I don't think I can connect 5 boxes at the same time and get reliable results...  ;)

Thanx.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3321
  • Country: nl
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #8 on: January 23, 2019, 10:45:43 am »
The regual Cy7 boxes are made for only 8 channels as you probably know.
When you stick a general CY7C68013 board (those with 2 doulbe row headers) onto Sigrok you get 16 channels, but those have no input protection, you'll have to add that yourself.

I'm not sure how many channels the fx3fun project has in Sigrok, but it is probably not fully polished / integrated in Sigrok, it is not listed in the supported hardware part on the Sigrok site.
https://github.com/cnlohr/fx3fun
The FX3 board sure has impressive capabilities though. and it's also based on ARM.
http://www.cypress.com/documentation/development-kitsboards/cyusb3kit-003-ez-usb-fx3-superspeed-explorer-kit

The FX3 board is also supported by:
https://sysprogs.com/w/tag/analyzer2go/

Analyser2go also supports various STM32F4xx boards, but without the Cypress peripheral the streaming bandwidh is much lower. It is also a commercial package, so instead of having the ability to learn something from the source code you are probably stuck with an expensive binary blob if you want to use it for more than 2 weeks.
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #9 on: January 23, 2019, 12:19:25 pm »
I don't think USB speed is an issue here. I will just run the Z80 at a slower clock speed if my ARM software is too slow.
Like I said, I really want to stick with the hardware I've got.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #10 on: January 23, 2019, 02:08:21 pm »
I tested my stm32f446RE (64-pins nucleo) for parallel port reading, using TIM->DMA->GPIO signal /trigger path. It's able to read
 glitch-free at about 11.25 MHz. 
Have you defined 40-pins? I think, you would have to use 3-4 GPIO ports to assembly 40 lines bus. This 'd be the most difficult part, to locate pins that:
1. Belongs to the same port
2. Consecutive pins, A0, A1 ...etc.
3. Less overall number of ports , less congestion on the DMA bus.

DMA couldn't read each pin, it get's in 8-bits blocks. Block is like A0-A7, A8-A15, B0-B7 etc.
 It possible to not carry for 1, 2, 3 but speed would be much lower than 10 MHz, and more complex pin-bit-magic needs to re-map data.
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #11 on: January 23, 2019, 03:23:28 pm »
I have played around with CubeMX trying to figure out what pin assignments would make most sense.
So far I've concluded that the 16 bit address bus would be one full port and the 8 bit data bus half a port (preferably the lower half).
Now I'm looking into the clock signal, the most critical to be high speed and preferably able to trigger interrupts on both pos- and neg-edges...
Not figured that out yet.

So not using a timer here, but the real clock that is used in the circuit - which is adjustable.
If I would get as fast as 10 Mhz I would be more than happy. For the logic analyzer it is not very important to be super fast because I can slow the Z80 down.

I see this project as a 'getting my feet wet' prelude to the real thing - the in-circuit emulator. If I could get the emulator up to into the couple of MHz, that would be great. A lot more logic will run on the STM32 chip for the emulator than for the logic analyzer.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #12 on: January 23, 2019, 03:52:50 pm »
Study :  AN4666 Application note Parallel synchronous transmission using GPIO and DMA

There is a code available to download from ST.com, unfortunately you have to adapt F429 to F446, since transmit / receive examples for F429.

https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-packages/x-cube-paral-com.html
 
The following users thanked this post: obiwanjacobi

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #13 on: January 30, 2019, 01:02:07 pm »
The plan is to make a Z80 in-circuit emulator with it.
In order to get the timings right, I thought I would first make a purpose built logic analyzer that records running a real Z80 in my circuit.

The idea is to grab the state of all pins on each clock pos-edge and neg-edge transition.

Except for the exercise itself, you shouldnt need to do this.

The Z80 datasheet contains all of the timings for the various signals used in memory/IO read/write operations, so it should be easy enough to reproduce these in code.
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #14 on: January 30, 2019, 02:13:34 pm »
The plan is to make a Z80 in-circuit emulator with it.
In order to get the timings right, I thought I would first make a purpose built logic analyzer that records running a real Z80 in my circuit.

The idea is to grab the state of all pins on each clock pos-edge and neg-edge transition.

Except for the exercise itself, you shouldnt need to do this.

The Z80 datasheet contains all of the timings for the various signals used in memory/IO read/write operations, so it should be easy enough to reproduce these in code.

If with 'datasheet' you mean the user manual, than no - that does not contain enough detailed info.
I have recently found a Mostek document that (looks a lot more like a datasheet and) identifies the operations per machine cycle (one instruction may execute in multiple machine cycle, each taking multiple clock cycles), page 85 - that helps, but the details of how these operations manifest on the Z80 signal lines is not specified (have not read through the entire document yet - so disclaimer).

Still, it would be a good stepping stone for a in-circuit emulator, would it not?

Here are some screen shot of some simple tests I have performed.

Code: [Select]
org $0000
start:
ld b, 2
loop:
djnz loop
halt




Code: [Select]
org $0000
start:
ld a, $AA
ld bc, word
ld (bc), a
halt
word:
defb 00, 00

« Last Edit: January 30, 2019, 02:19:01 pm by obiwanjacobi »
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3321
  • Country: nl
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #15 on: January 30, 2019, 05:03:19 pm »
Pulseview has a software decoder of Z80 Asm from LA traces.
 
The following users thanked this post: obiwanjacobi

Offline blacksheeplogic

  • Frequent Contributor
  • **
  • Posts: 532
  • Country: nz
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #16 on: January 30, 2019, 07:35:36 pm »
I see this project as a 'getting my feet wet' prelude to the real thing - the in-circuit emulator. If I could get the emulator up to into the couple of MHz, that would be great. A lot more logic will run on the STM32 chip for the emulator than for the logic analyzer.

The logic/code is simple, your problem is trying to develop an ICE using flying leads to GPIO pins on a micro. It's not a good way to go.
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #17 on: January 31, 2019, 06:36:36 am »
I see this project as a 'getting my feet wet' prelude to the real thing - the in-circuit emulator. If I could get the emulator up to into the couple of MHz, that would be great. A lot more logic will run on the STM32 chip for the emulator than for the logic analyzer.

The logic/code is simple, your problem is trying to develop an ICE using flying leads to GPIO pins on a micro. It's not a good way to go.

But is it good enough? It might not be the best, fasted, most professional bla bla  :blah:
But will it work with the hardware I've got (F446) knowing I can lower the Z80 clock speed as needed...

Just saying it is no good, does not really help other than stamping out enthusiasm someone might have...  :-//

Pulseview has a software decoder of Z80 Asm from LA traces.

Thanx! I don't know how I missed PulseView, but I had never heard of it before. I can even import and export data files, so I blast the recorded signals to the PC and transform them to a suitable format and then view them in PulseView. Excellent!  :-+
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline blacksheeplogic

  • Frequent Contributor
  • **
  • Posts: 532
  • Country: nz
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #18 on: January 31, 2019, 07:40:50 pm »
Just saying it is no good, does not really help other than stamping out enthusiasm someone might have...  :-//

Or instead of thinking someone is out to get you, you cold also take it as a suggestion to rethink though the design.
 

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #19 on: February 01, 2019, 05:52:34 am »
Just saying it is no good, does not really help other than stamping out enthusiasm someone might have...  :-//

Or instead of thinking someone is out to get you, you cold also take it as a suggestion to rethink though the design.

Lucky for me, I don't think that  ;D

Don't you think some pointers in which area you see a problem would be more constructive?

Previous posts also talked about using different hardware etc - but I really want to use the F446 I've got.
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline ale500

  • Frequent Contributor
  • **
  • Posts: 415
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #20 on: February 01, 2019, 08:46:23 pm »
Lowering the clock can work very well, but I was thinking maybe you can "latch" the information in some '573s and then read them in sequence using your 8 channel logic analyzer, or the STM32.
Another device that may be of interest is a Cypress PSoC5. It has some logic that could do what you want, I saw a project some time ago doing almost that, and it has 5 V tolerant inputs.
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #21 on: February 01, 2019, 10:04:16 pm »
I do not see it mentioned above, but

USE A DCMI INTERFACE TO CAPTURE EXTERNAL DATA

Can be clocked externally (slave parallel inputs) with high precision. GPIO + DMA + TIM is an amateur hour how ya doin solution. And unlikely to be faster than the DCMI interface.

//Also, there is an internal burst fifo and access to fast bus. Plain DMA needs just to many bus turnaround cycles.)
« Last Edit: February 01, 2019, 10:05:53 pm by Yansi »
 
The following users thanked this post: obiwanjacobi

Offline obiwanjacobiTopic starter

  • Frequent Contributor
  • **
  • Posts: 988
  • Country: nl
  • What's this yippee-yayoh pin you talk about!?
    • Marctronix Blog
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #22 on: February 02, 2019, 06:45:58 am »
Lowering the clock can work very well, but I was thinking maybe you can "latch" the information in some '573s and then read them in sequence using your 8 channel logic analyzer, or the STM32.
Another device that may be of interest is a Cypress PSoC5. It has some logic that could do what you want, I saw a project some time ago doing almost that, and it has 5 V tolerant inputs.

Yep, PSoC5 I know. Good call, will look into that. With the help of the programmable logic, it might just be fast enough - not sure.

The Latches - don't know. I want to trigger them on the pos- and neg-edge of the clock and frankly I don't see what benefit having this extra indirection brings...
You still have read that -now latched data- at the same speed as you would without latches.


I do not see it mentioned above, but

USE A DCMI INTERFACE TO CAPTURE EXTERNAL DATA

Can be clocked externally (slave parallel inputs) with high precision. GPIO + DMA + TIM is an amateur hour how ya doin solution. And unlikely to be faster than the DCMI interface.

//Also, there is an internal burst fifo and access to fast bus. Plain DMA needs just to many bus turnaround cycles.)

Excellent, thanks! Will look into that - have to read up on a lot of the special interfaces these STM32's have...
Arduino Template Library | Zalt Z80 Computer
Wrong code should not compile!
 

Offline blacksheeplogic

  • Frequent Contributor
  • **
  • Posts: 532
  • Country: nz
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #23 on: February 02, 2019, 07:35:19 am »
Lowering the clock can work very well, but I was thinking maybe you can "latch" the information in some '573s and then read them in sequence using your 8 channel logic

Yep, PSoC5 I know. Good call, will look into that. With the help of the programmable logic, it might just be fast enough - not sure.

The Latches - don't know. I want to trigger them on the pos- and neg-edge of the clock and frankly I don't see what benefit having this extra indirection brings...
You still have read that -now latched data- at the same speed as you would without latches.

You might be able to lower the clock speed but how will that effect everything else on the bus and can you met the timing constraints. Adding programmable logic on the probe head can buffer, transitioning states needs to be synchronous and there will also be skew which may violate constraints otherwise.

I guess it comes down to what you are trying to accomplish, a fancy project with lots of wires flashing a LED connected to a bit of 7400 logic, or a useful Z80 ICE. The latter needs to be able to take the place of a actual CPU.

Also, often overlooked is that an ICE is a tool which replaces the processor and provided quite complex debug functionality including emulation (for example memory) as well as hardware debug. There's no benefit if all it does it replace the CPU (especially if it cripples the system), far better to focus on the logic analyzer portion and make something useful - for example runs at full bus speed and provides an instruction/data trace which was a common use. You don't have to take the place of the CPU to do this.
 
The following users thanked this post: obiwanjacobi

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Any tips on making a logic analyzer with STM32F446ZE
« Reply #24 on: February 02, 2019, 08:07:01 am »
DCMI can be configured to trigger on either CLK edge and can be gated using the HSYNC signal, if configured in suitable mode.

I do not think you can make any better logic analyzer than using the DCMI, without adding an external dedicated logic (CPLD/FPGA with fast RAM).

Also remember, that the absolute maximum speed DCMI is operable, should be HCLK/3, i.e.  56MHz.  If you go over that, it will do rubbish. I'd make the analyzer sample at 50MHz. It is a nice round value and still enough faster than those crap "Saleae whatever" clones from china.

However if your target then will be to make a Z80 in circuit emulator, your best friend is an FPGA anyway.  Would become very tedious to try achieving so using just software on a completely different architecture.
« Last Edit: February 02, 2019, 08:10:06 am by Yansi »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf