jmayes Posted May 1, 2011 Report Posted May 1, 2011 Hi, I am trying to convert my app from mios8 to mios32. In mios8 I used "PORTCbits.RC0 = 1" to turn a pin on, I can't seem to find an equivalent in mios32. I would like to use the J19 pins if possible. Also is there anything I will need to do to turn off any preexisting drivers or to configure the pins? Thankx for any help someone can provide, Jmayes Quote
ilmenator Posted May 1, 2011 Report Posted May 1, 2011 Not sure about J19, but there is a tutorial that shows how to do that for J5. Quote
jmayes Posted May 1, 2011 Author Report Posted May 1, 2011 Not sure about J19, but there is a tutorial that shows how to do that for J5. Thank you ilmenator, I am looking at that now. Seems some pins have mios32 def's and some don't, I was hoping there was generic C defs could be used to toggle any pin like with the pic. Can someone put some more light on this? Thankx again all, Jmayes Quote
TK. Posted May 2, 2011 Report Posted May 2, 2011 There are generic IO configuration routines which are part of the low-level driver provided by STM. It's already part of the repository, used by MIOS32 and available for all applications as well. Here the source code if you are interested: http://svnmios.midibox.org/listing.php?repname=svn.mios32&path=%2Ftrunk%2Fdrivers%2FSTM32F10x%2Fv3.3.0%2FSTM32F10x_StdPeriph_Driver%2F (but again: the sources are already compiled into the application, no special treatments required to integrate them) Example to configure J19:RC1 (pin PC13) as push-pull output (0/3.3V): GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // weak driver to reduce transients GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC, &GPIO_InitStructure); [/code] Example to configure J19:RC1 (pin PC13) as open drain output (0/5V if pull-up resistor is used): [code] GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // weak driver to reduce transients GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC, &GPIO_InitStructure); Example to configure J19:RC1 (pin PC13) as input with internal pull-up to 3.3V enabled: GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // doesn't really matter for inputs GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC, &GPIO_InitStructure); [/code] Example to configure J19:RC1 (pin PC13) as floating input (w/o pull device): [code] GPIO_InitTypeDef GPIO_InitStructure; GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // doesn't really matter for inputs GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOC, &GPIO_InitStructure); MIOS32 configures J19 pins for software based SPI, but as long as you don't use MIOS32_SPI_...(2...) (SPI port 2), the pins can be used for other purposes w/o danger. Toggling pins: GPIOC->BSRR = GPIO_Pin_13; [/code] will set the pin to 1, and: [code] GPIOC->BRR = GPIO_Pin_13; will set the pin to 0 Best Regards, Thorsten. Quote
jmayes Posted May 2, 2011 Author Report Posted May 2, 2011 (edited) There are generic IO configuration routines which are part of the low-level driver provided by STM. .......... Best Regards, Thorsten. Great! That was exactly what I needed. Thankx again for a quick answer, Jmayes Edited May 2, 2011 by jmayes Quote
jmayes Posted May 23, 2011 Author Report Posted May 23, 2011 Hey TK, While I got this working (with your help), I still don't understand exactly why all the config statements are needed (or how they work). Could you give a statement by statement explanation of how this works? I know it would help me greatly and I am sure other nubies too. Thankx again for all your help! Jmayes Quote
TK. Posted May 23, 2011 Report Posted May 23, 2011 ST provides a very useful documentation for these functions: STM32F10x reference manual: http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/REFERENCE_MANUAL/CD00171190.pdf Chapter 9: General Purpose and alternative-function IOs The functions and parameters are documented in the source code: http://svnmios.midibox.org/filedetails.php?repname=svn.mios32&path=%2Ftrunk%2Fdrivers%2FSTM32F10x%2Fv3.3.0%2FSTM32F10x_StdPeriph_Driver%2Finc%2Fstm32f10x_gpio.h http://svnmios.midibox.org/filedetails.php?repname=svn.mios32&path=%2Ftrunk%2Fdrivers%2FSTM32F10x%2Fv3.3.0%2FSTM32F10x_StdPeriph_Driver%2Fsrc%2Fstm32f10x_gpio.c Best Regards, Thorsten. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.