diff --git a/demos/ARMCM3-STM32F103-GCC/board.c b/demos/ARMCM3-STM32F103-GCC/board.c index d3e776d1a..7ce9248cd 100644 --- a/demos/ARMCM3-STM32F103-GCC/board.c +++ b/demos/ARMCM3-STM32F103-GCC/board.c @@ -61,7 +61,7 @@ void hwinit0(void) { /* * I/O ports initialization as specified in board.h. */ - RCC->APB2ENR = 0x0000003D; // Ports A-D enabled, AFIO enabled. + ioport_init(); GPIOA->CRL = VAL_GPIOACRL; GPIOA->CRH = VAL_GPIOACRH; GPIOA->ODR = VAL_GPIOAODR; diff --git a/ports/ARMCM3-STM32F103/ioports_lld.h b/ports/ARMCM3-STM32F103/ioports_lld.h index 2194c3869..fd028e4d3 100644 --- a/ports/ARMCM3-STM32F103/ioports_lld.h +++ b/ports/ARMCM3-STM32F103/ioports_lld.h @@ -107,6 +107,16 @@ typedef GPIO_TypeDef * ioportid_t; /* functions, please put them in a file named ioports_lld.c if so. */ /*===========================================================================*/ +/** + * @brief GPIO ports subsystem initialization. + * @details Ports A-D enabled, AFIO enabled. + */ +#define ioport_init() { \ + RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN | \ + RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | \ + RCC_APB2ENR_IOPDEN; \ +} + /** * @brief Writes a bits mask on a I/O port. * diff --git a/src/templates/ioports_lld.h b/src/templates/ioports_lld.h index 708efc8b7..a046446f5 100644 --- a/src/templates/ioports_lld.h +++ b/src/templates/ioports_lld.h @@ -65,6 +65,14 @@ typedef uint32_t ioportid_t; /* functions, please put them in a file named ioports_lld.c if so. */ /*===========================================================================*/ +/** + * @brief I/O ports subsystem initialization. + * + * @note This function is not invoked by a system API, it should be invoked + * from the system initialization code. + */ +#define ioport_init() + /** * @brief Writes a bits mask on a I/O port. *