@@ -172,27 +172,38 @@ static void *single_read_setup(void)
172172
173173 uart_async_test_init (idx ++ );
174174
175- memset (& tdata , 0 , sizeof (tdata ));
176- tdata .supply_second_buffer = true;
177175 uart_callback_set (uart_dev ,
178176 test_single_read_callback ,
179177 (void * ) & tdata );
180178
181179 return NULL ;
182180}
183181
184- static void tdata_check_recv_buffers (const uint8_t * tx_buf , uint32_t sent_bytes )
182+ static void tdata_check_recv_buffers (const uint8_t * tx_buf , uint32_t sent_bytes ,
183+ enum uart_config_data_bits data_bits )
185184{
186185 uint32_t recv_bytes_total ;
186+ uint8_t mask [] = {
187+ [UART_CFG_DATA_BITS_5 ] = BIT_MASK (5 ),
188+ [UART_CFG_DATA_BITS_6 ] = BIT_MASK (6 ),
189+ [UART_CFG_DATA_BITS_7 ] = BIT_MASK (7 ),
190+ [UART_CFG_DATA_BITS_8 ] = BIT_MASK (8 ),
191+ };
187192
188193 recv_bytes_total = tdata .recv_bytes_first_buffer + tdata .recv_bytes_second_buffer ;
189194 zassert_equal (recv_bytes_total , sent_bytes , "Incorrect number of bytes received" );
190195
191- zassert_equal (memcmp (tx_buf , tdata .rx_first_buffer , tdata .recv_bytes_first_buffer ), 0 ,
192- "Invalid data received in first buffer" );
193- zassert_equal (memcmp (tx_buf + tdata .recv_bytes_first_buffer , tdata .rx_second_buffer ,
194- tdata .recv_bytes_second_buffer ),
195- 0 , "Invalid data received in second buffer" );
196+ for (int i = 0 ; i < tdata .recv_bytes_first_buffer ; i ++ ) {
197+ zassert_equal (tx_buf [i ] & mask [data_bits ],
198+ tdata .rx_first_buffer [i ] & mask [data_bits ],
199+ "Invalid data received in the first buffer" );
200+ }
201+
202+ for (int i = 0 ; i < tdata .recv_bytes_second_buffer ; i ++ ) {
203+ zassert_equal (tx_buf [i + tdata .recv_bytes_first_buffer ] & mask [data_bits ],
204+ tdata .rx_second_buffer [i ] & mask [data_bits ],
205+ "Invalid data received in the second buffer" );
206+ }
196207
197208 /* check that the remaining bytes in the buffers are zero */
198209 for (int i = tdata .recv_bytes_first_buffer ; i < sizeof (tdata .rx_first_buffer ); i ++ ) {
@@ -206,11 +217,24 @@ static void tdata_check_recv_buffers(const uint8_t *tx_buf, uint32_t sent_bytes)
206217 }
207218}
208219
209- ZTEST_USER ( uart_async_single_read , test_single_read )
220+ static void single_read ( enum uart_config_data_bits data_bits )
210221{
211- /* Check also if sending from read only memory (e.g. flash) works. */
222+ struct uart_config uart_cfg ;
212223 static const uint8_t tx_buf [] = "0123456789" ;
213224 uint32_t sent_bytes = 0 ;
225+ int rv ;
226+
227+ memset (& tdata , 0 , sizeof (tdata ));
228+ tdata .supply_second_buffer = true;
229+
230+ zassert_ok (uart_config_get (uart_dev , & uart_cfg ));
231+ uart_cfg .data_bits = data_bits ;
232+ rv = uart_configure (uart_dev , & uart_cfg );
233+ if (rv == - ENOTSUP ) {
234+ /* If frame size is not supported, just continue. */
235+ return ;
236+ }
237+ zassert_ok (rv );
214238
215239 zassert_not_equal (memcmp (tx_buf , tdata .rx_first_buffer , 5 ), 0 ,
216240 "Initial buffer check failed" );
@@ -227,7 +251,7 @@ ZTEST_USER(uart_async_single_read, test_single_read)
227251 zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
228252 "Extra RX_RDY received" );
229253
230- tdata_check_recv_buffers (tx_buf , sent_bytes );
254+ tdata_check_recv_buffers (tx_buf , sent_bytes , data_bits );
231255
232256 uart_tx (uart_dev , tx_buf + sent_bytes , 5 , 100 * USEC_PER_MSEC );
233257 sent_bytes += 5 ;
@@ -244,11 +268,26 @@ ZTEST_USER(uart_async_single_read, test_single_read)
244268 zassert_equal (k_sem_take (& rx_rdy , K_MSEC (100 )), - EAGAIN ,
245269 "Extra RX_RDY received" );
246270
247- tdata_check_recv_buffers (tx_buf , sent_bytes );
271+ tdata_check_recv_buffers (tx_buf , sent_bytes , data_bits );
248272
249273 zassert_equal (tdata .tx_aborted_count , 0 , "TX aborted triggered" );
250274}
251275
276+ ZTEST_USER (uart_async_single_read , test_single_read )
277+ {
278+ /* This basic test is used also to check non-standard frame sizes.*/
279+ static const uint8_t data_bits [] = {
280+ UART_CFG_DATA_BITS_5 ,
281+ UART_CFG_DATA_BITS_6 ,
282+ UART_CFG_DATA_BITS_7 ,
283+ UART_CFG_DATA_BITS_8 ,
284+ };
285+
286+ ARRAY_FOR_EACH (data_bits , i ) {
287+ single_read (data_bits [i ]);
288+ }
289+ }
290+
252291static void * multiple_rx_enable_setup (void )
253292{
254293 static int idx ;
@@ -316,7 +355,7 @@ ZTEST_USER(uart_async_multi_rx, test_multiple_rx_enable)
316355 "RX_DISABLED timeout" );
317356 zassert_equal (tx_aborted_count , 0 , "Unexpected TX abort" );
318357
319- tdata_check_recv_buffers (tx_buf , sizeof (tx_buf ));
358+ tdata_check_recv_buffers (tx_buf , sizeof (tx_buf ), UART_CFG_DATA_BITS_8 );
320359
321360 k_sem_reset (& rx_rdy );
322361 k_sem_reset (& rx_buf_released );
@@ -345,7 +384,7 @@ ZTEST_USER(uart_async_multi_rx, test_multiple_rx_enable)
345384 "RX_DISABLED timeout" );
346385 zassert_equal (tx_aborted_count , 0 , "Unexpected TX abort" );
347386
348- tdata_check_recv_buffers (tx_buf , sizeof (tx_buf ));
387+ tdata_check_recv_buffers (tx_buf , sizeof (tx_buf ), UART_CFG_DATA_BITS_8 );
349388}
350389
351390#if NOCACHE_MEM
0 commit comments