Skip to content

Commit

Permalink
fixed UART
Browse files Browse the repository at this point in the history
  • Loading branch information
robert committed Apr 8, 2024
1 parent 625a426 commit 79669dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 7 additions & 4 deletions examples/infineon/infineon-xmc7200/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,15 @@ static inline void uart_init(volatile CySCB_Type *uart, unsigned long baud) {
if (div == 0) div = 1;
frac = SYS_FREQUENCY % (baud * ovs);
frac = (frac * 100) / (baud * ovs);
PERI_PCLK->GR[1].DIV_CMD = (3 << PERI_PCLK_GR_DIV_CMD_TYPE_SEL_Pos);
PERI_PCLK->GR[1].DIV_CMD = (3 << PERI_PCLK_GR_DIV_CMD_TYPE_SEL_Pos) |
PERI_PCLK_GR_DIV_CMD_PA_DIV_SEL_Msk |
PERI_PCLK_GR_DIV_CMD_PA_TYPE_SEL_Msk;
PERI_PCLK->GR[1].DIV_CMD |= PERI_PCLK_GR_DIV_CMD_DISABLE_Msk; // disable divider
PERI_PCLK->GR[1].DIV_24_5_CTL[0] = (((uint8_t) (div - 1)) << PERI_PCLK_GR_DIV_24_5_CTL_INT24_DIV_Pos) |
(frac << PERI_PCLK_GR_DIV_24_5_CTL_FRAC5_DIV_Pos);
PERI_PCLK->GR[1].DIV_CMD = (3 << PERI_PCLK_GR_DIV_CMD_TYPE_SEL_Pos);
PERI_PCLK->GR[1].DIV_CMD = (3 << PERI_PCLK_GR_DIV_CMD_TYPE_SEL_Pos) |
PERI_PCLK_GR_DIV_CMD_PA_DIV_SEL_Msk |
PERI_PCLK_GR_DIV_CMD_PA_TYPE_SEL_Msk;;
PERI_PCLK->GR[1].DIV_CMD |= PERI_PCLK_GR_DIV_CMD_ENABLE_Msk; // enable divider
PERI_PCLK->GR[1].CLOCK_CTL[PCLK_SCB3_CLOCK & 0xff] = 3 << PERI_PCLK_GR_CLOCK_CTL_TYPE_SEL_Pos; // connect SCB3 to div_24_5_ctl[0]

Expand All @@ -159,9 +163,8 @@ static inline void uart_init(volatile CySCB_Type *uart, unsigned long baud) {

static inline void uart_write_byte(volatile CySCB_Type *uart, uint8_t byte) {
(void) byte; (void) uart;
//while((uart->INTR_TX & SCB_INTR_TX_EMPTY_Msk) == 0) spin(1);
while((uart->INTR_TX & SCB_INTR_TX_EMPTY_Msk) == 0) spin(1);
uart->TX_FIFO_WR = byte;
spin(1000);
}

static inline void uart_write_buf(volatile CySCB_Type *uart, char *buf, size_t len) {
Expand Down
3 changes: 1 addition & 2 deletions examples/infineon/infineon-xmc7200/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ int main(void) {
now = mg_millis();
gpio_toggle(LED2);

// for now, write only a character to UART every second
uart_write_byte(UART_DEBUG, 'a');
uart_write_buf(UART_DEBUG, "hello\n", 6);
}
}

Expand Down

0 comments on commit 79669dc

Please sign in to comment.