From 1aa2773ad03807e3d5c9822ea108bc2e280281db Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 2 Jun 2009 10:59:32 +0000 Subject: STM32 initialization cleanup. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1015 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- demos/ARMCM3-STM32F103-GCC/board.c | 33 ++++++++++++++++----------------- ports/ARMCM3-STM32F103/ioports_lld.h | 12 +++++++++++- readme.txt | 3 ++- src/templates/ioports_lld.h | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/demos/ARMCM3-STM32F103-GCC/board.c b/demos/ARMCM3-STM32F103-GCC/board.c index 7ce9248cd..2c73879f7 100644 --- a/demos/ARMCM3-STM32F103-GCC/board.c +++ b/demos/ARMCM3-STM32F103-GCC/board.c @@ -59,24 +59,23 @@ void hwinit0(void) { ; /* - * I/O ports initialization as specified in board.h. + * I/O ports initialization as specified in board.h. Note that being this + * a low level initialization routine it is OK to invoke directly the + * low level port functions. */ - ioport_init(); - GPIOA->CRL = VAL_GPIOACRL; - GPIOA->CRH = VAL_GPIOACRH; - GPIOA->ODR = VAL_GPIOAODR; - - GPIOB->CRL = VAL_GPIOBCRL; - GPIOB->CRH = VAL_GPIOBCRH; - GPIOB->ODR = VAL_GPIOBODR; - - GPIOC->CRL = VAL_GPIOCCRL; - GPIOC->CRH = VAL_GPIOCCRH; - GPIOC->ODR = VAL_GPIOCODR; - - GPIOD->CRL = VAL_GPIODCRL; - GPIOD->CRH = VAL_GPIODCRH; - GPIOD->ODR = VAL_GPIODODR; + ioport_init_lld(); + + ioport_stm32_setup_lld(IOPORT_A, VAL_GPIOACRH, VAL_GPIOACRL); + ioport_write_lld(IOPORT_A, VAL_GPIOAODR); + + ioport_stm32_setup_lld(IOPORT_B, VAL_GPIOBCRH, VAL_GPIOBCRL); + ioport_write_lld(IOPORT_B, VAL_GPIOBODR); + + ioport_stm32_setup_lld(IOPORT_C, VAL_GPIOCCRH, VAL_GPIOCCRL); + ioport_write_lld(IOPORT_C, VAL_GPIOCODR); + + ioport_stm32_setup_lld(IOPORT_D, VAL_GPIODCRH, VAL_GPIODCRL); + ioport_write_lld(IOPORT_D, VAL_GPIODODR); } /* diff --git a/ports/ARMCM3-STM32F103/ioports_lld.h b/ports/ARMCM3-STM32F103/ioports_lld.h index fd028e4d3..df12f4bd5 100644 --- a/ports/ARMCM3-STM32F103/ioports_lld.h +++ b/ports/ARMCM3-STM32F103/ioports_lld.h @@ -111,7 +111,7 @@ typedef GPIO_TypeDef * ioportid_t; * @brief GPIO ports subsystem initialization. * @details Ports A-D enabled, AFIO enabled. */ -#define ioport_init() { \ +#define ioport_init_lld() { \ RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN | \ RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | \ RCC_APB2ENR_IOPDEN; \ @@ -201,6 +201,16 @@ typedef GPIO_TypeDef * ioportid_t; #define ioport_readbus_lld(bus) \ (((bus)->bus_portid->IDR & (bus)->bus_mask) >> (bus)->bus_offset) +/** + * @brief GPIO port setup. + * @details This function initializes a GPIO port, note that this functionality + * is STM32 specific and non portable. + */ +#define ioport_stm32_setup_lld(port, crh, crl) { \ + (port)->CRH = (crh); \ + (port)->CRL = (crl); \ +} + #endif /* _IOPORTS_LLD_H_ */ /** @} */ diff --git a/readme.txt b/readme.txt index 29fcab5cc..9d4a1446b 100644 --- a/readme.txt +++ b/readme.txt @@ -70,7 +70,8 @@ GNU-Linux-GCC - ChibiOS/RT simulator for x86 Linux systems, it is interface for digital I/O operations, this should help to create more portable applications and, in general, make easier to work with ChibiOS/RT on multiple architectures. -- NEW: Port driver for STM32. +- NEW: Port driver for STM32, cleaned up the initialization code in board.c to + use the port driver macros. - Documentation section reorganization and fixes. - Changed the STM32 demo stack sizes, it was incorrectly adjusted in version 1.3.0 but it did not create problems (not a bug). diff --git a/src/templates/ioports_lld.h b/src/templates/ioports_lld.h index a046446f5..dff095e75 100644 --- a/src/templates/ioports_lld.h +++ b/src/templates/ioports_lld.h @@ -71,7 +71,7 @@ typedef uint32_t ioportid_t; * @note This function is not invoked by a system API, it should be invoked * from the system initialization code. */ -#define ioport_init() +#define ioport_init_lld() /** * @brief Writes a bits mask on a I/O port. -- cgit v1.2.3