From 0ad5dc5b09f749e8d3b1db737d7283ab58412c96 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 29 Apr 2015 10:58:15 +0200 Subject: Use new rcc_periph_clock_{enable,disable} --- ucoo/hal/adc/adc_hard.stm32f4.cc | 8 ++++++-- ucoo/hal/gpio/test/test_gpio.cc | 4 ++-- ucoo/hal/i2c/i2c_hard.stm32.cc | 15 +++++++-------- ucoo/hal/i2c/test/test_i2c.cc | 6 +++--- ucoo/hal/spi/test/test_spi.cc | 4 ++-- ucoo/hal/uart/test/test_uart.cc | 4 ++-- ucoo/hal/uart/test/test_uart_disc.cc | 4 ++-- ucoo/hal/uart/uart.stm32.cc | 24 ++++++++++-------------- ucoo/hal/usb/usb.stm32.cc | 4 ++-- ucoo/utils/test/test_delay.cc | 2 +- 10 files changed, 37 insertions(+), 38 deletions(-) (limited to 'ucoo') diff --git a/ucoo/hal/adc/adc_hard.stm32f4.cc b/ucoo/hal/adc/adc_hard.stm32f4.cc index 444117f..c89d610 100644 --- a/ucoo/hal/adc/adc_hard.stm32f4.cc +++ b/ucoo/hal/adc/adc_hard.stm32f4.cc @@ -28,6 +28,10 @@ namespace ucoo { +static const enum rcc_periph_clken adc_clken[] = { + RCC_ADC1, RCC_ADC2, RCC_ADC3 +}; + AdcHard::AdcHard (int n) : n_ (n) { @@ -44,7 +48,7 @@ AdcHard::~AdcHard () void AdcHard::enable () { - rcc_peripheral_enable_clock (&RCC_APB2ENR, RCC_APB2ENR_ADC1EN << n_); + rcc_periph_clock_enable (adc_clken[n_]); ADC_CR2 (base_) = ADC_CR2_ADON; } @@ -52,7 +56,7 @@ void AdcHard::disable () { ADC_CR2 (base_) = 0; - rcc_peripheral_disable_clock (&RCC_APB2ENR, RCC_APB2ENR_ADC1EN << n_); + rcc_periph_clock_disable (adc_clken[n_]); } int diff --git a/ucoo/hal/gpio/test/test_gpio.cc b/ucoo/hal/gpio/test/test_gpio.cc index 8d70814..a51017c 100644 --- a/ucoo/hal/gpio/test/test_gpio.cc +++ b/ucoo/hal/gpio/test/test_gpio.cc @@ -56,8 +56,8 @@ int main (int argc, const char **argv) { ucoo::arch_init (argc, argv); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN - | RCC_AHB1ENR_IOPDEN); + rcc_periph_clock_enable (RCC_GPIOB); + rcc_periph_clock_enable (RCC_GPIOD); // For this test, shorten B6 & B7 to have loopback. gpio_mode_setup (GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO7); ucoo::Gpio loop_out (GPIOB, 6); diff --git a/ucoo/hal/i2c/i2c_hard.stm32.cc b/ucoo/hal/i2c/i2c_hard.stm32.cc index a9e8f00..6cadf8b 100644 --- a/ucoo/hal/i2c/i2c_hard.stm32.cc +++ b/ucoo/hal/i2c/i2c_hard.stm32.cc @@ -41,8 +41,8 @@ struct i2c_hardware_t { /// I2C base address. uint32_t base; - /// RCC enable bit. - uint32_t rcc_en; + /// Clock enable identifier. + enum rcc_periph_clken clken; /// Corresponding event IRQ (error IRQ is next one). int ev_irq; }; @@ -51,9 +51,9 @@ struct i2c_hardware_t /// 0. static const i2c_hardware_t i2c_hardware[i2c_nb] = { - { I2C1_BASE, RCC_APB1ENR_I2C1EN, NVIC_I2C1_EV_IRQ }, - { I2C2_BASE, RCC_APB1ENR_I2C2EN, NVIC_I2C2_EV_IRQ }, - { I2C3_BASE, RCC_APB1ENR_I2C3EN, NVIC_I2C3_EV_IRQ }, + { I2C1_BASE, RCC_I2C1, NVIC_I2C1_EV_IRQ }, + { I2C2_BASE, RCC_I2C2, NVIC_I2C2_EV_IRQ }, + { I2C3_BASE, RCC_I2C3, NVIC_I2C3_EV_IRQ }, }; static I2cHard *i2c_instances[i2c_nb]; @@ -99,7 +99,7 @@ I2cHard::enable (int speed) enabled_ = true; uint32_t base = i2c_hardware[n_].base; // Turn on. - rcc_peripheral_enable_clock (&RCC_APB1ENR, i2c_hardware[n_].rcc_en); + rcc_periph_clock_enable (i2c_hardware[n_].clken); // Reset. I2C_CR1 (base) = I2C_CR1_SWRST; // TODO: make sure the bus is free!!! How! @@ -145,8 +145,7 @@ I2cHard::disable () nvic_disable_irq (i2c_hardware[n_].ev_irq + 1); I2C_CR1 (base) = 0; // Turn off. - rcc_peripheral_disable_clock (&RCC_APB1ENR, - i2c_hardware[n_].rcc_en); + rcc_periph_clock_disable (i2c_hardware[n_].clken); } } diff --git a/ucoo/hal/i2c/test/test_i2c.cc b/ucoo/hal/i2c/test/test_i2c.cc index 440edea..8b6ef9b 100644 --- a/ucoo/hal/i2c/test/test_i2c.cc +++ b/ucoo/hal/i2c/test/test_i2c.cc @@ -198,9 +198,9 @@ main (int argc, const char **argv) // Connect I2C1 to I2C3 for the test. // I2C1: B6: SCL, B9: SDA // I2C3: A8: SCL, C9: SDA - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); + rcc_periph_clock_enable (RCC_GPIOA); + rcc_periph_clock_enable (RCC_GPIOB); + rcc_periph_clock_enable (RCC_GPIOC); gpio_mode_setup (GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO6 | GPIO9); gpio_mode_setup (GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO8); gpio_mode_setup (GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9); diff --git a/ucoo/hal/spi/test/test_spi.cc b/ucoo/hal/spi/test/test_spi.cc index 188ff40..f115c83 100644 --- a/ucoo/hal/spi/test/test_spi.cc +++ b/ucoo/hal/spi/test/test_spi.cc @@ -40,8 +40,8 @@ main (int argc, const char **argv) ucoo::Stream &ts = ucoo::test_stream (); // Use connection to LIS302DL device on discovery board revision MB997B. // Revision MB997C uses a different device. - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN - | RCC_AHB1ENR_IOPEEN); + rcc_periph_clock_enable (RCC_GPIOA); + rcc_periph_clock_enable (RCC_GPIOE); ucoo::Gpio ss (GPIOE, 3); ss.set (); ss.output (); diff --git a/ucoo/hal/uart/test/test_uart.cc b/ucoo/hal/uart/test/test_uart.cc index 785d9f1..3f4a53b 100644 --- a/ucoo/hal/uart/test/test_uart.cc +++ b/ucoo/hal/uart/test/test_uart.cc @@ -41,8 +41,8 @@ main (int argc, const char **argv) #elif defined (TARGET_stm32) // D8, D9: UART3 // C12, D2: UART5 - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPCEN); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); + rcc_periph_clock_enable (RCC_GPIOC); + rcc_periph_clock_enable (RCC_GPIOD); gpio_mode_setup (GPIOC, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO12); gpio_mode_setup (GPIOD, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO2 | GPIO8 | GPIO9); gpio_set_af (GPIOC, GPIO_AF8, GPIO12); diff --git a/ucoo/hal/uart/test/test_uart_disc.cc b/ucoo/hal/uart/test/test_uart_disc.cc index b67894b..7efe9ce 100644 --- a/ucoo/hal/uart/test/test_uart_disc.cc +++ b/ucoo/hal/uart/test/test_uart_disc.cc @@ -61,8 +61,8 @@ main (int argc, const char **argv) u4.enable (38400, ucoo::Uart::EVEN, 1); // For this test, shorten B6 & B7 to have a loopback on UART1, shorten C10 // & C11 to connect UART3 to UART4. - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPBEN - | RCC_AHB1ENR_IOPCEN); + rcc_periph_clock_enable (RCC_GPIOB); + rcc_periph_clock_enable (RCC_GPIOC); gpio_mode_setup (GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO6 | GPIO7); gpio_set_af (GPIOB, GPIO_AF7, GPIO6 | GPIO7); diff --git a/ucoo/hal/uart/uart.stm32.cc b/ucoo/hal/uart/uart.stm32.cc index c62ccac..b70b9fe 100644 --- a/ucoo/hal/uart/uart.stm32.cc +++ b/ucoo/hal/uart/uart.stm32.cc @@ -43,8 +43,8 @@ struct uart_hardware_t uint32_t base; /// APB number. int apb; - /// RCC enable bit. - uint32_t rcc_en; + /// Clock enable identifier. + enum rcc_periph_clken clken; /// Corresponding IRQ. int irq; }; @@ -53,12 +53,12 @@ struct uart_hardware_t /// index 0. static const uart_hardware_t uart_hardware[uart_nb] = { - { USART1, 2, RCC_APB2ENR_USART1EN, NVIC_USART1_IRQ }, - { USART2, 1, RCC_APB1ENR_USART2EN, NVIC_USART2_IRQ }, - { USART3, 1, RCC_APB1ENR_USART3EN, NVIC_USART3_IRQ }, - { UART4, 1, RCC_APB1ENR_UART4EN, NVIC_UART4_IRQ }, - { UART5, 1, RCC_APB1ENR_UART5EN, NVIC_UART5_IRQ }, - { USART6, 2, RCC_APB2ENR_USART6EN, NVIC_USART6_IRQ }, + { USART1, 2, RCC_USART1, NVIC_USART1_IRQ }, + { USART2, 1, RCC_USART2, NVIC_USART2_IRQ }, + { USART3, 1, RCC_USART3, NVIC_USART3_IRQ }, + { UART4, 1, RCC_UART4, NVIC_UART4_IRQ }, + { UART5, 1, RCC_UART5, NVIC_UART5_IRQ }, + { USART6, 2, RCC_USART6, NVIC_USART6_IRQ }, }; static Uart *uart_instances[uart_nb]; @@ -103,9 +103,7 @@ Uart::enable (int speed, Parity parity, int stop_bits) enabled_ = true; uint32_t base = uart_hardware[n_].base; // Turn on. - rcc_peripheral_enable_clock - (uart_hardware[n_].apb == 1 ? &RCC_APB1ENR : &RCC_APB2ENR, - uart_hardware[n_].rcc_en); + rcc_periph_clock_enable (uart_hardware[n_].clken); // Set speed, rounded to nearest. int apb_freq = uart_hardware[n_].apb == 1 ? rcc_apb1_frequency : rcc_apb2_frequency; @@ -142,9 +140,7 @@ Uart::disable () nvic_disable_irq (uart_hardware[n_].irq); USART_CR1 (base) = 0; // Turn off. - rcc_peripheral_disable_clock - (uart_hardware[n_].apb == 1 ? &RCC_APB1ENR : &RCC_APB2ENR, - uart_hardware[n_].rcc_en); + rcc_periph_clock_disable (uart_hardware[n_].clken); } } diff --git a/ucoo/hal/usb/usb.stm32.cc b/ucoo/hal/usb/usb.stm32.cc index 70db92b..04f0b70 100644 --- a/ucoo/hal/usb/usb.stm32.cc +++ b/ucoo/hal/usb/usb.stm32.cc @@ -66,8 +66,8 @@ UsbStreamControl::UsbStreamControl (const char *vendor, const char *product) instance_ = this; strings[0] = vendor; strings[1] = product; - rcc_peripheral_enable_clock (&RCC_AHB2ENR, RCC_AHB2ENR_OTGFSEN); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPAEN); + rcc_periph_clock_enable (RCC_OTGFS); + rcc_periph_clock_enable (RCC_GPIOA); gpio_mode_setup (GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO9 | GPIO11 | GPIO12); gpio_set_af (GPIOA, GPIO_AF10, GPIO9 | GPIO11 | GPIO12); diff --git a/ucoo/utils/test/test_delay.cc b/ucoo/utils/test/test_delay.cc index 0894d79..b56c7c1 100644 --- a/ucoo/utils/test/test_delay.cc +++ b/ucoo/utils/test/test_delay.cc @@ -31,7 +31,7 @@ int main (int argc, const char **argv) { ucoo::arch_init (argc, argv); - rcc_peripheral_enable_clock (&RCC_AHB1ENR, RCC_AHB1ENR_IOPDEN); + rcc_periph_clock_enable (RCC_GPIOD); gpio_mode_setup (GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12 | GPIO13 | GPIO14 | GPIO15); gpio_clear (GPIOD, GPIO12 | GPIO13 | GPIO14 | GPIO15); -- cgit v1.2.3