aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--demos/ARMCM3-STM32F103-GCC/board.c33
-rw-r--r--ports/ARMCM3-STM32F103/ioports_lld.h12
-rw-r--r--readme.txt3
-rw-r--r--src/templates/ioports_lld.h2
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.