<?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: Doc Request - Coretex M3 - Vector Interupt Primer</title>
		<link>http://forums.leaflabs.com/topic.php?id=40</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:14:37 +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=40" rel="self" type="application/rss+xml" />

		<item>
			<title>mbolivar on "Doc Request - Coretex M3 - Vector Interupt Primer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=40#post-5949</link>
			<pubDate>Tue, 09 Aug 2011 13:55:21 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">5949@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
Is the procedure to setup interrupts on the Maple still valid? I tried to follow the steps... I was trying to get the interrupt from the ADC to work... basically every conversion, the ADC sends an interrupt out to signal a complete conversion.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;nope.  libmaple has been refactored significantly since the time of those posts.  the names of the weakly-defined IRQ handlers are still given in libmaple's /support/ld/names.inc, but the names have all changed:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;https://github.com/leaflabs/libmaple/blob/0.0.11/support/ld/names.inc&#34; rel=&#34;nofollow&#34;&#62;https://github.com/leaflabs/libmaple/blob/0.0.11/support/ld/names.inc&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;the IRQ handler for ADC1 and ADC2 isn't currently defined by libmaple, so just defining your own (and calling it &#34;__irq_adc&#34;) should do the trick.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>jigajigajoo on "Doc Request - Coretex M3 - Vector Interupt Primer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=40#post-5936</link>
			<pubDate>Mon, 08 Aug 2011 15:39:45 +0000</pubDate>
			<dc:creator>jigajigajoo</dc:creator>
			<guid isPermaLink="false">5936@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Is the procedure to setup interrupts on the Maple still valid? I tried to follow the steps... I was trying to get the interrupt from the ADC to work... basically every conversion, the ADC sends an interrupt out to signal a complete conversion.&#60;/p&#62;
&#60;p&#62;I first initialized the ADC (initADC()). I then added an interrupt on the nvic, and the peripheral (in my case the ADC) (initInterrupts()), and then tried to overload the interrupt handlerADC_IRQHandler(). I didn't get it to work.... any input would be invaluable.&#60;/p&#62;
&#60;p&#62;The full code:&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
// START CONSTANTS&#60;br /&#62;
const uint8 numMics = 6;&#60;br /&#62;
volatile int tic = 0;&#60;/p&#62;
&#60;p&#62;// sampleRate = number of ADC cycles per read = ADC_SMPR_x + 12.5 =&#60;br /&#62;
// samples per cycle at 14 MHz. For ADC_SMPR_1_5, total conversion time = 1 microsec.&#60;br /&#62;
const adc_smp_rate sampleRate = ADC_SMPR_28_5;&#60;br /&#62;
const int       sampleRateInt =          28.5; &#60;/p&#62;
&#60;p&#62;// we're using raw adc channels via adcChans instead of micPins&#60;br /&#62;
const int micPins[6] = {D15, D16, D17, D18, D19, D20};&#60;/p&#62;
&#60;p&#62;// below refers to channels according to ADC docs, and not to pins on maple&#60;br /&#62;
// 10-15 correspond to pins D15-D20 on maple&#60;br /&#62;
// the order of adcChans decides the order in which the channels are read&#60;br /&#62;
// (ie first one = chan0, etc)&#60;br /&#62;
const uint8 adcChans[6] = {10, 11, 12, 13, 14, 15};&#60;/p&#62;
&#60;p&#62;HardwareTimer timer(1);&#60;/p&#62;
&#60;p&#62;// END CONSTANTS&#60;/p&#62;
&#60;p&#62;// Analog input pin.  You may need to change this number if your board&#60;br /&#62;
// can't do analog input on pin 15.&#60;br /&#62;
const int analogStartPin = 15;&#60;/p&#62;
&#60;p&#62;void setup() {&#60;br /&#62;
  // Set up board LED to blink, useful for debugging&#60;/p&#62;
&#60;p&#62;  pinMode(BOARD_LED_PIN, OUTPUT);&#60;br /&#62;
  // Declare analogInputPin as INPUT_ANALOG:&#60;br /&#62;
  for(int i = 0; i &#38;lt; numMics; i++)&#60;br /&#62;
  {&#60;br /&#62;
    pinMode(micPins[i], INPUT_ANALOG);&#60;br /&#62;
  }&#60;br /&#62;
  initADC();&#60;br /&#62;
  initInterrupts();&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void initADC() {&#60;br /&#62;
  // ADC register map&#60;br /&#62;
  adc_reg_map *regs = ADC1-&#38;gt;regs;&#60;/p&#62;
&#60;p&#62;  // below not needed, maplelib does it for us!&#60;br /&#62;
  //adc_init(ADC1);&#60;/p&#62;
&#60;p&#62;  // if adc is on, turn it off so we can change settings&#60;br /&#62;
  if(regs-&#38;gt;CR2 &#124; ADC_CR2_ADON) {&#60;br /&#62;
    regs-&#38;gt;CR2 ^= ADC_CR2_ADON;&#60;br /&#62;
  }&#60;br /&#62;
  adc_set_sample_rate(ADC1, sampleRate);&#60;/p&#62;
&#60;p&#62;  // set number of channels to read&#60;br /&#62;
  adc_set_reg_seqlen(ADC1, numMics);&#60;/p&#62;
&#60;p&#62;  // set channel read sequence order (from adcChans)&#60;br /&#62;
  uint32 channels = 0;&#60;br /&#62;
  for (int i = 0; i &#38;lt; numMics; i++) {&#60;br /&#62;
    channels &#124;= (adcChans[i] &#38;lt;&#38;lt; (i*4));&#60;br /&#62;
  }&#60;br /&#62;
  regs-&#38;gt;SQR3 = channels;&#60;/p&#62;
&#60;p&#62;  // scan mode on&#60;br /&#62;
  regs-&#38;gt;CR1 &#124;= ADC_CR1_SCAN;&#60;/p&#62;
&#60;p&#62;  // continuous mode on&#60;br /&#62;
  regs-&#38;gt;CR2 &#124;= ADC_CR2_CONT;&#60;/p&#62;
&#60;p&#62;  // enable end_of_conversion interrupts&#60;br /&#62;
  regs-&#38;gt;CR1 &#124;= ADC_CR1_EOCIE;&#60;/p&#62;
&#60;p&#62;  // calibrate ADC&#60;br /&#62;
  adc_calibrate(ADC1);&#60;/p&#62;
&#60;p&#62;  // turn on ADC&#60;br /&#62;
  regs-&#38;gt;CR2 &#124;= ADC_CR2_ADON;&#60;/p&#62;
&#60;p&#62;  // start adc read&#60;br /&#62;
  regs-&#38;gt;CR2 &#124;= ADC_CR2_SWSTART;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void initInterrupts() {&#60;br /&#62;
  // enable adc interrupt on the interrupt controller&#60;br /&#62;
  nvic_globalirq_enable();&#60;br /&#62;
  nvic_irq_enable(NVIC_ADC_1_2);&#60;/p&#62;
&#60;p&#62;  //enable adc interrupt on the adc&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void ADC_IRQHandler(void) {&#60;br /&#62;
  SerialUSB.print('x');&#60;br /&#62;
  tic++;&#60;br /&#62;
  if(tic == 60)&#60;br /&#62;
  {&#60;br /&#62;
    tic = 0;&#60;br /&#62;
    toggleLED();&#60;br /&#62;
  }&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
 // use interrupts!&#60;br /&#62;
}&#60;br /&#62;
&#60;/code&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Doc Request - Coretex M3 - Vector Interupt Primer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=40#post-157</link>
			<pubDate>Mon, 31 May 2010 13:42:31 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">157@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Were working on getting clean api's together than link to the interrupt (NVIC) system. If youd like to start hacking on it right away, the short answer is thus:&#60;/p&#62;
&#60;p&#62;Check the chip documentation here:&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/stonline/products/literature/rm/13902.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/stonline/products/literature/rm/13902.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;and determine how you would like to configure the NVIC and perihperal. This usually comes in two parts, the perihperal itself needs to be configured for interrupts (like the ADC, or the timer, etc), and the NVIC needs to have the particular interrupt channel enabled. &#60;/p&#62;
&#60;p&#62;Next you need to overflow the default interrupt handlers (which are weakly declared in the linker script), in your sketch/code. For example, in:&#60;/p&#62;
&#60;p&#62;git: libmaple/stm32conf/lanchon-stm32/src/libcs3-lanchon-stm32/lanchon-stm32-vector.S&#60;/p&#62;
&#60;p&#62;we see defined the default interrupt handler routines, like &#34;ADC_IRQHandler&#34;&#60;/p&#62;
&#60;p&#62;These defaults do nothing, but if you define them in your sketch like:&#60;/p&#62;
&#60;p&#62;void ADC_IRQHandler(void) {&#60;br /&#62;
  // stuff&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;And have the NVIC and ADC configured for it, then that should work for you. &#60;/p&#62;
&#60;p&#62;We'll be posting more thorough documentation on interrupts/NVIC as it gets added to libmaple. Ideally we want to turn the process in to something like&#60;/p&#62;
&#60;p&#62;Adc.Begin(ptr-to-interrupt-routine,config params);&#60;/p&#62;
&#60;p&#62;or something...the design for this is in the works but im out of the loop. We do rely on interrupts in several places in libmaple, to provide interfaces to timers, external interrupts, and the systick - I'll dig up the exact locations in the code so you can see how its done.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>coreyfro on "Doc Request - Coretex M3 - Vector Interupt Primer"</title>
			<link>http://forums.leaflabs.com/topic.php?id=40#post-155</link>
			<pubDate>Mon, 31 May 2010 12:34:33 +0000</pubDate>
			<dc:creator>coreyfro</dc:creator>
			<guid isPermaLink="false">155@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hey folks,&#60;/p&#62;
&#60;p&#62;The reason I got the Maple is because I want a serious piece of hardware to handle interrupts.  I have two options, link up lots of micro-controllers, each listening to a device, or get one serious micro-controller.  Obviously, I'd prefer the latter.&#60;/p&#62;
&#60;p&#62;I would love links to documentation around the interweb, but I'd also like to know more about how to leverage the Maple-IDE and API's to unlock this powerful interrupt controller.  Sample code would be great, too.&#60;/p&#62;
&#60;p&#62;Thanks!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
