Changeset 7be19f8 in rtems


Ignore:
Timestamp:
Apr 15, 2012, 7:15:22 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
c050143
Parents:
bce41f4
git-author:
Sebastian Huber <sebastian.huber@…> (04/15/12 19:15:22)
git-committer:
Sebastian Huber <sebastian.huber@…> (04/15/12 19:47:43)
Message:

bsp/stm32f4: API changes

Location:
c/src/lib/libbsp/arm/stm32f4
Files:
1 added
8 edited

Legend:

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

    rbce41f4 r7be19f8  
    8080libbsp_a_SOURCES += startup/io.c
    8181libbsp_a_SOURCES += startup/rcc.c
     82libbsp_a_SOURCES += startup/start-config-io.c
    8283
    8384# IRQ
  • c/src/lib/libbsp/arm/stm32f4/configure.ac

    rbce41f4 r7be19f8  
    3636RTEMS_BSPOPTS_HELP([STM32F4_USART_BAUD],[baud for USARTs])
    3737
    38 RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_1],[*],[1])
     38RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_1],[*],[])
    3939RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_1],[enable USART 1])
    4040
     
    4242RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_2],[enable USART 2])
    4343
    44 RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_3],[*],[])
     44RTEMS_BSPOPTS_SET([STM32F4_ENABLE_USART_3],[*],[1])
    4545RTEMS_BSPOPTS_HELP([STM32F4_ENABLE_USART_3],[enable USART 3])
    4646
  • c/src/lib/libbsp/arm/stm32f4/console/usart.c

    rbce41f4 r7be19f8  
    119119}
    120120
    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 
    131 static 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 
    153 static 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 
    163121static void usart_initialize(int minor)
    164122{
     
    170128
    171129  stm32f4_rcc_set_clock(rcc_index, true);
    172   usart_set_gpio_config(ct);
    173130
    174131  usart->cr1 = 0;
  • c/src/lib/libbsp/arm/stm32f4/include/io.h

    rbce41f4 r7be19f8  
    9393#define STM32F4_GPIO_INDEX_OF_PIN(pin) ((pin) & 0xf)
    9494
    95 typedef struct {
    96   uint32_t pin : 8;
    97   uint32_t mode : 2;
    98   uint32_t otype : 1;
    99   uint32_t ospeed : 2;
    100   uint32_t pupd : 2;
    101   uint32_t af : 4;
     95typedef union {
     96  struct {
     97    uint32_t pin_first : 8;
     98    uint32_t pin_last : 8;
     99    uint32_t mode : 2;
     100    uint32_t otype : 1;
     101    uint32_t ospeed : 2;
     102    uint32_t pupd : 2;
     103    uint32_t output : 1;
     104    uint32_t af : 4;
     105    uint32_t reserved : 4;
     106  } fields;
     107
     108  uint32_t value;
    102109} stm32f4_gpio_config;
    103110
     111extern const stm32f4_gpio_config stm32f4_start_config_gpio [];
     112
     113void stm32f4_gpio_set_clock(int pin, bool set);
     114
    104115void stm32f4_gpio_set_config(const stm32f4_gpio_config *config);
     116
     117#define STM32F4_GPIO_CONFIG_TERMINAL \
     118  { { 0xff, 0xff, 0x3, 0x1, 0x3, 0x3, 0x1, 0xf, 0xf } }
     119
     120/**
     121 * @brief Sets the GPIO configuration of an array terminated by
     122 * STM32F4_GPIO_CONFIG_TERMINAL.
     123 */
     124void stm32f4_gpio_set_config_array(const stm32f4_gpio_config *configs);
    105125
    106126void stm32f4_gpio_set_output(int pin, bool set);
    107127
    108128bool stm32f4_gpio_get_input(int pin);
     129
     130#define STM32F4_PIN_USART(port, idx, altfunc) \
     131  { \
     132    { \
     133      .pin_first = STM32F4_GPIO_PIN(port, idx), \
     134      .pin_last = STM32F4_GPIO_PIN(port, idx), \
     135      .mode = STM32F4_GPIO_MODE_AF, \
     136      .otype = STM32F4_GPIO_OTYPE_PUSH_PULL, \
     137      .ospeed = STM32F4_GPIO_OSPEED_2_MHZ, \
     138      .pupd = STM32F4_GPIO_PULL_UP, \
     139      .af = altfunc \
     140    } \
     141  }
     142
     143#define STM32F4_PIN_USART1_TX_PA9 STM32F4_PIN_USART(0, 9, STM32F4_GPIO_AF_USART1)
     144#define STM32F4_PIN_USART1_TX_PB6 STM32F4_PIN_USART(1, 6, STM32F4_GPIO_AF_USART1)
     145#define STM32F4_PIN_USART1_RX_PA10 STM32F4_PIN_USART(0, 10, STM32F4_GPIO_AF_USART1)
     146#define STM32F4_PIN_USART1_RX_PB7 STM32F4_PIN_USART(1, 7, STM32F4_GPIO_AF_USART1)
     147
     148#define STM32F4_PIN_USART2_TX_PA2 STM32F4_PIN_USART(0, 2, STM32F4_GPIO_AF_USART2)
     149#define STM32F4_PIN_USART2_TX_PD5 STM32F4_PIN_USART(3, 5, STM32F4_GPIO_AF_USART2)
     150#define STM32F4_PIN_USART2_RX_PA3 STM32F4_PIN_USART(0, 3, STM32F4_GPIO_AF_USART2)
     151#define STM32F4_PIN_USART2_RX_PD6 STM32F4_PIN_USART(3, 6, STM32F4_GPIO_AF_USART2)
     152
     153#define STM32F4_PIN_USART3_TX_PC10 STM32F4_PIN_USART(2, 10, STM32F4_GPIO_AF_USART3)
     154#define STM32F4_PIN_USART3_TX_PD8 STM32F4_PIN_USART(3, 8, STM32F4_GPIO_AF_USART3)
     155#define STM32F4_PIN_USART3_RX_PC11 STM32F4_PIN_USART(2, 11, STM32F4_GPIO_AF_USART3)
     156#define STM32F4_PIN_USART3_RX_PD9 STM32F4_PIN_USART(3, 9, STM32F4_GPIO_AF_USART3)
     157
     158#define STM32F4_PIN_UART4_TX_PA0 STM32F4_PIN_USART(0, 0, STM32F4_GPIO_AF_UART4)
     159#define STM32F4_PIN_UART4_TX_PC10 STM32F4_PIN_USART(2, 10, STM32F4_GPIO_AF_UART4)
     160#define STM32F4_PIN_UART4_RX_PA1 STM32F4_PIN_USART(0, 1, STM32F4_GPIO_AF_UART4)
     161#define STM32F4_PIN_UART4_RX_PC11 STM32F4_PIN_USART(2, 11, STM32F4_GPIO_AF_UART4)
     162
     163#define STM32F4_PIN_UART5_TX_PC12 STM32F4_PIN_USART(2, 12, STM32F4_GPIO_AF_UART5)
     164#define STM32F4_PIN_UART5_RX_PD2 STM32F4_PIN_USART(3, 2, STM32F4_GPIO_AF_UART5)
     165
     166#define STM32F4_PIN_USART6_TX_PC6 STM32F4_PIN_USART(2, 6, STM32F4_GPIO_AF_USART6)
     167#define STM32F4_PIN_USART6_RX_PC7 STM32F4_PIN_USART(2, 7, STM32F4_GPIO_AF_USART6)
    109168
    110169#ifdef __cplusplus
  • c/src/lib/libbsp/arm/stm32f4/include/rcc.h

    rbce41f4 r7be19f8  
    8989} stm32f4_rcc_index;
    9090
    91 void stm32f4_rcc_reset(stm32f4_rcc_index index, bool set);
     91void stm32f4_rcc_reset(stm32f4_rcc_index index);
     92
     93void stm32f4_rcc_set_reset(stm32f4_rcc_index index, bool set);
    9294
    9395void stm32f4_rcc_set_clock(stm32f4_rcc_index index, bool set);
    94 
    95 void stm32f4_rcc_set_gpio_clock(int pin, bool set);
    9696
    9797void stm32f4_rcc_set_low_power_clock(stm32f4_rcc_index index, bool set);
  • c/src/lib/libbsp/arm/stm32f4/startup/bspstart.c

    rbce41f4 r7be19f8  
    1414
    1515#include <bsp.h>
     16#include <bsp/io.h>
     17#include <bsp/irq.h>
    1618#include <bsp/bootcard.h>
    1719#include <bsp/irq-generic.h>
    18 #include <bsp/irq.h>
    19 #include <bsp/linker-symbols.h>
    2020
    2121void bsp_start(void)
    2222{
     23  stm32f4_gpio_set_config_array(&stm32f4_start_config_gpio [0]);
     24
    2325  if (bsp_interrupt_initialize() != RTEMS_SUCCESSFUL) {
    2426    _CPU_Fatal_halt(0xe);
  • c/src/lib/libbsp/arm/stm32f4/startup/io.c

    rbce41f4 r7be19f8  
    1414
    1515#include <bsp/io.h>
     16#include <bsp/rcc.h>
    1617
    1718#include <rtems.h>
     19
     20RTEMS_STATIC_ASSERT(sizeof(stm32f4_gpio_config) == 4, size_of_config);
     21
     22void stm32f4_gpio_set_clock(int pin, bool set)
     23{
     24  int port = STM32F4_GPIO_PORT_OF_PIN(pin);
     25  stm32f4_rcc_index index = STM32F4_RCC_GPIOA + port;
     26
     27  stm32f4_rcc_set_clock(index, set);
     28}
    1829
    1930static void clear_and_set(
     
    2435)
    2536{
    26   uint32_t one = 1;
    27   uint32_t mask = (one << width) - one;
     37  uint32_t mask = (1U << width) - 1U;
    2838  unsigned shift = width * index;
    2939  uint32_t val = *reg;
     
    3545}
    3646
    37 void stm32f4_gpio_set_config(const stm32f4_gpio_config *config)
     47static void set_config(unsigned pin, const stm32f4_gpio_config *config)
    3848{
    39   unsigned pin = config->pin;
    4049  unsigned port = STM32F4_GPIO_PORT_OF_PIN(pin);
    4150  volatile stm32f4_gpio *gpio = STM32F4_GPIO(port);
    4251  unsigned index = STM32F4_GPIO_INDEX_OF_PIN(pin);
    43   unsigned af_reg = index >> 8;
    44   unsigned af_index = index & 0x3;
     52  unsigned af_reg = index >> 3;
     53  unsigned af_index = index & 0x7;
     54  int set_or_clear_offset = config->fields.output ? 0 : 16;
    4555  rtems_interrupt_level level;
    4656
    4757  rtems_interrupt_disable(level);
    48   clear_and_set(&gpio->moder, index, 2, config->mode);
    49   clear_and_set(&gpio->afr [af_reg], af_index, 4, config->af);
    50   clear_and_set(&gpio->pupdr, index, 2, config->pupd);
    51   clear_and_set(&gpio->otyper, index, 1, config->otype);
    52   clear_and_set(&gpio->ospeedr, index, 2, config->ospeed);
     58  gpio->bsrr = 1U << (index + set_or_clear_offset);
     59  clear_and_set(&gpio->pupdr, index, 2, config->fields.pupd);
     60  clear_and_set(&gpio->otyper, index, 1, config->fields.otype);
     61  clear_and_set(&gpio->ospeedr, index, 2, config->fields.ospeed);
     62  clear_and_set(&gpio->afr [af_reg], af_index, 4, config->fields.af);
     63  clear_and_set(&gpio->moder, index, 2, config->fields.mode);
    5364  rtems_interrupt_enable(level);
     65}
     66
     67void stm32f4_gpio_set_config(const stm32f4_gpio_config *config)
     68{
     69  int current = config->fields.pin_first;
     70  int last = config->fields.pin_last;
     71
     72  while (current <= last) {
     73    stm32f4_gpio_set_clock(current, true);
     74    set_config(current, config);
     75    ++current;
     76  }
     77}
     78
     79void stm32f4_gpio_set_config_array(const stm32f4_gpio_config *configs)
     80{
     81  stm32f4_gpio_config terminal = STM32F4_GPIO_CONFIG_TERMINAL;
     82
     83  while (configs->value != terminal.value) {
     84    stm32f4_gpio_set_config(configs);
     85    ++configs;
     86  }
    5487}
    5588
     
    5992  volatile stm32f4_gpio *gpio = STM32F4_GPIO(port);
    6093  int index = STM32F4_GPIO_INDEX_OF_PIN(pin);
    61   int offset = set ? 0 : 16;
    62   uint32_t one = 1;
     94  int set_or_clear_offset = set ? 0 : 16;
    6395
    64   gpio->bsrr = one << (index + offset);
     96  gpio->bsrr = 1U << (index + set_or_clear_offset);
    6597}
    6698
     
    70102  volatile stm32f4_gpio *gpio = STM32F4_GPIO(port);
    71103  int index = STM32F4_GPIO_INDEX_OF_PIN(pin);
    72   uint32_t one = 1;
    73104
    74   return (gpio->idr & (one << index)) != 0;
     105  return (gpio->idr & (1U << index)) != 0;
    75106}
  • c/src/lib/libbsp/arm/stm32f4/startup/rcc.c

    rbce41f4 r7be19f8  
    1414
    1515#include <bsp/rcc.h>
    16 #include <bsp/io.h>
    1716
    1817#include <rtems.h>
     
    4140}
    4241
    43 void stm32f4_rcc_reset(stm32f4_rcc_index index, bool set)
     42void stm32f4_rcc_reset(stm32f4_rcc_index index)
     43{
     44  stm32f4_rcc_set_reset(index, true);
     45  stm32f4_rcc_set_reset(index, false);
     46}
     47
     48void stm32f4_rcc_set_reset(stm32f4_rcc_index index, bool set)
    4449{
    4550  volatile stm32f4_rcc *rcc = STM32F4_RCC;
     
    5560}
    5661
    57 void stm32f4_rcc_set_gpio_clock(int pin, bool set)
    58 {
    59   int port = STM32F4_GPIO_PORT_OF_PIN(pin);
    60   stm32f4_rcc_index index = STM32F4_RCC_GPIOA + port;
    61 
    62   stm32f4_rcc_set_clock(index, set);
    63 }
    64 
    6562void stm32f4_rcc_set_low_power_clock(stm32f4_rcc_index index, bool set)
    6663{
Note: See TracChangeset for help on using the changeset viewer.