ZNeo Serial: Need to configure UART1 alternate function

This commit is contained in:
Gregory Nutt 2014-04-26 09:43:40 -06:00
parent f8671a7ab4
commit fe80779eb7
4 changed files with 175 additions and 139 deletions

View File

@ -148,8 +148,8 @@
_z16f_reset:
/* Initialize the init/idle task stack */
ld sp, #(_near_stack+1) /* Set Stack Pointer to the top of internal RAM */
clr fp
ld sp, #(_near_stack+1) /* Set Stack Pointer to the top of internal RAM */
clr fp
/* Initialize clocking */
@ -163,27 +163,27 @@ _z16f_reset:
/* Perform VERY early UART initialization so that we can use it here */
#ifdef USE_LOWUARTINIT
call _z16f_lowuartinit /* Initialize the UART for debugging */
call _z16f_lowuartinit /* Initialize the UART for debugging */
#endif
/* Initialize the hardware stack overflow register */
#ifdef CONFIG_Z16F_INITSPOV
ld r0, #(_near_stack_bot+1)
ld spov, r0
ld r0, #(_near_stack_bot+1)
ld spov, r0
#endif
/* Clear BSS */
lea r0, _low_nearbss
ld r1, #_len_nearbss+1
jp _z16f_reset2
lea r0, _low_nearbss
ld r1, #_len_nearbss+1
jp _z16f_reset2
_z16f_reset1:
ld.b (r0++), #0
_z16f_reset2:
djnz r1, _z16f_reset1
lea r0, _low_farbss
ld r1, #_len_farbss+1
jp _z16f_reset4
lea r0, _low_farbss
ld r1, #_len_farbss+1
jp _z16f_reset4
_z16f_reset3:
ld.b (r0++), #0
_z16f_reset4:
@ -191,20 +191,20 @@ _z16f_reset4:
/* Copy ROM data into RAM */
lea r0, _low_near_romdata
lea r1, _low_neardata
ld r2, #_len_neardata+1
jp _z16f_reset6
lea r0, _low_near_romdata
lea r1, _low_neardata
ld r2, #_len_neardata+1
jp _z16f_reset6
_z16f_reset5:
ld.b r3, (r0++)
ld.b r3, (r0++)
ld.b (r1++), r3
_z16f_reset6:
djnz r2, _z16f_reset5
djnz r2, _z16f_reset5
lea r0, _low_far_romdata
lea r1, _low_fardata
ld r2, #_len_fardata+1
jp _z16f_reset8
lea r0, _low_far_romdata
lea r1, _low_fardata
ld r2, #_len_fardata+1
jp _z16f_reset8
_z16f_reset7:
ld.b r3, (r0++)
ld.b (r1++), r3
@ -213,7 +213,7 @@ _z16f_reset8:
/* Perform low-level hardware initialization */
call _z16f_lowinit /* Perform low-level hardware initialization */
call _z16f_lowinit /* Perform low-level hardware initialization */
#ifdef USE_EARLYSERIALINIT
/* Perform early serial initialization */
@ -222,8 +222,8 @@ _z16f_reset8:
#endif
/* Start NuttX */
call _os_start /* Start the operating system */
_halt1: /* _os_start() should not return */
call _os_start /* Start the operating system */
_halt1: /* _os_start() should not return */
halt
jp _halt1
@ -244,15 +244,15 @@ _halt1: /* _os_start() should not return */
**************************************************************************/
_sysexc_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
/* Calculate the value of the SP BEFORE the interrupt occurred and
* push that as the saved value of r15=sp
*/
ld r1, #-6 /* return(4) + flags(1) + padding(1) */
add r1, sp /* r1 = Value of the SP before the interrupt */
push r1 /* Push r1 in the spot for the saved SP */
ld r1, #-6 /* return(4) + flags(1) + padding(1) */
add r1, sp /* r1 = Value of the SP before the interrupt */
push r1 /* Push r1 in the spot for the saved SP */
/* Save all of the remaining registers */
@ -263,10 +263,10 @@ _sysexc_isr:
* of the register save structure.
*/
ld r1, sp
call _z16f_sysexec /* Handle in C logic */
ld r1, sp
call _z16f_sysexec /* Handle in C logic */
_halt2: /* _z16f_sysexec() should not return */
_halt2: /* _z16f_sysexec() should not return */
halt
jp _halt2
@ -287,125 +287,124 @@ _halt2: /* _z16f_sysexec() should not return */
**************************************************************************/
_timer2_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER2 /* r1 = Timer 2 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER2 /* r1 = Timer 2 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_timer1_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER1 /* r1 = Timer 1 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER1 /* r1 = Timer 1 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_timer0_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER0 /* r1 = Timer 0 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_TIMER0 /* r1 = Timer 0 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_uart0rx_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART0RX /* r1 = UART0 RX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART0RX /* r1 = UART0 RX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_uart0tx_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART0TX /* r1 = UART0 TX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART0TX /* r1 = UART0 TX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_i2c_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_I2C /* r1 = I2C IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_I2C /* r1 = I2C IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_spi_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_SPI /* r1 = SPI IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_SPI /* r1 = SPI IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_adc_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_ADC /* r1 = ADC IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_ADC /* r1 = ADC IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p7ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P7AD /* r1 = Port A/D7, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P7AD /* r1 = Port A/D7, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p6ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P6AD /* r1 = Port A/D6, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P6AD /* r1 = Port A/D6, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p5ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P5AD /* r1 = Port A/D5, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P5AD /* r1 = Port A/D5, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p4ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P4AD /* r1 = Port A/D4, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P4AD /* r1 = Port A/D4, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p3ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P3AD /* r1 = Port A/D3, rising/falling edgeEXEC IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P3AD /* r1 = Port A/D3, rising/falling edgeEXEC IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p2ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P2AD /* r1 = Port A/D2, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P2AD /* r1 = Port A/D2, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p1ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P1AD /* r1 = Port A/D1, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P1AD /* r1 = Port A/D1, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_p0ad_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P0AD /* r1 = Port A/D0, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_P0AD /* r1 = Port A/D0, rising/falling edge IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_pwmtimer_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_PWMTIMER /* r1 = PWM Timer IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_PWMTIMER /* r1 = PWM Timer IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_uart1rx_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART1RX /* r1 = UART1 RX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART1RX /* r1 = UART1 RX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_uart1tx_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART1TX /* r1 = UART1 TX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_UART1TX /* r1 = UART1 TX IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_pwmfault_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_PWMFAULT /* r1 = PWM Fault IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_PWMFAULT /* r1 = PWM Fault IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_c3_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C3 /* r1 = Port C3, both edges DMA3 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C3 /* r1 = Port C3, both edges DMA3 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_c2_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C2 /* r1 = Port C2, both edges DMA2 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C2 /* r1 = Port C2, both edges DMA2 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_c1_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C1 /* r1 = Port C1, both edges DMA1 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C1 /* r1 = Port C1, both edges DMA1 IRQ number */
jp _common_isr /* Join common interrupt handling logic */
_c0_isr:
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C0 /* r1 = Port C0, both edges DMA0 IRQ number */
/* Join common interrupt handling logic */
pushmlo <r0-r7> /* Save r0-r7 on the stack */
ld r1, #Z16F_IRQ_C0 /* r1 = Port C0, both edges DMA0 IRQ number */
/* Join common interrupt handling logic */
/**************************************************************************
* Name: _common_isr
@ -437,9 +436,9 @@ _common_isr:
* push that as the saved value of r15=sp
*/
ld r2, #(9*4+2) /* See stack accounting above */
add r2, sp /* r1 = Value of the SP before the interrupt */
push r2 /* Push r1 in the spot for the saved SP */
ld r2, #(9*4+2) /* See stack accounting above */
add r2, sp /* r1 = Value of the SP before the interrupt */
push r2 /* Push r1 in the spot for the saved SP */
/* Save all of the remaining registers */
@ -450,7 +449,7 @@ _common_isr:
* arg2(r2)=address of the register save structure.
*/
ld r2, sp
ld r2, sp
call _up_doirq
/* Upon return, _up_doirq will provide that address of the save structure
@ -458,11 +457,11 @@ _common_isr:
* same value as sp.
*/
cp r0, sp /* Check if we are performing a context switch */
jp nz, _common_switch /* Jump if yes, else use faster return */
popmhi <r8-r14> /* Restore r8-r14 */
add sp, #4 /* Skip over restore of r15=sp */
popmlo <r0-r7> /* Restore r0-r7 */
cp r0, sp /* Check if we are performing a context switch */
jp nz, _common_switch /* Jump if yes, else use faster return */
popmhi <r8-r14> /* Restore r8-r14 */
add sp, #4 /* Skip over restore of r15=sp */
popmlo <r0-r7> /* Restore r0-r7 */
iret
/* We are not returning to the same thread that was interrupted. In this case,
@ -470,21 +469,21 @@ _common_isr:
*/
_common_switch:
ld sp, 2*REG_SP(r0) /* sp=Value of SP on return from interrupt */
ld.w r1, 2*REG_FLAGS(r0) /* r1=padded flags value */
push.w r1 /* Push padded flags value onto the stack */
ld r1, 2*REG_PC(r0) /* r1=return address */
push r1 /* Push the return address onto the stack */
ld r7, 2*REG_R7(r0) /* Recover saved r7 */
push r7 /* And save on the stack so that we can use r7 */
ld r7, sp /* r7=saved sp */
ld sp, 2*REG_SP(r0) /* sp=Value of SP on return from interrupt */
ld.w r1, 2*REG_FLAGS(r0) /* r1=padded flags value */
push.w r1 /* Push padded flags value onto the stack */
ld r1, 2*REG_PC(r0) /* r1=return address */
push r1 /* Push the return address onto the stack */
ld r7, 2*REG_R7(r0) /* Recover saved r7 */
push r7 /* And save on the stack so that we can use r7 */
ld r7, sp /* r7=saved sp */
ld sp, r0 /* sp=Pointer to register save structure */
popmhi <r8-r14> /* Restore r8-r14 */
add sp, #4 /* Skip over restore of r15=sp */
popmlo <r0-r6> /* Restore r0-r6 */
ld sp, r7 /* Switch back to the correct stack */
pop r7 /* Recover r7 from the stack */
iret /* Return from interrupt */
ld sp, r0 /* sp=Pointer to register save structure */
popmhi <r8-r14> /* Restore r8-r14 */
add sp, #4 /* Skip over restore of r15=sp */
popmlo <r0-r6> /* Restore r0-r6 */
ld sp, r7 /* Switch back to the correct stack */
pop r7 /* Recover r7 from the stack */
iret /* Return from interrupt */
end

View File

@ -90,7 +90,7 @@
* Description:
* Initialize UART0 or UART1
*
* Parameters:
* Input Parameters:
* None
*
*************************************************************************/
@ -103,7 +103,7 @@ _z16f_lowuartinit:
#ifdef CONFIG_UART1_SERIAL_CONSOLE
ld r3, #CONFIG_UART1_BAUD /* r3 = Selected UART1 baud */
#else
ld r3, #CONFIG_UART0_BAUD /* r3 = Selected UART0 (default) baud */
ld r3, #CONFIG_UART0_BAUD /* r3 = Selected UART0 (default) baud */
#endif
ld r0, r3 /* r0 = baud */
sll r0, #3 /* r0 = baud * 8 */
@ -111,8 +111,10 @@ _z16f_lowuartinit:
sll r3, #4 /* r3 = baud * 16 */
udiv r0, r3 /* BRG = (freq + baud * 8)/(baud * 16) */
/* Hacks to get a serial console available ASAP */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
ld.w Z16F_UART1_BR, r0 /* Z16F_UART1_BR = BRG */
ld.w Z16F_UART1_BR, r0 /* Z16F_UART1_BR = BRG */
/* Set the GPIO Alternate Function Register Lo (AFL) register */
@ -152,10 +154,10 @@ _z16f_lowuartinit:
* Description:
* Send one character to the selected serial console
*
* Parmeters:
* Input Parameters:
* r1 = character
*
* Return:
* Returned Value:
* None
*
* Modifies r0 (and maybe r1)

View File

@ -435,6 +435,7 @@ static int z16f_attach(struct uart_dev_s *dev)
irq_detach(priv->rxirq);
}
}
return ret;
}
@ -451,8 +452,10 @@ static int z16f_attach(struct uart_dev_s *dev)
static void z16f_detach(struct uart_dev_s *dev)
{
struct z16f_uart_s *priv = (struct z16f_uart_s*)dev->priv;
up_disable_irq(priv->rxirq);
up_disable_irq(priv->txirq);
irq_detach(priv->rxirq);
irq_detach(priv->txirq);
}
@ -484,8 +487,8 @@ static int z16f_rxinterrupt(int irq, void *context)
{
dev = &g_uart0port;
}
#endif
else
#endif
{
PANIC();
}
@ -504,7 +507,7 @@ static int z16f_rxinterrupt(int irq, void *context)
if (status & Z16F_UARTSTAT0_RDA)
{
/* Handline an incoming, receive byte */
/* Handle an incoming, received byte */
uart_recvchars(dev);
}
@ -539,8 +542,8 @@ static int z16f_txinterrupt(int irq, void *context)
{
dev = &g_uart0port;
}
#endif
else
#endif
{
PANIC();
}
@ -593,6 +596,7 @@ static int z16f_receive(struct uart_dev_s *dev, uint32_t *status)
rxd = getreg8(priv->uartbase + Z16F_UART_RXD);
stat0 = getreg8(priv->uartbase + Z16F_UART_STAT0);
*status = (uint32_t)rxd | (((uint32_t)stat0) << 8);
return rxd;
}
@ -730,15 +734,46 @@ static bool z16f_txempty(struct uart_dev_s *dev)
void up_earlyserialinit(void)
{
/* REVISIT: UART GPIO AFL register is not initialized */
uint8_t regval;
/* Configure UART alternate pin functions */
#ifdef CONFIG_Z16F_UART0
/* UART0 is PA4 and PA5, alternate function 1 */
regval = getreg8(Z16F_GPIOA_AFL);
regval |= 0x30;
putreg8(regval, Z16F_GPIOA_AFL);
regval = getreg8(Z16F_GPIOA_AFH);
regval &= ~0x30;
putreg8(regval, Z16F_GPIOA_AFH);
#endif
#ifdef CONFIG_Z16F_UART1
/* UART1 is PD4 and PD5, alternate function 1 */
regval = getreg8(Z16F_GPIOD_AFL);
regval |= 0x30;
putreg8(regval, Z16F_GPIOD_AFL);
regval = getreg8(Z16F_GPIOD_AFH);
regval &= ~0x30;
putreg8(regval, Z16F_GPIOD_AFH);
#endif
/* Disable UART interrupts */
#ifdef TTYS0_DEV
(void)z16f_disableuartirq(&TTYS0_DEV);
#endif
#ifdef TTYS1_DEV
(void)z16f_disableuartirq(&TTYS1_DEV);
#endif
/* Configuration any serial console */
#ifdef CONSOLE_DEV
CONSOLE_DEV.isconsole = true;
z16f_setup(&CONSOLE_DEV);

View File

@ -115,8 +115,8 @@ connector labelled CONSOLE.
UART1 is also available on JP2:
MCU PIN GPIO JP2
Pin 86 TXD1 PD5 JP2 Pin 25
Pin 87 RXD1 PD4 JP2 Pin 25
Pin 86 TXD1 PD5 JP2 Pin 26
Pin 87 RXD1 PD4 JP2 Pin 27
Vcc JP2 Pin 59
GND JP2 Pins 19, 39, 46, 48, 56