<?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: Setting entire GPIO as input/output?</title>
		<link>http://forums.leaflabs.com/topic.php?id=770</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:12:55 +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=770" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Setting entire GPIO as input/output?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=770#post-4615</link>
			<pubDate>Sun, 15 May 2011 06:26:55 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">4615@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666 -&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;So if both CRL and CRH are set to 0x33333333 then you'll have all 16-bits working as push-pull output @ 50MHz?&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;As I mention in the other thread &#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=774&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=774&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;The 50MHz is the rise-time of the electrical signal, and not the rate that software can change the state of the GPIO pin. The theoretical maximum for toggling a pin is two store instructions, which must be at least 2 cycles at 72MHz, or 36MHz. In practice it is usually slower.&#60;/p&#62;
&#60;p&#62;mbolivar -&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;I think that a better approach might be to lock the relevant control register bits through the port configuration lock register: GPIOx_LCKR in RM0008 (see sections 9.1.6 and 9.2.7), and GPIOx_BASE-&#38;gt;LCKR in libmaple.&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Sneaky!-) I haven't tried that!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Setting entire GPIO as input/output?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=770#post-4607</link>
			<pubDate>Sat, 14 May 2011 17:59:24 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">4607@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;robodude666,&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
So if both CRL and CRH are set to 0x33333333 then you'll have all 16-bits working as push-pull output @ 50MHz?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;That's correct.&#60;/p&#62;
&#60;p&#62;Note also that if you don't like typing &#34;-&#38;gt;&#34; (I sure don't), you can say e.g.&#60;/p&#62;
&#60;p&#62;GPIOA_BASE-&#38;gt;CRL = 0x33333333;&#60;/p&#62;
&#60;p&#62;instead.  I haven't checked, but since GPIOA_BASE is just a macro for ((gpio_reg_map*)0x40010800), it's possible that avoiding the indirection might allow the optimizer to do a little extra work.&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
If I read the default configuration of these pins, could I write them back every time?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I think that a better approach might be to lock the relevant control register bits through the port configuration lock register: GPIOx_LCKR in RM0008 (see sections 9.1.6 and 9.2.7), and GPIOx_BASE-&#38;gt;LCKR in libmaple.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "Setting entire GPIO as input/output?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=770#post-4596</link>
			<pubDate>Sat, 14 May 2011 12:20:27 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4596@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ah, that makes sense. I'll look at the manual first in the future :P.&#60;/p&#62;
&#60;p&#62;Each pin is controlled by 4 bits in the CRL/H registers. The lower two control the mode, which is whether it's an input or output, as well as what the output speed is in output mode. The upper two bits control the configuration related to how the pins drain/source current.&#60;/p&#62;
&#60;p&#62;So if both CRL and CRH are set to 0x33333333 then you'll have all 16-bits working as push-pull output @ 50MHz? When configuring a pin to input, is it required to also modify the ODR register to be LOW?&#60;/p&#62;
&#60;p&#62;Lastly, I also assume it's not wise to set the ENTIRE port to input/output, as some of the pins are being used already for something. I can see from the schematic that PA11/PA12 are being used for USB, PB2 is tied to ground for BOOT1, PC9 is connected to the BOOT0 button, and PC13/PC14 are used for the RTC. If I read the default configuration of these pins, could I write them back every time? (so that I simply set CRL/CRH every time instead of having to &#38;amp;/&#124; to save instructions.) Would that work without interrupting their original configuration? In most cases, however, I'm fine with just the lower or upper 8, so I'll try to avoid using the half they reside in.&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>
		<item>
			<title>snigelen on "Setting entire GPIO as input/output?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=770#post-4595</link>
			<pubDate>Sat, 14 May 2011 11:08:45 +0000</pubDate>
			<dc:creator>snigelen</dc:creator>
			<guid isPermaLink="false">4595@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Hello!&#60;/p&#62;
&#60;p&#62;There's some more options on the STM32 than on AVR and it's described in the reference manual (RM0008). But in short, there's four bits in a configuration register and, for pull-up/down, one bit in the ODR-register for each port pin.&#60;/p&#62;
&#60;p&#62;The two lower bits in the configuration register are (from RM0008)&#60;/p&#62;
&#60;p&#62;00: Input mode (reset state)&#60;br /&#62;
01: Output mode, max speed 10 MHz.&#60;br /&#62;
10: Output mode, max speed 2 MHz.&#60;br /&#62;
11: Output mode, max speed 50 MHz&#60;/p&#62;
&#60;p&#62;and the upper two are&#60;/p&#62;
&#60;p&#62;In input mode (MODE[1:0]=00):&#60;br /&#62;
00: Analog mode&#60;br /&#62;
01: Floating input (reset state)&#60;br /&#62;
10: Input with pull-up / pull-down&#60;br /&#62;
11: Reserved&#60;br /&#62;
In output mode (MODE[1:0] &#38;gt;00):&#60;br /&#62;
00: General purpose output push-pull&#60;br /&#62;
01: General purpose output Open-drain&#60;br /&#62;
10: Alternate function output Push-pull&#60;br /&#62;
11: Alternate function output Open-drain&#60;/p&#62;
&#60;p&#62;If you, for example, want a port to be output push-pull max speed 10MHz, the bits will be 0001 in binary. Four bits corresponds to one hexadecimal digit, 0x1 in this case. To set GPIOA in this mode you can write (in recent versions of libmaple)&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;GPIOA-&#38;gt;regs-&#38;gt;CRL = 0x11111111; // Configure GPIOA[7:0]
GPIOA-&#38;gt;regs-&#38;gt;CRH = 0x11111111;  // Configure GPIOA[15:8]&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;(each hexadecimal digit corresponds to one port pin)&#60;/p&#62;
&#60;p&#62;To set GPIOA to input with pull-up enabled the four CR-bits will be 0b1000 which is 0x8 in hex and the ODR-register should be set to all 1's (zeros for pull-down).&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;GPIOA-&#38;gt;regs-&#38;gt;CRL = 0x88888888;
GPIOA-&#38;gt;regs-&#38;gt;CRH = 0x88888888;
GPIOA-&#38;gt;regs-&#38;gt;ODR = 0xFFFF;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;So it's not that straight forward as on AVR's.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>robodude666 on "Setting entire GPIO as input/output?"</title>
			<link>http://forums.leaflabs.com/topic.php?id=770#post-4590</link>
			<pubDate>Fri, 13 May 2011 20:10:37 +0000</pubDate>
			<dc:creator>robodude666</dc:creator>
			<guid isPermaLink="false">4590@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Howdy folks!&#60;/p&#62;
&#60;p&#62;I got my Maple in the mail today, along with some candy!&#60;/p&#62;
&#60;p&#62;I've started work on my first project, which requires me to control the data direction on the entire port. I see there is a &#60;code&#62;gpio_set_mode&#60;/code&#62; function in libmaple for controlling the data direction of one gpio pin, but how do you set multiple at a time (for higher performance)?&#60;/p&#62;
&#60;p&#62;In my previous AVR world, you'd set DDRx to 0xFF or 0x00 to make it an output/input, etc. Is gpio-&#38;gt;regs-&#38;gt;CTL the closest thing? I see gpio_set_mode doing a few things, which confuse me. No 1-liner way of doing it?&#60;/p&#62;
&#60;p&#62;-robodude666
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
