<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: add &#34;adc_attach_interrupt(...)&#34; in libmaple?</title>
		<link>http://forums.leaflabs.com/topic.php?id=1912</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:06:08 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=1912" rel="self" type="application/rss+xml" />

		<item>
			<title>newyorkbrass on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912&amp;page=2#post-26447</link>
			<pubDate>Mon, 03 Jun 2013 22:52:13 +0000</pubDate>
			<dc:creator>newyorkbrass</dc:creator>
			<guid isPermaLink="false">26447@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Is this going to be merged into main line?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912&amp;page=2#post-13075</link>
			<pubDate>Sun, 02 Sep 2012 00:15:01 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">13075@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
What about adding an 'adc_irq_cause' function instead of passing the 'irq_flags' in the 'adc_callback_data' struct? This would make it more inline with the DMA IRQ framework.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;As far as I'm concerned, dma_get_irq_cause() is broken, and there's no good way to fix it. See this thread for why:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=2624&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=2624&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Providing all the bits is more confusing at first, but it's the only way to avoid the kind of confusion that hacks like dma_get_irq_cause() will cause when you stress the implementation.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
What is the usage scenario for the 'arg' argument in the 'adc_callback_data' struct?&#60;br /&#62;
Most&#124;all other interrupt handlers in libmaple have no attached user data.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;I think this is a deficiency. We're trying to backwards-compatibly add user data to callbacks in other areas as well; see this pull request for external interrupts for another example and usage scenario:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/pull/53&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/pull/53&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912&amp;page=2#post-13041</link>
			<pubDate>Sat, 01 Sep 2012 04:06:52 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">13041@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;This is awesome!&#60;/p&#62;
&#60;p&#62;Just one thing I'm curious about, is the 'adc_callback_data' struct needed?&#60;/p&#62;
&#60;p&#62;What about adding an 'adc_irq_cause' function instead of passing the 'irq_flags' in the 'adc_callback_data' struct? This would make it more inline with the DMA IRQ framework.&#60;/p&#62;
&#60;p&#62;What is the usage scenario for the 'arg' argument in the 'adc_callback_data' struct?&#60;br /&#62;
Most&#124;all other interrupt handlers in libmaple have no attached user data.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-13006</link>
			<pubDate>Thu, 30 Aug 2012 15:01:20 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">13006@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;OK, I've got some patches in a branch on my libmaple tree:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/tree/adc-api-expansion&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/tree/adc-api-expansion&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;They provide adc_attach_interrupt() and a variety of other convenience functions to make using it easier.&#60;/p&#62;
&#60;p&#62;Here is an example program which shows how it all fits together:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/examples/adc-low-level-interrupts.cpp&#34; rel=&#34;nofollow&#34;&#62;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/examples/adc-low-level-interrupts.cpp&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The example shows how to start with a pin number, and end up with an interrupt that calls your handler each time ADC conversion on that pin finishes. You can try it out from libmaple like this (WARNING, this will delete any main.cpp you have):&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$ git remote add -f mbolivar git://github.com/mbolivar/libmaple.git
$ git checkout mbolivar/adc-api-expansion
$ rm main.cpp
$ ln -s examples/adc-low-level-interrupts.cpp main.cpp
$ make clean; make install&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Any comments about the new API or the example code are very welcome. Here are the most important new functions:&#60;/p&#62;
&#60;p&#62;- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/adc.c#L145&#34;&#62;adc_set_conv_seq()&#60;/a&#62;&#60;br /&#62;
- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/adc.c#L201&#34;&#62;adc_attach_interrupt()&#60;/a&#62;&#60;br /&#62;
- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/include/libmaple/adc.h#L354&#34;&#62;adc_start_conv()&#60;/a&#62;&#60;br /&#62;
- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/include/libmaple/adc.h#L395&#34;&#62;adc_get_data()&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Some important new types, which you use in your interrupt handlers, are:&#60;/p&#62;
&#60;p&#62;- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/include/libmaple/adc.h#L418&#34;&#62;enum adc_interrupt_id&#60;/a&#62;&#60;br /&#62;
- &#60;a href=&#34;https://github.com/mbolivar/libmaple/blob/adc-api-expansion/libmaple/include/libmaple/adc.h#L462&#34;&#62;struct adc_callback_data&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;Barring any feedback which implies changes, I'll polish this up and merge it into master.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12818</link>
			<pubDate>Thu, 23 Aug 2012 00:33:14 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12818@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I've prepared a document explaining how interrupt handling in libmaple works:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/master/notes/interrupts.txt&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/master/notes/interrupts.txt&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;It's mostly useful as a developers' doc, but it attempts to archive a lot of the information discussed in this thread.&#60;/p&#62;
&#60;p&#62;As it definitely meets the &#34;generally useful&#34; criterion, I'll try to get around to adding &#60;code&#62;adc_attach_interrupt()&#60;/code&#62; (and something like a non-blocking &#60;code&#62;adc_start_conversion(adc_dev* dev, int channel)&#60;/code&#62; to make it more useful) this week.&#60;/p&#62;
&#60;p&#62;As you can see from the document, doing QA on foo_attach_interrupt() routines can be nontrivial given the variety of STM32s libmaple supports, so hopefully you'll forgive us for not having done it sooner. We don't mean to be an unfriendly &#34;zomg RTFS N00b!&#34;-style forum, and I do try to help, but we've got limited resources to devote to Maple, so these things can take a little while sometimes.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12696</link>
			<pubDate>Sun, 19 Aug 2012 09:53:45 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">12696@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;@davies46, that's because the IDE uses Wiring which is a subset of C++ iirc, and therefore does not support all valid C++ syntax. When using the code from within the unix toolchain, both syntax are valid and give the same object code.&#60;/p&#62;
&#60;p&#62;Is your code shareable? It'd be nice to have a look at it...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>davies46 on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12463</link>
			<pubDate>Thu, 16 Aug 2012 02:55:32 +0000</pubDate>
			<dc:creator>davies46</dc:creator>
			<guid isPermaLink="false">12463@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;FWIW, building under the Maple IDE v0.0.12 I got my adc interrupt called when I changed the syntax slightly to:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;extern &#38;quot;C&#38;quot; {
  void __irq_adc(void) {
	conversionInterrupts++;
	ADC2-&#38;gt;regs-&#38;gt;SR = 0;
  }
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;since&#60;br /&#62;
&#60;code&#62;extern &#38;quot;C&#38;quot; void __irq_adc(void) {/* Your ADC handler goes here */}&#60;/code&#62;&#60;br /&#62;
doesn't compile on that setup.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12145</link>
			<pubDate>Wed, 01 Aug 2012 11:02:20 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">12145@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;thanks, but I've got the ADC DMA interrupt up and running in DUAL ADC SCAN mode, but I'd like to use an ADC interrupt, too, besides the DMA interrupt.&#60;/p&#62;
&#60;p&#62;consider the following setup:&#60;/p&#62;
&#60;p&#62;144 sensors -&#38;gt; 9x 16:1 channel multiplexer -&#38;gt; maple mini&#60;/p&#62;
&#60;p&#62;So far I use a timer and in its interrupt I switch the mux channel and start a new ADC conversion burst. DMA is setup once at startup in circular mode and fires its interrupt after all 160 conversions (1 ADC channel is converted twice because dual adc mode requires an even number of channels).&#60;/p&#62;
&#60;p&#62;This works fine for running things at fixed rates, but I'd like be able to run this as fast as possible. Simply replacing the timer interrupt with the ADC interrupt would just be the simplest change and I could even switch easily between the two modes (fixed-rate vs. as-fast-as-you-can).&#60;/p&#62;
&#60;p&#62;Alternatively I'll try this now:&#60;/p&#62;
&#60;p&#62;Set up DMA in non-circular mode and let it fire after each ADC burst (10 conversions), switch the muxes and start the next conversion. And then reset the DMA destination address after all the 160 conversions. For this I won't need an ADC interrupt.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12135</link>
			<pubDate>Tue, 31 Jul 2012 16:44:13 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">12135@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I don't, but I think I have some old code somewhere of ADC firing DMA interrupts. If you can afford the latency hit, maybe it's still useful to you? I can try to dig it up if so.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-12091</link>
			<pubDate>Sat, 28 Jul 2012 11:04:09 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">12091@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Has anybody some working code with an ADC interrupt that could be shared?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-11340</link>
			<pubDate>Thu, 21 Jun 2012 15:36:46 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">11340@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the detailed explanation, this was exactly what I was looking for. Sadly my handler is linked in correctly, so the problem sits somewhere else :-(
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-11339</link>
			<pubDate>Thu, 21 Jun 2012 12:51:08 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">11339@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
Is there a way to check in the produced binary, whether my function was linked in correctly and will be called instead of the __default_handler?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;(I assume you're not using a JTAG or SWD debugger)&#60;/p&#62;
&#60;p&#62;One way is to check the vector table in the disassembly file (in build/&#38;lt;your_board&#38;gt;.disas using libmaple from Git). In libmaple, the vector table symbol is &#60;code&#62;__stm32_vector_table&#60;/code&#62;; it should be the first symbol in the text section (and hence will be at the top of the file). Look up the ADC handler address in the vector table, and make sure it's the address of &#60;code&#62;__irq_adc&#60;/code&#62; (which you can also look up in the disassembly).&#60;/p&#62;
&#60;p&#62;Here's a worked example.&#60;/p&#62;
&#60;p&#62;This is the vector table from a disassembled program with __irq_adc() defined:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;08000000 &#38;lt;__stm32_vector_table&#38;gt;:
 8000000:	00 50 00 20 1d 23 00 08 71 08 00 08 75 08 00 08     .P. .#..q...u...
 8000010:	79 08 00 08 7d 08 00 08 81 08 00 08 d7 1a 00 08     y...}...........
 8000020:	d7 1a 00 08 d7 1a 00 08 d7 1a 00 08 d7 1a 00 08     ................
 8000030:	d7 1a 00 08 d7 1a 00 08 d7 1a 00 08 09 04 00 08     ................
 8000040:	d7 1a 00 08 d7 1a 00 08 d7 1a 00 08 d7 1a 00 08     ................
 8000050:	d7 1a 00 08 d7 1a 00 08 8d 01 00 08 ad 01 00 08     ................
 8000060:	cd 01 00 08 ed 01 00 08 0d 02 00 08 59 1d 00 08     ............Y...
 8000070:	79 1d 00 08 99 1d 00 08 b9 1d 00 08 d9 1d 00 08     y...............
 8000080:	f9 1d 00 08 19 1e 00 08 1d 01 00 08 d7 1a 00 08     ................
 8000090:	29 0a 00 08 d7 1a 00 08 d7 1a 00 08 2d 02 00 08     )...........-...
 80000a0:	c5 1f 00 08 f1 1f 00 08 1d 20 00 08 59 20 00 08     ......... ..Y ..
 80000b0:	b5 20 00 08 31 21 00 08 ad 21 00 08 cd 1e 00 08     . ..1!...!......
 80000c0:	e5 1e 00 08 d9 1e 00 08 f1 1e 00 08 d7 1a 00 08     ................
 80000d0:	d7 1a 00 08 e1 22 00 08 f5 22 00 08 09 23 00 08     .....&#38;quot;...&#38;quot;...#..
 80000e0:	65 02 00 08 d7 1a 00 08 d7 1a 00 08                 e...........&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This contains:&#60;/p&#62;
&#60;p&#62;1. The initial stack pointer,&#60;br /&#62;
2. The addresses of the interrupt handlers, in the order specified by Table 63 in RM0008. (Starting with the reset vector, then NMI, etc.)&#60;/p&#62;
&#60;p&#62;Each entry is 4 bytes long. The byte-order is little-endian. The first entry in the above example (the initial stack pointer value) is thus 0x20005000, and the reset vector is at address 0x0800231d. Note that the last bit in the reset vector address is set. This is the &#34;thumb bit&#34;; it's an ARM feature meaning that the address to be branched to contains thumb-2 (mixed 16- and 32-bit) instructions instead of 32-bit only (this is fine since instructions want 2 or 4 byte alignment). The actual address of the reset vector is thus 0x0800231c.&#60;/p&#62;
&#60;p&#62;__irq_adc() is at offset 0x88 from the start of __stm32_vector_table, so in this example, the corresponding value is 0x0800011d. Masking out the thumb bit, the ADC handler address is 0x0800011c. And sure enough, when I search the disassembly file for &#34;__irq_adc&#34;, this turns up:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;0800011c &#38;lt;__irq_adc&#38;gt;:
 800011c:	4770      	bx	lr&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(My handler is a trivial one that returns immediately, so it just contains a standard &#34;return to caller&#34; &#60;code&#62;bx lr&#60;/code&#62; instruction).
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-11338</link>
			<pubDate>Thu, 21 Jun 2012 09:28:11 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">11338@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I have the feeling that my custom __irq_adc function does not properly replace the weak definition and then libmaple calls the __default_handler which is an infinite loop as I've read in the documentation somewhere.&#60;/p&#62;
&#60;p&#62;Is there a way to check in the produced binary, whether my function was linked in correctly and will be called instead of the __default_handler?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-11300</link>
			<pubDate>Sun, 17 Jun 2012 04:11:53 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">11300@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here my non-working code&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/vCzwm2F6&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/vCzwm2F6&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>ventosus on "add &#34;adc_attach_interrupt(...)&#34; in libmaple?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1912#post-11297</link>
			<pubDate>Sat, 16 Jun 2012 12:56:43 +0000</pubDate>
			<dc:creator>ventosus</dc:creator>
			<guid isPermaLink="false">11297@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;correction: the maple_mini hangs only when actually starting a conversion when both the NVIC_ADC_1_2 and the ADC_CR1_EOCIE are set, no matter whether a custom __irq_adc function was defined or not...
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
