Changeset 228ece9 in rtems


Ignore:
Timestamp:
Apr 12, 2012, 7:27:56 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
52cf1358, 8c6608bd
Parents:
b467782b
git-author:
Sebastian Huber <sebastian.huber@…> (04/12/12 19:27:56)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/12/12 20:48:56)
Message:

bsp/stm32f4: Add IO and RCC

Location:
c/src/lib/libbsp/arm/stm32f4
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/stm32f4/Makefile.am

    rb467782b r228ece9  
    4747include_bsp_HEADERS += include/usart.h
    4848include_bsp_HEADERS += include/stm32f4.h
     49include_bsp_HEADERS += include/io.h
     50include_bsp_HEADERS += include/rcc.h
    4951
    5052###############################################################################
     
    7678libbsp_a_SOURCES += startup/bspstarthook.c
    7779libbsp_a_SOURCES += startup/bspreset.c
     80libbsp_a_SOURCES += startup/io.c
     81libbsp_a_SOURCES += startup/rcc.c
    7882
    7983# IRQ
  • c/src/lib/libbsp/arm/stm32f4/console/console-config.c

    rb467782b r228ece9  
    2828      .deviceType = SERIAL_CUSTOM,
    2929      .pDeviceFns = &stm32f4_usart_fns,
    30       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_1,
     30      .ulCtrlPort1 = (uint32_t) STM32F4_USART_1,
    3131      .ulCtrlPort2 = 0,
    3232      .ulClock = STM32F4_USART_BAUD,
     
    3939      .deviceType = SERIAL_CUSTOM,
    4040      .pDeviceFns = &stm32f4_usart_fns,
    41       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_2,
     41      .ulCtrlPort1 = (uint32_t) STM32F4_USART_2,
    4242      .ulCtrlPort2 = 1,
    4343      .ulClock = STM32F4_USART_BAUD,
     
    5050      .deviceType = SERIAL_CUSTOM,
    5151      .pDeviceFns = &stm32f4_usart_fns,
    52       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_3,
     52      .ulCtrlPort1 = (uint32_t) STM32F4_USART_3,
    5353      .ulCtrlPort2 = 2,
    5454      .ulClock = STM32F4_USART_BAUD,
     
    6161      .deviceType = SERIAL_CUSTOM,
    6262      .pDeviceFns = &stm32f4_usart_fns,
    63       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_4,
     63      .ulCtrlPort1 = (uint32_t) STM32F4_USART_4,
    6464      .ulCtrlPort2 = 3,
    6565      .ulClock = STM32F4_USART_BAUD,
     
    7272      .deviceType = SERIAL_CUSTOM,
    7373      .pDeviceFns = &stm32f4_usart_fns,
    74       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_5,
     74      .ulCtrlPort1 = (uint32_t) STM32F4_USART_5,
    7575      .ulCtrlPort2 = 4,
    7676      .ulClock = STM32F4_USART_BAUD,
     
    8383      .deviceType = SERIAL_CUSTOM,
    8484      .pDeviceFns = &stm32f4_usart_fns,
    85       .ulCtrlPort1 = (uint32_t) &STM32F4_USART_6,
     85      .ulCtrlPort1 = (uint32_t) STM32F4_USART_6,
    8686      .ulCtrlPort2 = 5,
    8787      .ulClock = STM32F4_USART_BAUD,
  • c/src/lib/libbsp/arm/stm32f4/console/usart.c

    rb467782b r228ece9  
    1616
    1717#include <bsp.h>
     18#include <bsp/io.h>
     19#include <bsp/rcc.h>
    1820#include <bsp/irq.h>
    1921#include <bsp/usart.h>
     
    3133}
    3234#endif
     35
     36static const stm32f4_rcc_index usart_rcc_index [] = {
     37  STM32F4_RCC_USART1,
     38  STM32F4_RCC_USART2,
     39  STM32F4_RCC_USART3,
     40  STM32F4_RCC_UART4,
     41  STM32F4_RCC_UART5,
     42  STM32F4_RCC_USART6
     43};
     44
     45static stm32f4_rcc_index usart_get_rcc_index(const console_tbl *ct)
     46{
     47  return usart_rcc_index [ct->ulCtrlPort2];
     48}
    3349
    3450static const uint8_t usart_pclk_index [] = { 1, 0, 0, 0, 0, 1 };
     
    103119}
    104120
     121#define USART_CFG(port, idx, altfunc) \
     122  { \
     123    .pin = STM32F4_GPIO_PIN(port, idx), \
     124    .mode = STM32F4_GPIO_MODE_AF, \
     125    .otype = STM32F4_GPIO_OTYPE_PUSH_PULL, \
     126    .ospeed = STM32F4_GPIO_OSPEED_2_MHZ, \
     127    .pupd = STM32F4_GPIO_PULL_UP, \
     128    .af = altfunc \
     129  }
     130
     131static const stm32f4_gpio_config usart_gpio_config [] [2] = {
     132  {
     133    USART_CFG(0, 9, STM32F4_GPIO_AF_USART1),
     134    USART_CFG(0, 10, STM32F4_GPIO_AF_USART1)
     135  }, {
     136    USART_CFG(0, 2, STM32F4_GPIO_AF_USART2),
     137    USART_CFG(0, 3, STM32F4_GPIO_AF_USART2)
     138  }, {
     139    USART_CFG(3, 8, STM32F4_GPIO_AF_USART3),
     140    USART_CFG(3, 9, STM32F4_GPIO_AF_USART3)
     141  }, {
     142    USART_CFG(0, 1, STM32F4_GPIO_AF_UART4),
     143    USART_CFG(0, 2, STM32F4_GPIO_AF_UART4)
     144  }, {
     145    USART_CFG(2, 11, STM32F4_GPIO_AF_UART5),
     146    USART_CFG(2, 12, STM32F4_GPIO_AF_UART5)
     147  }, {
     148    USART_CFG(2, 6, STM32F4_GPIO_AF_USART6),
     149    USART_CFG(2, 7, STM32F4_GPIO_AF_USART6)
     150  }
     151};
     152
     153static void usart_set_gpio_config(const console_tbl *ct)
     154{
     155  const stm32f4_gpio_config *config = usart_gpio_config [ct->ulCtrlPort2];
     156
     157  stm32f4_rcc_set_gpio_clock(config [0].pin, true);
     158  stm32f4_gpio_set_config(&config [0]);
     159  stm32f4_rcc_set_gpio_clock(config [1].pin, true);
     160  stm32f4_gpio_set_config(&config [1]);
     161}
     162
    105163static void usart_initialize(int minor)
    106164{
     
    109167  uint32_t pclk = usart_get_pclk(ct);
    110168  uint32_t baud = usart_get_baud(ct);
    111   volatile stm32f4_rcc *rcc = &STM32F4_RCC;
    112 
    113   rcc->apb2enr |= STM32F4_RCC_APB2ENR_USART1_EN;
     169  stm32f4_rcc_index rcc_index = usart_get_rcc_index(ct);
     170
     171  stm32f4_rcc_set_clock(rcc_index, true);
     172  usart_set_gpio_config(ct);
    114173
    115174  usart->cr1 = 0;
  • c/src/lib/libbsp/arm/stm32f4/include/stm32f4.h

    rb467782b r228ece9  
    2121
    2222typedef struct {
    23         uint32_t reserved_00 [16];
    24         uint32_t apb1enr;
    25 #define STM32F4_RCC_APB1ENR_DAC_EN BSP_BIT32(29)
    26 #define STM32F4_RCC_APB1ENR_PWR_EN BSP_BIT32(28)
    27 #define STM32F4_RCC_APB1ENR_CAN2_EN BSP_BIT32(26)
    28 #define STM32F4_RCC_APB1ENR_CAN1_EN BSP_BIT32(25)
    29 #define STM32F4_RCC_APB1ENR_I2C3_EN BSP_BIT32(23)
    30 #define STM32F4_RCC_APB1ENR_I2C2_EN BSP_BIT32(22)
    31 #define STM32F4_RCC_APB1ENR_I2C1_EN BSP_BIT32(21)
    32 #define STM32F4_RCC_APB1ENR_UART5_EN BSP_BIT32(20)
    33 #define STM32F4_RCC_APB1ENR_UART4_EN BSP_BIT32(19)
    34 #define STM32F4_RCC_APB1ENR_USART3_EN BSP_BIT32(18)
    35 #define STM32F4_RCC_APB1ENR_USART2_EN BSP_BIT32(17)
    36 #define STM32F4_RCC_APB1ENR_SPI3_EN BSP_BIT32(15)
    37 #define STM32F4_RCC_APB1ENR_SPI2_EN BSP_BIT32(14)
    38 #define STM32F4_RCC_APB1ENR_WWDG_EN BSP_BIT32(11)
    39 #define STM32F4_RCC_APB1ENR_TIM14_EN BSP_BIT32(8)
    40 #define STM32F4_RCC_APB1ENR_TIM13_EN BSP_BIT32(7)
    41 #define STM32F4_RCC_APB1ENR_TIM12_EN BSP_BIT32(6)
    42 #define STM32F4_RCC_APB1ENR_TIM7_EN BSP_BIT32(5)
    43 #define STM32F4_RCC_APB1ENR_TIM6_EN BSP_BIT32(4)
    44 #define STM32F4_RCC_APB1ENR_TIM5_EN BSP_BIT32(3)
    45 #define STM32F4_RCC_APB1ENR_TIM4_EN BSP_BIT32(2)
    46 #define STM32F4_RCC_APB1ENR_TIM3_EN BSP_BIT32(1)
    47 #define STM32F4_RCC_APB1ENR_TIM2_EN BSP_BIT32(0)
    48         uint32_t apb2enr;
    49 #define STM32F4_RCC_APB2ENR_TIM11 BSP_BIT32(18)
    50 #define STM32F4_RCC_APB2ENR_TIM10_EN BSP_BIT32(17)
    51 #define STM32F4_RCC_APB2ENR_TIM9_EN BSP_BIT32(16)
    52 #define STM32F4_RCC_APB2ENR_SYSCFG_EN BSP_BIT32(14)
    53 #define STM32F4_RCC_APB2ENR_SPI1_EN BSP_BIT32(12)
    54 #define STM32F4_RCC_APB2ENR_SDIO_EN BSP_BIT32(11)
    55 #define STM32F4_RCC_APB2ENR_ADC3_EN BSP_BIT32(10)
    56 #define STM32F4_RCC_APB2ENR_ADC2_EN BSP_BIT32(9)
    57 #define STM32F4_RCC_APB2ENR_ADC1_EN BSP_BIT32(8)
    58 #define STM32F4_RCC_APB2ENR_USART6_EN BSP_BIT32(5)
    59 #define STM32F4_RCC_APB2ENR_USART1_EN BSP_BIT32(4)
    60 #define STM32F4_RCC_APB2ENR_TIM8_EN BSP_BIT32(1)
    61 #define STM32F4_RCC_APB2ENR_TIM1_EN BSP_BIT32(0)
     23        uint32_t moder;
     24        uint32_t otyper;
     25        uint32_t ospeedr;
     26        uint32_t pupdr;
     27        uint32_t idr;
     28        uint32_t odr;
     29        uint32_t bsrr;
     30        uint32_t lckr;
     31        uint32_t afr [2];
     32        uint32_t reserved_28 [246];
     33} stm32f4_gpio;
     34
     35#define STM32F4_GPIO(i) ((volatile stm32f4_gpio *) (STM32F4_BASE + 0x40020000) + (i))
     36
     37typedef struct {
     38        uint32_t cr;
     39        uint32_t pllcfgr;
     40        uint32_t cfgr;
     41        uint32_t cir;
     42        uint32_t ahbrstr [3];
     43        uint32_t reserved_1c;
     44        uint32_t apbrstr [2];
     45        uint32_t reserved_28 [2];
     46        uint32_t ahbenr [3];
     47        uint32_t reserved_3c;
     48        uint32_t apbenr [2];
     49        uint32_t reserved_48 [2];
     50        uint32_t ahblpenr [3];
     51        uint32_t reserved_5c;
     52        uint32_t apblpenr [2];
     53        uint32_t reserved_68 [2];
     54        uint32_t bdcr;
     55        uint32_t csr;
     56        uint32_t reserved_78 [2];
     57        uint32_t sscgr;
     58        uint32_t plli2scfgr;
    6259} stm32f4_rcc;
    6360
    64 #define STM32F4_RCC (*(volatile stm32f4_rcc *) (STM32F4_BASE + 0x40023800))
     61#define STM32F4_RCC ((volatile stm32f4_rcc *) (STM32F4_BASE + 0x40023800))
    6562
    6663typedef struct {
     
    139136} stm32f4_usart;
    140137
    141 #define STM32F4_USART_1 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40011000))
    142 #define STM32F4_USART_2 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40004400))
    143 #define STM32F4_USART_3 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40004800))
    144 #define STM32F4_USART_4 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40004c00))
    145 #define STM32F4_USART_5 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40005000))
    146 #define STM32F4_USART_6 (*(volatile stm32f4_usart *) (STM32F4_BASE + 0x40011400))
     138#define STM32F4_USART_1 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40011000))
     139#define STM32F4_USART_2 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40004400))
     140#define STM32F4_USART_3 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40004800))
     141#define STM32F4_USART_4 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40004c00))
     142#define STM32F4_USART_5 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40005000))
     143#define STM32F4_USART_6 ((volatile stm32f4_usart *) (STM32F4_BASE + 0x40011400))
    147144
    148145typedef struct {
     
    159156        uint32_t reserved_4001101c [249];
    160157        stm32f4_usart usart_6;
    161         uint32_t reserved_4001141c [18681];
     158        uint32_t reserved_4001141c [15097];
     159        stm32f4_gpio gpio [9];
     160        uint32_t reserved_40022400 [1280];
    162161        stm32f4_rcc rcc;
    163162} stm32f4;
  • c/src/lib/libbsp/arm/stm32f4/preinstall.am

    rb467782b r228ece9  
    106106PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/stm32f4.h
    107107
     108$(PROJECT_INCLUDE)/bsp/io.h: include/io.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
     109        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/io.h
     110PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/io.h
     111
     112$(PROJECT_INCLUDE)/bsp/rcc.h: include/rcc.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
     113        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/rcc.h
     114PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/rcc.h
     115
Note: See TracChangeset for help on using the changeset viewer.