Custom Board Pin Assignment

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
gradoj
Posts: 27
Joined: Mon Aug 11, 2014 5:47 pm

Custom Board Pin Assignment

Post by gradoj » Tue May 26, 2015 8:33 pm

I am trying to get micro python to run on a custom board running the STM32F407. I'm just trying to figure out how to get an LED lit to start with. My board has an LED on PG2.

I changed:
-added LED_RED, PG2 to pins.csv
-modified mpconfigboard.h with #define MICROPY_HW_LED2 (pin_G2) // red
-enabled clock for port g in main.c

I noticed after compiling in pins_af.py the define for my LED is blank:
('LED_RED', ),

Do I need to modify stm32f405_af.csv in the root of boards? and create a new stm32f407_af.csv? or do I need to just modify the stm32f405_af.csv file? I'm not clear on how the make pins is working and what I need to do. Thanks.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Custom Board Pin Assignment

Post by Damien » Wed May 27, 2015 7:01 am

The F407 is almost the same as the F405 so you can use the same af file. The STM32F4DISC port uses the F407 so that might be a better starting point. Remember to configure your crystal frequency!

gradoj
Posts: 27
Joined: Mon Aug 11, 2014 5:47 pm

Re: Custom Board Pin Assignment

Post by gradoj » Wed May 27, 2015 5:08 pm

Yes, thanks. I started with the Discovery board directory.

I still have a question about the pins_af.py file that is generated. If I build the original STM32F4DISC the LED in the pins_af.py entry shows: ('LED_RED', (2, 'TIM4_CH3'), ),
Can someone explain what I'm looking at? Does this mean the red led pin is assigned to the timer module for pwm, etc?

In my build it looks like
('LED_RED', ),
Can I still use it for an IO just without the timer module? Do I need to change my stm32f405_af.csv to use an IO on PG2? Thanks in advance.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Custom Board Pin Assignment

Post by Damien » Wed May 27, 2015 9:29 pm

gradoj wrote: I still have a question about the pins_af.py file that is generated. If I build the original STM32F4DISC the LED in the pins_af.py entry shows: ('LED_RED', (2, 'TIM4_CH3'), ),
Can someone explain what I'm looking at? Does this mean the red led pin is assigned to the timer module for pwm, etc?
It means that the pin called LED_RED has alternate function capabilities and can be connected to the output of TIM4, CH3. By default the pin is a standard GPIO pin.
gradoj wrote: In my build it looks like
('LED_RED', ),
Can I still use it for an IO just without the timer module? Do I need to change my stm32f405_af.csv to use an IO on PG2? Thanks in advance.
Yes it's fine this way. No need to change anything. Your LED_RED pin (=PG2) doesn't have any alternate function capabilites and can only be used as GPIO.

From what you've described everything should be working, and if it compiles and downloads (which it should) then it should work. Do you get a Python REPL prompt over USB/UART?

One thing to check is how your LEDs are driven: the default from the discovery board mpconfigboard.h is that they are push-pull, active high.

gradoj
Posts: 27
Joined: Mon Aug 11, 2014 5:47 pm

Re: Custom Board Pin Assignment

Post by gradoj » Thu May 28, 2015 1:32 am

Okay. I understand how you handle the alternative functions now. Not applicable for that led pin.

Code compiled and programmed on the board. I have a UART on pa9 and 10. I enabled the REPL on uart1 with the compile option in main.c. The UART seems to echo back my characters but no REPL.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: Custom Board Pin Assignment

Post by Damien » Thu May 28, 2015 6:08 am

gradoj wrote:The UART seems to echo back my characters but no REPL.
That's strange because the only way it'll echo back is if the readline function is running which means you'd be in the REPL loop. Try pressing ctrl-C and ctrl-D many times.

Maybe your terminal program is echoing back the chars itself and it's not the board doing it?

Next you'll need to put some debugging code in main.c at various point to see if the code is actually being executed. You can write led_debug(15, 200) to turn all leds on and wait 200ms. But that assumes the leds work!

gradoj
Posts: 27
Joined: Mon Aug 11, 2014 5:47 pm

Re: Custom Board Pin Assignment

Post by gradoj » Thu May 28, 2015 5:19 pm

REPL and LEDs are working. I slowed it down to 9600 and everything works. Still can't get it going at 115200 for some reason. Something wrong with my clock setup. Thanks for your help.

Post Reply