<?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: Accessing raw ports in byte-wise fashion</title>
		<link>http://forums.leaflabs.com/topic.php?id=1071</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:17:40 +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=1071" rel="self" type="application/rss+xml" />

		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-105240</link>
			<pubDate>Mon, 17 Feb 2014 20:10:17 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">105240@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for the replies @cbrunschen and @gbulmer -- even though it's two years later now! Apparently, I didn't see these helpful replies, way back then. I was just Googling, as a refresher on GPIO register names and stumbled on this old post. Took a while before I realised it was mine. LOL&#60;/p&#62;
&#60;p&#62;Of course, I've now actually read up all the data sheets and all is clear. I've also learnt a lot about 32-bit ARM and MIPS MCU architecture in general, since then. So everything really does make a lot more sense now!&#60;/p&#62;
&#60;p&#62;I guess the biggest problem/shock for me back then, having come the 8-bit MCU world, was in realising just how much more configurable and flexible the STM32F10x GPIO ports are! I was thinking in way too small a bubble and well, had a bad attitude about how, &#34;unnecessarily difficult&#34; it all seemed. It's way better! That's why! (And not hard at all, actually.)&#60;/p&#62;
&#60;p&#62;Well, thanks again.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071&amp;page=2#post-6589</link>
			<pubDate>Sun, 25 Sep 2011 14:50:34 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">6589@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gruvin - as cbrunschen has written, the pins are not necessarily in a tidy 'row', but this need not have much impact on you.&#60;/p&#62;
&#60;p&#62;By writing to the Port bit set/reset register, or Port bit reset register (GPIOx_BRR) you can atomically update any subset of 16 pins in a port with a single instruction.&#60;/p&#62;
&#60;p&#62;See manual the ST Micro manual RM0008 sections 9.2.5 &#34;Port bit set/reset register (GPIOx_BSRR)&#34;, and 9.2.6 &#34;Port bit reset register (GPIOx_BRR)&#34; referenced at &#60;a href=&#34;http://leaflabs.com/docs/gpio.html#recommended-reading&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/gpio.html#recommended-reading&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The BSRR register is a sneaky idea, A 16-bit port is mapped to both 16-bit halves of the register.&#60;br /&#62;
Bits that are 0 do not effect any pins.&#60;br /&#62;
Bits set in the top 16 bits of the register clear the corresponding port pin to 0, or low.&#60;br /&#62;
Bits set in the bottom 16 bits of the register set the corresponding port pin to 1 or high.&#60;/p&#62;
&#60;p&#62;It is quite nice to use, e.g. `(GPIOB_BASE)-&#38;gt;BSRR = BIT(3) &#124; BIT(4) &#124; BIT(6) &#124; BIT(9) &#124; BIT(14)&#60;br /&#62;
                                                                                        &#124; ((BIT(5) &#124; BIT(8) &#124; BIT(15)) &#38;lt;&#38;lt; 16;`&#60;/p&#62;
&#60;p&#62;If speed were very critical, I might use a table to map from a value to the inconvenient layout of port pins, e.g.&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;uint32 pinmapB[256] __FLASH__ = {
(BIT(3) &#124; BIT(4) &#124; (BIT(5) &#124; BIT(6) &#124; BIT(8) &#124; BIT(9) &#124; BIT(14) &#124;  BIT(15) &#38;lt;&#38;lt; 16),
(BIT(3) &#124; BIT(4) &#124; (BIT(5) &#124; BIT(6) &#124; BIT(8) &#124; BIT(9) &#124; BIT(14)  &#38;lt;&#38;lt; 16) &#124;  BIT(15),
// ... etc.
};
...
(GPIOB_BASE)-&#38;gt;BSRR = pinmapB[val];&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;But otherwise, maybe write a macro or an inline function to construct it on the fly.&#60;/p&#62;
&#60;p&#62;I often write a little program to generate all the values for a table, with the appropriate C syntax and layout, redirect the text into a file, and #include the file directly into my program:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;uint32 pinmapB[256] __FLASH__ = {
#include &#38;quot;pinmapB_data.h&#38;quot;
};&#60;/code&#62;&#60;/pre&#62;</description>
		</item>
		<item>
			<title>cbrunschen on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6588</link>
			<pubDate>Sun, 25 Sep 2011 11:48:33 +0000</pubDate>
			<dc:creator>cbrunschen</dc:creator>
			<guid isPermaLink="false">6588@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Keep in mind that even on the chip itself, pins from the same port are generally not placed contiguously. On the other hand, as long as all of the pins of a port are available, you can always route the signals together to where you want them. &#60;/p&#62;
&#60;p&#62;Note that not all ports have all their bits available on pins / headers; but you should be able to find several combinations of 8 bits within a port that are all available, even if not pin-contiguously.&#60;/p&#62;
&#60;p&#62;Best wishes,&#60;/p&#62;
&#60;p&#62;// Christian Brunschen
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6586</link>
			<pubDate>Sun, 25 Sep 2011 05:30:21 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">6586@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ah... OK. I've found ~/wirish/boards/maple.cpp&#60;/p&#62;
&#60;p&#62;It seems the digital pin are not actually distributed in the way I wanted, for the most part. Pins are quite 'randomly' scattered about the place, without on single strip of contiguous 8-bits to be found. The closest I can find would be PB10-PB15, on the external header. But they're not in a nice neat row like I'd hoped for. &#60;/p&#62;
&#60;p&#62;Oh well, that's the end of that then. *sigh*&#60;/p&#62;
&#60;p&#62;Thanks for reading. :D
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cbrunschen on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6585</link>
			<pubDate>Sun, 25 Sep 2011 05:21:10 +0000</pubDate>
			<dc:creator>cbrunschen</dc:creator>
			<guid isPermaLink="false">6585@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Generally, you can set all the pins that correspond to a single _port_ – 'A', 'B', etc – in one go by writing to the corresponding register. The mapping from port bits to pins is in the documentation, for the Maple it's at&#60;/p&#62;
&#60;p&#62;  &#60;a href=&#34;http://leaflabs.com/docs/hardware/maple.html#gpio-port-pin-map&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/hardware/maple.html#gpio-port-pin-map&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;General GPIO docs are at&#60;/p&#62;
&#60;p&#62;  &#60;a href=&#34;http://leaflabs.com/docs/gpio.html&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/gpio.html&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;including links to the STM32 docs at the bottom of that page.&#60;/p&#62;
&#60;p&#62;Basically, you identify the port (A, B, C, or similar) that you want to write. For each port, there is a corresponding output register, GPIOx_ODR - for port A, this would be GPIOA_ODR. To set all of the bits to the values you want in one go, simply write the value you want to that register.&#60;/p&#62;
&#60;p&#62;There are also ways to just set and/or reset _some_ bits of a port in an atomic fashion, but without changing other bits about whose values you don't at the moment care.&#60;/p&#62;
&#60;p&#62;For more detailed information, look at the manual at&#60;/p&#62;
&#60;p&#62;  &#60;a href=&#34;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;and in particular section 9, GPIO.&#60;/p&#62;
&#60;p&#62;Best wishes,&#60;/p&#62;
&#60;p&#62;// Christian Brunschen
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6584</link>
			<pubDate>Sun, 25 Sep 2011 05:19:34 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">6584@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oh, there's constants pre-defined gpio_dev pointers for each port, GPIOA, GPIOB, etc.&#60;/p&#62;
&#60;p&#62;See, I told you I needed help getting used to libmaple. :P
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6583</link>
			<pubDate>Sun, 25 Sep 2011 05:17:39 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">6583@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Oh yeah, I forgot -- 16-bit physical ports.&#60;/p&#62;
&#60;p&#62;So I need to figure out how to do a read/modify/write, I guess -- if I only want to affect 8 bits.&#60;/p&#62;
&#60;p&#62;Is it as simple as something like ...&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;gpio_dev *dev = PIN_MAP[0].gpio_device;
dev-&#38;gt;ODR = (dev-&#38;gt;IDR &#38;amp; 0x00ff) &#124; 0xAA;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;???&#60;/p&#62;
&#60;p&#62;I still need to know exactly what port pins actually connect to which Maple pins, of course. Still having some trouble finding that.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6582</link>
			<pubDate>Sun, 25 Sep 2011 05:02:17 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">6582@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Perhaps I should be more specific ...&#60;/p&#62;
&#60;p&#62;Lets say I wanted my Maple Rev.5's pin numbers 0-to-7 to be set to represent the binary value 10101010 (0xAA), LSb on pin 0. What command could I execute to make that happen in a single instruction?&#60;/p&#62;
&#60;p&#62;There. Now that was a bunch less to wade through, wasn't it! :P&#60;/p&#62;
&#60;p&#62;Thanks again, again.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gruvin on "Accessing raw ports in byte-wise fashion"</title>
			<link>http://forums.leaflabs.com/topic.php?id=1071#post-6581</link>
			<pubDate>Sun, 25 Sep 2011 04:53:06 +0000</pubDate>
			<dc:creator>gruvin</dc:creator>
			<guid isPermaLink="false">6581@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello&#60;/p&#62;
&#60;p&#62;For efficiencies sake in a high speed interrupt service routine, I really need to be able to access an entire 8-bit wide port as a single byte, rather than using the likes of digitalWrite(pin, 0&#124;1). Specifically, I want to be able to assemble bit value in a byte register and then write them all to a physical port in one go. I then also need to reset them all in a single instruction. Well, you get the idea. Pretty common stuff.&#60;/p&#62;
&#60;p&#62;To help save me a bunch of time and learning curve with the Maple, can someone please give me an example of how to write and read to an 8-bit wide data port, directly, on the Maple Rev5?&#60;/p&#62;
&#60;p&#62;Also -- where do I go looking for a pin map of which 'Arduino' pin numbers are connected to what ports on the Maple Rev.5's MCU?&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Post-ample ...&#60;/p&#62;
&#60;p&#62;I'm very familiar with how to do all this, having programmed MCU's without Wirish etc for years. I guess what I'm asking for then is some pointers on how to best get under the hood (libmaple?) to get this done in the sort of best, 'libmaple friendly' way -- if that makes sense.&#60;/p&#62;
&#60;p&#62;Obviously, my code will not be necessarily compatible from board to board. That's OK. I'm targeting the Maple Rev5 only for this project.&#60;/p&#62;
&#60;p&#62;Of course, I *could* just go to the SMT32 data sheets and look up the register addresses, etc. But I'm sure there's &#34;better&#34; ways to handle things, given what I have been able to absorb from the libmaple docs. It's all just a bit overwhelming right now.&#60;/p&#62;
&#60;p&#62;Meanwhile, I'll keep reading. Maybe I'll I figure out before someone replies. *gulp*&#60;/p&#62;
&#60;p&#62;Thanks again!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
