@@ -87,29 +87,72 @@ mod app {
87
87
] ;
88
88
let mut flash = dp. FLASH . constrain ( ) ;
89
89
let mut flash_writer = flash. writer :: < 2048 > ( FlashSize :: Sz256K ) ;
90
- const FLASH_SPACING : usize = 16 ; // Separate flash writes by 16 bytes
90
+ const FLASH_SPACING : u32 = 16 ; // Separate flash writes by 16 bytes
91
91
92
92
flash_writer. erase ( 0x1FC00 , 128 ) . unwrap ( ) ; // Erase entire page
93
93
94
94
for i in 0 ..6 {
95
95
match i {
96
- 0 => flash_writer
97
- . write ( 0x1FC00 + i * FLASH_SPACING , & one_byte)
98
- . unwrap ( ) ,
99
- 1 => flash_writer
100
- . write ( 0x1FC00 + i * FLASH_SPACING , & two_bytes)
101
- . unwrap ( ) ,
102
- 2 => flash_writer
103
- . write ( 0x1FC00 + i * FLASH_SPACING , & three_bytes)
104
- . unwrap ( ) ,
105
- 3 => flash_writer
106
- . write ( 0x1FC00 + i * FLASH_SPACING , & four_bytes)
107
- . unwrap ( ) ,
96
+ 0 => {
97
+ // This test should fail, as the data needs to be divisible by 8 and force padding is false
98
+ let result = flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & one_byte, false ) ;
99
+ assert ! ( result. is_err( ) ) ;
100
+ assert_eq ! (
101
+ result. err( ) . unwrap( ) ,
102
+ stm32g4xx_hal:: flash:: Error :: ArrayMustBeDivisibleBy8
103
+ ) ;
104
+
105
+ // This test should pass, as the data needs to be divisible by 8 and force padding is true, so the one_byte array will be padded with 7 bytes of 0xFF
106
+ let result = flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & one_byte, true ) ;
107
+ assert ! ( result. is_ok( ) ) ;
108
+ }
109
+ 1 => {
110
+ // This test should fail, as the data needs to be divisible by 8 and force padding is false
111
+ let result = flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & two_bytes, false ) ;
112
+ assert ! ( result. is_err( ) ) ;
113
+ assert_eq ! (
114
+ result. err( ) . unwrap( ) ,
115
+ stm32g4xx_hal:: flash:: Error :: ArrayMustBeDivisibleBy8
116
+ ) ;
117
+
118
+ // This test should pass, as the data needs to be divisible by 8 and force padding is true, so the one_byte array will be padded with 7 bytes of 0xFF
119
+ let result = flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & two_bytes, true ) ;
120
+ assert ! ( result. is_ok( ) ) ;
121
+ }
122
+ 2 => {
123
+ // This test should fail, as the data needs to be divisible by 8 and force padding is false
124
+ let result =
125
+ flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & three_bytes, false ) ;
126
+ assert ! ( result. is_err( ) ) ;
127
+ assert_eq ! (
128
+ result. err( ) . unwrap( ) ,
129
+ stm32g4xx_hal:: flash:: Error :: ArrayMustBeDivisibleBy8
130
+ ) ;
131
+
132
+ // This test should pass, as the data needs to be divisible by 8 and force padding is true, so the one_byte array will be padded with 7 bytes of 0xFF
133
+ let result =
134
+ flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & three_bytes, true ) ;
135
+ assert ! ( result. is_ok( ) ) ;
136
+ }
137
+ 3 => {
138
+ // This test should fail, as the data needs to be divisible by 8 and force padding is false
139
+ let result =
140
+ flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & four_bytes, false ) ;
141
+ assert ! ( result. is_err( ) ) ;
142
+ assert_eq ! (
143
+ result. err( ) . unwrap( ) ,
144
+ stm32g4xx_hal:: flash:: Error :: ArrayMustBeDivisibleBy8
145
+ ) ;
146
+
147
+ // This test should pass, as the data needs to be divisible by 8 and force padding is true, so the one_byte array will be padded with 7 bytes of 0xFF
148
+ let result = flash_writer. write ( 0x1FC00 + i * FLASH_SPACING , & four_bytes, true ) ;
149
+ assert ! ( result. is_ok( ) ) ;
150
+ }
108
151
4 => flash_writer
109
- . write ( 0x1FC00 + i * FLASH_SPACING , & eight_bytes)
152
+ . write ( 0x1FC00 + i * FLASH_SPACING , & eight_bytes, false )
110
153
. unwrap ( ) ,
111
154
5 => flash_writer
112
- . write ( 0x1FC00 + i * 16 , & sixteen_bytes)
155
+ . write ( 0x1FC00 + i * 16 , & sixteen_bytes, false )
113
156
. unwrap ( ) ,
114
157
_ => ( ) ,
115
158
}
0 commit comments