Skip to content

Commit 9d563ae

Browse files
danielinuxdgarske
authored andcommitted
Added XMODEM update
1 parent aff2072 commit 9d563ae

6 files changed

Lines changed: 406 additions & 19 deletions

File tree

hal/stm32h5.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,23 @@ static void clock_pll_on(void)
366366
}
367367

368368
#if (TZ_SECURE())
369+
370+
#define NVIC_ISER_BASE (0xE000E100)
371+
#define NVIC_ICER_BASE (0xE000E180)
372+
#define NVIC_IPRI_BASE (0xE000E400)
373+
#define NVIC_USART3_IRQ 60
374+
375+
/* Cortex M-33 has an extra register to set up non-secure interrupts */
376+
#define NVIC_ITNS_BASE (0xE000E380)
377+
378+
379+
369380
static void periph_unsecure(void)
370381
{
371382
uint32_t pin;
372383
volatile uint32_t reg;
384+
volatile uint32_t *nvic_itns;
385+
uint32_t nvic_reg_pos, nvic_reg_off;
373386

374387
/*Enable clock for User LED GPIOs */
375388
RCC_AHB2_CLOCK_ER|= LED_AHB2_ENABLE;
@@ -412,6 +425,13 @@ static void periph_unsecure(void)
412425
TZSC_SECCFGR1 = reg;
413426
}
414427

428+
/* Set USART3 interrupt as non-secure */
429+
nvic_reg_pos = NVIC_USART3_IRQ / 32;
430+
nvic_reg_off = NVIC_USART3_IRQ % 32;
431+
nvic_itns = ((volatile uint32_t *)(NVIC_ITNS_BASE + 4 * nvic_reg_pos));
432+
*nvic_itns |= (1 << nvic_reg_off);
433+
434+
415435
/* Disable GPIOs clock used previously for accessing SECCFGR registers */
416436
#if 0
417437
RCC_AHB2_CLOCK_ER &= ~GPIOA_AHB2_CLOCK_ER;

hal/stm32h5.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#ifndef STM32H5_DEF_INCLUDED
2424
#define STM32H5_DEF_INCLUDED
2525
/* Assembly helpers */
26+
#ifndef DMB
2627
#define DMB() __asm__ volatile ("dmb")
28+
#endif
2729
#define ISB() __asm__ volatile ("isb")
2830
#define DSB() __asm__ volatile ("dsb")
2931

@@ -409,8 +411,14 @@
409411
#define UART_CR3_HDSEL (1 << 3)
410412
#define UART_CR3_DEM (1 << 14)
411413
#define UART_CR3_IREN (1 << 1)
414+
#define UART_CR3_RXFTIE (1 << 28)
412415
#define UART_ISR_TX_EMPTY (1 << 7)
413416
#define UART_ISR_RX_NOTEMPTY (1 << 5)
417+
#define UART_EPE (1 << 0) /* Parity error */
418+
#define UART_EFE (1 << 1) /* Framing error */
419+
#define UART_ENE (1 << 2) /* Noise error */
420+
#define UART_ORE (1 << 3) /* Overrun error */
421+
414422

415423

416424
/* OTP FLASH AREA */

hal/uart/uart_drv_stm32h5.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,18 @@ static int uart1_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop)
141141
return 0;
142142
}
143143

144+
static void uart1_clear_errors(void)
145+
{
146+
UART1_ICR = UART1_ISR & (UART_ENE | UART_EPE | UART_ORE | UART_EFE);
147+
}
148+
144149
static int uart1_tx(const uint8_t c)
145150
{
146151
volatile uint32_t reg;
147152
do {
148153
reg = UART1_ISR;
154+
if (reg & (UART_ENE | UART_EPE | UART_ORE | UART_EFE))
155+
uart1_clear_errors();
149156
} while ((reg & UART_ISR_TX_EMPTY) == 0);
150157
UART1_TDR = c;
151158
return 1;
@@ -156,6 +163,8 @@ static int uart1_rx(uint8_t *c)
156163
volatile uint32_t reg;
157164
int i = 0;
158165
reg = UART1_ISR;
166+
if (reg & (UART_ENE | UART_EPE | UART_ORE | UART_EFE))
167+
uart1_clear_errors();
159168
if (reg & UART_ISR_RX_NOTEMPTY) {
160169
*c = (uint8_t)UART1_RDR;
161170
return 1;
@@ -209,11 +218,18 @@ static int uart3_init(uint32_t bitrate, uint8_t data, char parity, uint8_t stop)
209218
return 0;
210219
}
211220

221+
static void uart3_clear_errors(void)
222+
{
223+
UART3_ICR = UART3_ISR & (UART_ENE | UART_EPE | UART_ORE | UART_EFE);
224+
}
225+
212226
static int uart3_tx(const uint8_t c)
213227
{
214228
volatile uint32_t reg;
215229
do {
216230
reg = UART3_ISR;
231+
if (reg & (UART_ENE | UART_EPE | UART_ORE | UART_EFE))
232+
uart3_clear_errors();
217233
} while ((reg & UART_ISR_TX_EMPTY) == 0);
218234
UART3_TDR = c;
219235
return 1;
@@ -224,6 +240,8 @@ static int uart3_rx(uint8_t *c)
224240
volatile uint32_t reg;
225241
int i = 0;
226242
reg = UART3_ISR;
243+
if (reg & (UART_ENE | UART_EPE | UART_ORE | UART_EFE))
244+
uart3_clear_errors();
227245
if (reg & UART_ISR_RX_NOTEMPTY) {
228246
*c = (uint8_t)UART3_RDR;
229247
return 1;

0 commit comments

Comments
 (0)