I think the second option looks quite reasonable. I will give it a try tomorrow. It is the first time I will start writing something a little more extensive for the system!! :-) I hope it optimizes as expected. With Warm Regards, Ivan Raul On Wed, Jan 29, 2014 at 10:04 PM, Pekka Nikander <pekka.nikander@xxxxxx>wrote: > >>> To really make the PWM work, still the GPIO alternate functions need > to be initialized, do I work on that in parallel with the Serial testing? > >> > >> Please remind me what this was about? > >> > > Is the setting of the alternate functions: > > > > > https://github.com/Ell-i/Arduino/blob/ell-i/hardware/ell-i/stm32/variants/ellduino_stm32f051/stm32f051_init.c#L321 > > > > Serial sets them in begin routine, but there is not initialization part > for analogWrite. The timer is activated, but it can't access the pins. > > I see. I have completely forgotten that we need to not only activate the > GPIO peripherals in the RCC register, but also to initialise them for > analogWrite, SPI, and perhaps other functions. I thought about that back > in November but alas my memory is too short. (Or there are too many things > I'm trying to remember. :-) > > Anyway, we have here a small architectural problem. Architecturally, each > GPIO pin is a separate entity, and has a separate mode, output type, output > speed, pull up/down, and alternate function setting. However, if we just > simply declare them separately for each pin, we consume quite a lot of > memory as we would have to define about 6 * 32 bits for each pin. On the > other hand, if we define each GPIO register initialisation value, as we've > done in the old runtime, then the definitions for each pin get dispersed > over several lines in the source code, which is bad from the modularity and > maintenance point of view. > > That is, I'd like to use a macro like > > DEFINE_GPIO_PIN_INIT(B, 2, INPUT, ..., AF2); > > One line for each pin. > > The simple approach would then to generate a simple init record like > const SystemInitRecordArrayData32NoAddress ... { > ... > D32(GPIO_TypeDef, AF[0], GPIO_AFRx_AFRx3_AF2) > > However, that would consume excessive memory, as I wrote. > > Perhaps we could generate static const values out of the macro, and then > combine them? Something like > > ... > static const __GPIOB_PIN2_AF = GPIO_AFRx_AFRx3_AF2; > ... > const SystemInitRecordArrayData32NoAddress ... { > ... > D32(GPIO_TypeDef, AF[0], > __GPIOB_PIN0_AF | > __GPIOB_PIN1_AF | > ... > > What do you think? Would that work? Could you perhaps try it, Ivan? Or > should I? > > --Pekka > > >