Blame view

RIOT/cpu/stm32_common/cpu_common.c 2.35 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
  /*
   * Copyright (C) 2016 Freie Universitรคt Berlin
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     cpu_cortexm_common
   * @{
   *
   * @file
   * @brief       Shared CPU specific function for the STM32 CPU family
   *
   * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
   *
   * @}
   */
  
  #include "periph_conf.h"
  #include "periph_cpu_common.h"
  
  #define ENABLE_DEBUG (0)
  #include "debug.h"
  
  uint32_t periph_apb_clk(uint8_t bus)
  {
      if (bus == APB1) {
          return CLOCK_APB1;
      }
      else {
          return CLOCK_APB2;
      }
  }
  
  void periph_clk_en(bus_t bus, uint32_t mask)
  {
      switch (bus) {
          case APB1:
              RCC->APB1ENR |= mask;
              break;
          case APB2:
              RCC->APB2ENR |= mask;
              break;
  #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) || defined(CPU_FAM_STM32F1) \
              || defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3)
          case AHB:
              RCC->AHBENR |= mask;
              break;
  #elif defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)
          case AHB1:
              RCC->AHB1ENR |= mask;
              break;
          case AHB2:
              RCC->AHB2ENR |= mask;
              break;
          case AHB3:
              RCC->AHB3ENR |= mask;
              break;
  #endif
          default:
              DEBUG("unsupported bus %d\n", (int)bus);
              break;
      }
      /* stm32xx-errata: Delay after a RCC peripheral clock enable */
      __DSB();
  }
  
  void periph_clk_dis(bus_t bus, uint32_t mask)
  {
      switch (bus) {
          case APB1:
              RCC->APB1ENR &= ~(mask);
              break;
          case APB2:
              RCC->APB2ENR &= ~(mask);
              break;
  #if defined(CPU_FAM_STM32L0) || defined(CPU_FAM_STM32L1) || defined(CPU_FAM_STM32F1) \
              || defined(CPU_FAM_STM32F0) || defined(CPU_FAM_STM32F3)
          case AHB:
              RCC->AHBENR &= ~(mask);
              break;
  #elif defined(CPU_FAM_STM32F2) || defined(CPU_FAM_STM32F4)
          case AHB1:
              RCC->AHB1ENR &= ~(mask);
              break;
          case AHB2:
              RCC->AHB2ENR &= ~(mask);
              break;
          case AHB3:
              RCC->AHB3ENR &= ~(mask);
              break;
  #endif
          default:
              DEBUG("unsupported bus %d\n", (int)bus);
              break;
      }
  }