I need to read data from another chip, one signal, 1.6Mhz and about 16224 bits.
kqr2 told me I should use DMA.
I have spend a whole afternoon on this and got nothing:
http://leaflabs.com/docs/libmaple/api/dma.html?highlight=dma
Could any one told me step by step on how to let it read data, store and transfer it to PC use serial USB?
Thanks a lot!
How could I using DMA to read and store data from another chip
(4 posts) (3 voices)-
Posted 4 years ago #
-
You could drive a DMA channel with a timer running at 1.6MHz, and the DMA channel could read and save a byte into RAM for each sample. Reading the 'bit band' address would be the way I'd do it. Each int at a bit-band address actually corresponds to one bit. You could send all of that straight up to the host, or you could compress it by using the bit value to the sampled pin, and pack 8 of those sampled bits into a byte, reducing the total amount of data you need to send to the host.
That approach would need about 16224bytes of RAM.
A problem might 'jitter' on the input signal. For example if the input signal isn't exactly at 1.6MHz, but is a tiny fraction away, possibly due to temperature drift. In that case, the signal might be sampled a bit early or a bit late, giving the wrong value. You could fix that by detecting the first edge, and waiting for 1/2 a cycle [1/(1.6*10^6 * 2) seconds], then starting the timer. Or you could take several samples, and use the majority, or discard ones near the transition.
If you don't need to do anything while the sampling is happening, it may be as easier to ignore DMA.
Just read the pin. I've suggested a couple approaches in http://forums.leaflabs.com/topic.php?id=1054#post-6477Posted 4 years ago # -
gulu2065,
kqr2 told me I should use DMA.
I have spend a whole afternoon on this and got nothing:
http://leaflabs.com/docs/libmaple/api/dma.html?highlight=dmacheck out this note at the top of the documentation index, http://leaflabs.com/docs/:
If you can’t find what you’re looking for, try looking on our wiki.
the wiki does in fact have a page on using DMA: http://wiki.leaflabs.com/index.php?title=DMA
be advised, however, that this is not "beginner" material. i would definitely try gbulmer's suggestions first, moving on to using DMA only if they don't work out the way you want.
Posted 4 years ago # -
gulu2065 - I've read your post in the other thread http://forums.leaflabs.com/topic.php?id=1054#post-6485 and looks like jitter is not a problem. The output of the Maple timer is synchronising the input data.
So you could use DMA to grab the bit and put it into memory, preferably using a bit band address to ensure you only touch the signal pin.
I would still recommend using one of the techniques I suggested in that other thread.
It did occur to me that if the STM32F is driving the clock for another chip, and transferring data synchronously, then you might be able to use SPI. That hardware peripheral can read 8 or 16 bits at a time at the clock rate.
That would have the advantages
1. The data rate your code has to deal with is 1/8th or 1/16th the bit rate
2. Your code isn't responsible for testing the pin in real-time, that is all done by the SPI hardware peripheral
3. The data is correctly packed as bytes or half words, so there is very little else to do
4. If you wanted to, you could also use DMA to move the SPI data into memoryThe first problem I can see is the clock rate when the SPI is in charge is limited to clock/32 or clock/64.
If that is a problem, maybe you could use the timer to generate the clock for both the external chip and the SPI would run as a 'slave'. I have never tried this, so there may be a problem I haven't thought of.HTH
Posted 4 years ago #
Reply
You must log in to post.