2
2
3
3
use core:: marker:: PhantomData ;
4
4
5
- use crate :: stm32 :: { EXTI , SYSCFG } ;
5
+ use crate :: pac :: { EXTI , SYSCFG } ;
6
6
7
7
/// Extension trait to split a GPIO peripheral in independent pins and registers
8
8
pub trait GpioExt {
@@ -236,7 +236,7 @@ macro_rules! exti {
236
236
}
237
237
238
238
macro_rules! gpio {
239
- ( $GPIOX: ident, $gpiox: ident, $iopxenr : ident , $PXx: ident, $extigpionr: expr, [
239
+ ( $GPIOX: ident, $gpiox: ident, $rcc_bit : expr , $PXx: ident, $extigpionr: expr, [
240
240
$( $PXi: ident: ( $pxi: ident, $i: expr, $MODE: ty, $exticri: ident) , ) +
241
241
] ) => {
242
242
/// GPIO
@@ -245,9 +245,9 @@ macro_rules! gpio {
245
245
use core:: convert:: Infallible ;
246
246
247
247
use embedded_hal:: digital:: v2:: { InputPin , OutputPin , StatefulOutputPin , toggleable} ;
248
- use crate :: stm32 :: $GPIOX;
248
+ use crate :: pac :: $GPIOX;
249
249
250
- use crate :: stm32 :: { RCC , EXTI , SYSCFG } ;
250
+ use crate :: { pac :: { RCC , EXTI , SYSCFG } , bb } ;
251
251
use super :: {
252
252
Alternate , AlternateOD , Floating , GpioExt , Input , OpenDrain , Output , Speed ,
253
253
PullDown , PullUp , PushPull , AF0 , AF1 , AF2 , AF3 , AF4 , AF5 , AF6 , AF7 , AF8 , AF9 , AF10 ,
@@ -266,10 +266,13 @@ macro_rules! gpio {
266
266
type Parts = Parts ;
267
267
268
268
fn split( self ) -> Parts {
269
- // NOTE( unsafe) This executes only during initialisation
270
- let rcc = unsafe { & ( * RCC :: ptr ( ) ) } ;
271
- rcc. ahb1enr . modify ( |_ , w| w . $iopxenr ( ) . set_bit ( ) ) ;
269
+ unsafe {
270
+ // NOTE(unsafe) this reference will only be used for atomic writes with no side effects.
271
+ let rcc = & ( * RCC :: ptr ( ) ) ;
272
272
273
+ // Enable clock.
274
+ bb:: set( & rcc. ahb1enr, $rcc_bit) ;
275
+ }
273
276
Parts {
274
277
$(
275
278
$pxi: $PXi { _mode: PhantomData } ,
@@ -834,7 +837,7 @@ macro_rules! gpio {
834
837
feature = "stm32f469" ,
835
838
feature = "stm32f479"
836
839
) ) ]
837
- gpio ! ( GPIOA , gpioa, gpioaen , PA , 0 , [
840
+ gpio ! ( GPIOA , gpioa, 0 , PA , 0 , [
838
841
PA0 : ( pa0, 0 , Input <Floating >, exticr1) ,
839
842
PA1 : ( pa1, 1 , Input <Floating >, exticr1) ,
840
843
PA2 : ( pa2, 2 , Input <Floating >, exticr1) ,
@@ -872,7 +875,7 @@ gpio!(GPIOA, gpioa, gpioaen, PA, 0, [
872
875
feature = "stm32f469" ,
873
876
feature = "stm32f479"
874
877
) ) ]
875
- gpio ! ( GPIOB , gpiob, gpioben , PB , 1 , [
878
+ gpio ! ( GPIOB , gpiob, 1 , PB , 1 , [
876
879
PB0 : ( pb0, 0 , Input <Floating >, exticr1) ,
877
880
PB1 : ( pb1, 1 , Input <Floating >, exticr1) ,
878
881
PB2 : ( pb2, 2 , Input <Floating >, exticr1) ,
@@ -910,7 +913,7 @@ gpio!(GPIOB, gpiob, gpioben, PB, 1, [
910
913
feature = "stm32f469" ,
911
914
feature = "stm32f479"
912
915
) ) ]
913
- gpio ! ( GPIOC , gpioc, gpiocen , PC , 2 , [
916
+ gpio ! ( GPIOC , gpioc, 2 , PC , 2 , [
914
917
PC0 : ( pc0, 0 , Input <Floating >, exticr1) ,
915
918
PC1 : ( pc1, 1 , Input <Floating >, exticr1) ,
916
919
PC2 : ( pc2, 2 , Input <Floating >, exticr1) ,
@@ -947,7 +950,7 @@ gpio!(GPIOC, gpioc, gpiocen, PC, 2, [
947
950
feature = "stm32f469" ,
948
951
feature = "stm32f479"
949
952
) ) ]
950
- gpio ! ( GPIOD , gpiod, gpioden , PD , 3 , [
953
+ gpio ! ( GPIOD , gpiod, 3 , PD , 3 , [
951
954
PD0 : ( pd0, 0 , Input <Floating >, exticr1) ,
952
955
PD1 : ( pd1, 1 , Input <Floating >, exticr1) ,
953
956
PD2 : ( pd2, 2 , Input <Floating >, exticr1) ,
@@ -984,7 +987,7 @@ gpio!(GPIOD, gpiod, gpioden, PD, 3, [
984
987
feature = "stm32f469" ,
985
988
feature = "stm32f479"
986
989
) ) ]
987
- gpio ! ( GPIOE , gpioe, gpioeen , PE , 4 , [
990
+ gpio ! ( GPIOE , gpioe, 4 , PE , 4 , [
988
991
PE0 : ( pe0, 0 , Input <Floating >, exticr1) ,
989
992
PE1 : ( pe1, 1 , Input <Floating >, exticr1) ,
990
993
PE2 : ( pe2, 2 , Input <Floating >, exticr1) ,
@@ -1019,7 +1022,7 @@ gpio!(GPIOE, gpioe, gpioeen, PE, 4, [
1019
1022
feature = "stm32f469" ,
1020
1023
feature = "stm32f479"
1021
1024
) ) ]
1022
- gpio ! ( GPIOF , gpiof, gpiofen , PF , 5 , [
1025
+ gpio ! ( GPIOF , gpiof, 5 , PF , 5 , [
1023
1026
PF0 : ( pf0, 0 , Input <Floating >, exticr1) ,
1024
1027
PF1 : ( pf1, 1 , Input <Floating >, exticr1) ,
1025
1028
PF2 : ( pf2, 2 , Input <Floating >, exticr1) ,
@@ -1054,7 +1057,7 @@ gpio!(GPIOF, gpiof, gpiofen, PF, 5, [
1054
1057
feature = "stm32f469" ,
1055
1058
feature = "stm32f479"
1056
1059
) ) ]
1057
- gpio ! ( GPIOG , gpiog, gpiogen , PG , 6 , [
1060
+ gpio ! ( GPIOG , gpiog, 6 , PG , 6 , [
1058
1061
PG0 : ( pg0, 0 , Input <Floating >, exticr1) ,
1059
1062
PG1 : ( pg1, 1 , Input <Floating >, exticr1) ,
1060
1063
PG2 : ( pg2, 2 , Input <Floating >, exticr1) ,
@@ -1091,7 +1094,7 @@ gpio!(GPIOG, gpiog, gpiogen, PG, 6, [
1091
1094
feature = "stm32f469" ,
1092
1095
feature = "stm32f479"
1093
1096
) ) ]
1094
- gpio ! ( GPIOH , gpioh, gpiohen , PH , 7 , [
1097
+ gpio ! ( GPIOH , gpioh, 7 , PH , 7 , [
1095
1098
PH0 : ( ph0, 0 , Input <Floating >, exticr1) ,
1096
1099
PH1 : ( ph1, 1 , Input <Floating >, exticr1) ,
1097
1100
PH2 : ( ph2, 2 , Input <Floating >, exticr1) ,
@@ -1111,7 +1114,7 @@ gpio!(GPIOH, gpioh, gpiohen, PH, 7, [
1111
1114
] ) ;
1112
1115
1113
1116
#[ cfg( any( feature = "stm32f401" ) ) ]
1114
- gpio ! ( GPIOH , gpioh, gpiohen , PH , 7 , [
1117
+ gpio ! ( GPIOH , gpioh, 7 , PH , 7 , [
1115
1118
PH0 : ( ph0, 0 , Input <Floating >, exticr1) ,
1116
1119
PH1 : ( ph1, 1 , Input <Floating >, exticr1) ,
1117
1120
] ) ;
@@ -1128,7 +1131,7 @@ gpio!(GPIOH, gpioh, gpiohen, PH, 7, [
1128
1131
feature = "stm32f469" ,
1129
1132
feature = "stm32f479"
1130
1133
) ) ]
1131
- gpio ! ( GPIOI , gpioi, gpioien , PI , 8 , [
1134
+ gpio ! ( GPIOI , gpioi, 8 , PI , 8 , [
1132
1135
PI0 : ( pi0, 0 , Input <Floating >, exticr1) ,
1133
1136
PI1 : ( pi1, 1 , Input <Floating >, exticr1) ,
1134
1137
PI2 : ( pi2, 2 , Input <Floating >, exticr1) ,
@@ -1155,7 +1158,7 @@ gpio!(GPIOI, gpioi, gpioien, PI, 8, [
1155
1158
feature = "stm32f469" ,
1156
1159
feature = "stm32f479"
1157
1160
) ) ]
1158
- gpio ! ( GPIOJ , gpioj, gpiojen , PJ , 9 , [
1161
+ gpio ! ( GPIOJ , gpioj, 9 , PJ , 9 , [
1159
1162
PJ0 : ( pj0, 0 , Input <Floating >, exticr1) ,
1160
1163
PJ1 : ( pj1, 1 , Input <Floating >, exticr1) ,
1161
1164
PJ2 : ( pj2, 2 , Input <Floating >, exticr1) ,
@@ -1182,7 +1185,7 @@ gpio!(GPIOJ, gpioj, gpiojen, PJ, 9, [
1182
1185
feature = "stm32f469" ,
1183
1186
feature = "stm32f479"
1184
1187
) ) ]
1185
- gpio ! ( GPIOK , gpiok, gpioken , PK , 10 , [
1188
+ gpio ! ( GPIOK , gpiok, 10 , PK , 10 , [
1186
1189
PK0 : ( pk0, 0 , Input <Floating >, exticr1) ,
1187
1190
PK1 : ( pk1, 1 , Input <Floating >, exticr1) ,
1188
1191
PK2 : ( pk2, 2 , Input <Floating >, exticr1) ,
0 commit comments