質問編集履歴

3

コードの修正

2020/07/05 06:56

投稿

taga
taga

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  構造体のメンバに数値を代入しようしたのですが、
2
2
 
3
- エラー(Invalid memory reference)が出てしまします。
3
+ エラー(Invalid memory reference)が出てしまします。
4
4
 
5
5
  なぜでしょうか?
6
6
 
@@ -74,7 +74,7 @@
74
74
 
75
75
 
76
76
 
77
- RCC->CR = (uint32_t)0x0C;
77
+ RCC->CR = (uint32_t)0x0C; <--エラー発生(Invalid memory reference)
78
78
 
79
79
  }
80
80
 

2

コードの修正

2020/07/05 06:56

投稿

taga
taga

スコア8

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  構造体のメンバに数値を代入しようしたのですが、
2
2
 
3
- エラー(30行目:Invalid memory reference)が出てしまします。
3
+ エラー(:Invalid memory reference)が出てしまします。
4
4
 
5
5
  なぜでしょうか?
6
6
 
@@ -8,66 +8,74 @@
8
8
 
9
9
  ```c言語
10
10
 
11
- 1 int main(void){
11
+ #include <iostream>
12
12
 
13
- 2 // Your code here!
13
+ #include <stdint.h>
14
14
 
15
- 3 #define __IO volatile /*!< Defines 'read / write' permissions */
16
15
 
17
- 4
18
16
 
19
- 5 typedef struct
17
+ using namespace std;
20
18
 
21
- 6 {
19
+ int main(void){
22
20
 
23
- 7 __IO uint32_t CR ; /*!< RCC clock control register, Address offset: 0x00 */
21
+ // Your code here!
24
22
 
25
- 8 __IO uint32_t CFGR; /*!< RCC clock configuration register, Address offset: 0x04 */
23
+ #define __IO volatile /*!< Defines 'read / write' permissions */
26
24
 
27
- 9 __IO uint32_t CIR; /*!< RCC clock interrupt register, Address offset: 0x08 */
25
+
28
26
 
29
- 10 __IO uint32_t APB2RSTR; /*!< RCC APB2 peripheral reset register, Address offset: 0x0C */
27
+ typedef struct
30
28
 
31
- 11 __IO uint32_t APB1RSTR; /*!< RCC APB1 peripheral reset register, Address offset: 0x10 */
29
+ {
32
30
 
33
- 12 __IO uint32_t AHBENR; /*!< RCC AHB peripheral clock register, Address offset: 0x14 */
31
+ __IO uint32_t CR ; /*!< RCC clock control register, Address offset: 0x00 */
34
32
 
35
- 13 __IO uint32_t APB2ENR; /*!< RCC APB2 peripheral clock enable register, Address offset: 0x18 */
33
+ __IO uint32_t CFGR; /*!< RCC clock configuration register, Address offset: 0x04 */
36
34
 
37
- 14 __IO uint32_t APB1ENR; /*!< RCC APB1 peripheral clock enable register, Address offset: 0x1C */
35
+ __IO uint32_t CIR; /*!< RCC clock interrupt register, Address offset: 0x08 */
38
36
 
39
- 15 __IO uint32_t BDCR; /*!< RCC Backup domain control register, Address offset: 0x20 */
37
+ __IO uint32_t APB2RSTR; /*!< RCC APB2 peripheral reset register, Address offset: 0x0C */
40
38
 
41
- 16 __IO uint32_t CSR; /*!< RCC clock control & status register, Address offset: 0x24 */
39
+ __IO uint32_t APB1RSTR; /*!< RCC APB1 peripheral reset register, Address offset: 0x10 */
42
40
 
43
- 17 __IO uint32_t AHBRSTR; /*!< RCC AHB peripheral reset register, Address offset: 0x28 */
41
+ __IO uint32_t AHBENR; /*!< RCC AHB peripheral clock register, Address offset: 0x14 */
44
42
 
45
- 18 __IO uint32_t CFGR2; /*!< RCC clock configuration register 2, Address offset: 0x2C */
43
+ __IO uint32_t APB2ENR; /*!< RCC APB2 peripheral clock enable register, Address offset: 0x18 */
46
44
 
47
- 19 __IO uint32_t CFGR3; /*!< RCC clock configuration register 3, Address offset: 0x30 */
45
+ __IO uint32_t APB1ENR; /*!< RCC APB1 peripheral clock enable register, Address offset: 0x1C */
48
46
 
49
- 20 __IO uint32_t CR2; /*!< RCC clock control register 2, Address offset: 0x34 */
47
+ __IO uint32_t BDCR; /*!< RCC Backup domain control register, Address offset: 0x20 */
50
48
 
51
- 21 } RCC_TypeDef;
49
+ __IO uint32_t CSR; /*!< RCC clock control & status register, Address offset: 0x24 */
52
50
 
53
- 22
51
+ __IO uint32_t AHBRSTR; /*!< RCC AHB peripheral reset register, Address offset: 0x28 */
54
52
 
55
- 23 #define PI (uint32_t)0x40000000
53
+ __IO uint32_t CFGR2; /*!< RCC clock configuration register 2, Address offset: 0x2C */
56
54
 
57
- 24 #define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */
55
+ __IO uint32_t CFGR3; /*!< RCC clock configuration register 3, Address offset: 0x30 */
58
56
 
59
- 25 #define AHBPERIPH_BASE (PERIPH_BASE + 0x00020000)
57
+ __IO uint32_t CR2; /*!< RCC clock control register 2, Address offset: 0x34 */
60
58
 
61
- 26 #define RCC_BASE (AHBPERIPH_BASE + 0x00001000)
59
+ } RCC_TypeDef;
62
60
 
63
- 27
64
61
 
65
- 28 #define RCC ((RCC_TypeDef *) RCC_BASE)
66
62
 
67
- 29
63
+ #define PI (uint32_t)0x40000000
68
64
 
69
- 30 RCC->CR = (uint32_t)0x0C; <--エラー発生(Invalid memory reference)
65
+ #define PERIPH_BASE ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */
70
66
 
67
+ #define AHBPERIPH_BASE (PERIPH_BASE + 0x00020000)
68
+
69
+ #define RCC_BASE (AHBPERIPH_BASE + 0x00001000)
70
+
71
+
72
+
73
+ #define RCC ((RCC_TypeDef *) RCC_BASE)
74
+
75
+
76
+
77
+ RCC->CR = (uint32_t)0x0C;
78
+
71
- 31}
79
+ }
72
80
 
73
81
  ```

1

コード修正

2020/07/05 06:54

投稿

taga
taga

スコア8

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,8 @@
5
5
  なぜでしょうか?
6
6
 
7
7
 
8
+
9
+ ```c言語
8
10
 
9
11
  1 int main(void){
10
12
 
@@ -67,3 +69,5 @@
67
69
  30 RCC->CR = (uint32_t)0x0C; <--エラー発生(Invalid memory reference)
68
70
 
69
71
  31}
72
+
73
+ ```