[libopenstm32-devel] gpio_toggle and examples question
Status: Inactive
Brought to you by:
uh1763
|
From: Marko K. <kra...@gm...> - 2011-01-28 09:10:43
|
Hi, I just got a little STM32 discovery board, came across a post from
Uwe somewhere mentioning libopenstm32 and the script to build the
toolchain. I got it up and running and have been playing around a little
bit.
I modified examples/button.c to work with the discovery board (should I
be submitting examples modified for this target, anyway? Could be handy,
as the board is 10 bucks.. nice way to get into ARM, I thought).
Anyway, I started to play with a few of the library routines, and
gpio_toggle doesn't exactly work with multiple GPIOs. If you have some
high, and some low... it toggles them all as they were the same as the
first (presumably) bit read.
eg. If you pass GPIO0...3 to gpio_toggle(), and they are 0xA, instead of
toggling 0xA, 0x5, 0xA ad nauseam, it will go 0xF, 0x0, 0xF.
I came up with a direct way of implementing it properly, and one using
existing functions, I'm not sure which is better?
current function:
void gpio_toggle(u32 gpioport, u16 gpio)
{
if ((gpio_port_read(gpioport) & gpio) == gpio)
gpio_clear(gpioport, gpio);
else
gpio_set(gpioport, gpio);
}
calling existing port read/write functions:
void gpio_toggle(u32 gpioport, u16 gpios)
{
gpio_port_write(gpioport, gpio_port_read(gpioport) ^ gpios);
}
or direct register:
void gpio_toggle(u32 gpioport, u16 gpios)
{
GPIO_ODR(gpioport) = GPIO_IDR(gpioport) ^ gpios;
}
I suppose it's the same deal either way, just not sure what is
preferred. I've made a little wig-wag blinker to demo it, if there is
any want for it.
What else...
Regarding the clock setup bits, eg.
rcc_clock_setup_in_hse_8mhz_out_72mhz() - Is there any thought of moving
this to a more universal function? say like:
rcc_clock_setup_hse(in_mhz, out_mhz) - or so? Do you think this is
worthwhile? (the MCU on this board only goes to 24MHz, so I've just
added a in_hse_8MHz_out_24MHz function temporarily).
Is there a delay function in the works? What areas of the lib need help?
Sorry for rambling. There was more I was thinking about but it seems to
have slipped my mind.
-Mark
|