2222#ifdef TARGET_nrf54l
2323
2424#include <stdint.h>
25+ #include <inttypes.h>
2526
2627#include <string.h>
2728
@@ -67,8 +68,8 @@ static void uart_init_device(int device, uint32_t bitrate, uint8_t data, char pa
6768 ((port << UART_PSEL_RXD_PORT_Pos ) & UART_PSEL_RXD_PORT_Msk );
6869 UART_PSEL_CTS (device ) = UART_PSEL_CTS_CONNECT_Disconnected ;
6970 UART_PSEL_RTS (device ) = UART_PSEL_RTS_CONNECT_Disconnected ;
70- UART_BAUDRATE (device ) = UART_BAUDRATE_BAUDRATE_Baud115200 ;
71- UART_CONFIG (device ) = UART_CONFIG_8N1 ; /* 8N1, no HW flow control */
71+ UART_BAUDRATE (device ) = UART_BAUDRATE_VALUE ( bitrate ) ;
72+ UART_CONFIG (device ) = UART_CONFIG_VALUE ( data , parity , stop );
7273
7374 UART_ENABLE (device ) = UART_ENABLE_ENABLE_Enabled ;
7475}
@@ -99,6 +100,12 @@ void uart_write_raw(int device, const char* buffer, unsigned int sz)
99100 (UART_EVENTS_DMA_TX_BUSERROR (device ) == 0 ))
100101 ;
101102
103+ if (UART_EVENTS_DMA_TX_BUSERROR (device ) != 0 ) {
104+ UART_TASKS_DMA_TX_STOP (device ) =
105+ UART_TASKS_DMA_TX_STOP_STOP_Trigger ;
106+ break ;
107+ }
108+
102109 sz -= xfer ;
103110 buffer += xfer ;
104111 }
@@ -109,13 +116,18 @@ void uart_write_device(int device, const char* buf, unsigned int sz)
109116 static char buffer [UART_WRITE_BUF_SIZE ];
110117 int bufsz = 0 ;
111118
112- for (int i = 0 ; i < (int )sz && bufsz < UART_WRITE_BUF_SIZE ; i ++ )
113- {
119+ for (int i = 0 ; i < (int )sz && bufsz < UART_WRITE_BUF_SIZE ; i ++ ) {
114120 char ch = (char ) buf [i ];
115- if (ch == '\r' )
121+
122+ if (ch == '\r' )
116123 continue ;
117- if (ch == '\n' )
124+
125+ if (ch == '\n' ) {
126+ if (bufsz >= (UART_WRITE_BUF_SIZE - 1 ))
127+ break ;
128+
118129 buffer [bufsz ++ ] = '\r' ;
130+ }
119131 buffer [bufsz ++ ] = ch ;
120132 }
121133 uart_write_raw (device , buffer , bufsz );
@@ -299,6 +311,9 @@ void uart_init(void)
299311static uintptr_t ext_flash_addr_calc (uintptr_t address )
300312{
301313 /* offset external flash addresses by the update partition address */
314+ if (address < WOLFBOOT_PARTITION_UPDATE_ADDRESS ) {
315+ return 0 ;
316+ }
302317 address -= WOLFBOOT_PARTITION_UPDATE_ADDRESS ;
303318 return address ;
304319}
@@ -307,7 +322,8 @@ int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
307322{
308323#ifdef DEBUG_FLASH
309324 uintptr_t addr = ext_flash_addr_calc (address );
310- wolfBoot_printf ("Ext Write: Len %d, Addr 0x%x (off 0x%x) -> 0x%x\n" ,
325+ wolfBoot_printf ("Ext Write: Len %d, Addr 0x%" PRIxPTR " (off 0x%" PRIxPTR
326+ ") -> %p\n" ,
311327 len , address , addr , data );
312328#endif
313329 return 0 ;
@@ -317,7 +333,8 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)
317333{
318334#ifdef DEBUG_FLASH
319335 uintptr_t addr = ext_flash_addr_calc (address );
320- wolfBoot_printf ("Ext Read: Len %d, Addr 0x%x (off 0x%x) -> %p\n" ,
336+ wolfBoot_printf ("Ext Read: Len %d, Addr 0x%" PRIxPTR " (off 0x%" PRIxPTR
337+ ") -> %p\n" ,
321338 len , address , addr , data );
322339#endif
323340 memset (data , FLASH_BYTE_ERASED , len );
@@ -328,7 +345,8 @@ int ext_flash_erase(uintptr_t address, int len)
328345{
329346#ifdef DEBUG_FLASH
330347 uintptr_t addr = ext_flash_addr_calc (address );
331- wolfBoot_printf ("Ext Erase: Len %d, Addr 0x%x (off 0x%x)\n" ,
348+ wolfBoot_printf ("Ext Erase: Len %d, Addr 0x%" PRIxPTR " (off 0x%" PRIxPTR
349+ ")\n" ,
332350 len , address , addr );
333351#endif
334352 return 0 ;
0 commit comments