diff --git a/TODO b/TODO index 5c67ae83ac..bbc8f7657a 100644 --- a/TODO +++ b/TODO @@ -937,6 +937,7 @@ o Network (net/, drivers/net) LM3S NO NO TM4C YES YES eZ80 NO NO + Kinetis YES YES (not tested) LPC17xx YES YES (not tested) LPC43xx YES YES (not tested) DMxxx NIC NO NO diff --git a/arch/arm/src/kinetis/Kconfig b/arch/arm/src/kinetis/Kconfig index 2e0ff4ae89..6a0c036765 100644 --- a/arch/arm/src/kinetis/Kconfig +++ b/arch/arm/src/kinetis/Kconfig @@ -548,18 +548,27 @@ config KINETIS_ENETNTXBUFFERS Number of Ethernet Tx buffers to use. The size of one buffer is determined by NET_BUFSIZE -config KINETIS_ENETPHYADDR - int "PHY address" - default 1 - ---help--- - MII/RMII address of the PHY - config KINETIS_ENETUSEMII bool "Use MII interface" default n ---help--- The the MII PHY interface. Default: Use RMII interface +config KINETIS_ENET_MDIOPULLUP + bool "MDIO pull-up" + default n + ---help--- + If there is no on-board pull-up resister on the MII/RMII MDIO line, + then this option may be selected in order to configure an internal + pull-up on MDIO. + +config KINETIS_ENET_NORXER + bool "Suppress RXER" + default n + ---help--- + If selected, then the MII/RMII RXER output will be configured as a + GPIO and pulled low. + endmenu # Kinetis Ethernet Configuration menu "Kinetis SDHC Configuration" diff --git a/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h index 5cfb3a1aa0..4e7619c18f 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k60pinmux.h @@ -83,12 +83,12 @@ #define PIN_FTM0_CH1_1 (PIN_ALT3 | PIN_PORTA | PIN4) #define PIN_NMI (PIN_ALT7 | PIN_PORTA | PIN4) #define PIN_FTM0_CH2_1 (PIN_ALT3 | PIN_PORTA | PIN5) -#if 0 +#ifdef CONFIG_KINETIS_ENET_NORXER +# define PIN_RMII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) +# define PIN_MII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) +#else # define PIN_RMII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) # define PIN_MII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) -#else -# define PIN_RMII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) -# define PIN_MII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) #endif #define PIN_CMP2_OUT_1 (PIN_ALT5 | PIN_PORTA | PIN5) #define PIN_I2S0_RX_BCLK_1 (PIN_ALT6 | PIN_PORTA | PIN5) @@ -174,7 +174,11 @@ #define PIN_TSI0_CH0 (PIN_ANALOG | PIN_PORTB | PIN0) #define PIN_I2C0_SCL_1 (PIN_ALT2 | PIN_PORTB | PIN0) #define PIN_FTM1_CH0_3 (PIN_ALT3 | PIN_PORTB | PIN0) -#define PIN_RMII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#ifdef CONFIG_KINETIS_ENET_MDIOPULLUP +# define PIN_RMII0_MDIO (PIN_ALT4_PULLUP | PIN_PORTB | PIN0) +#else +# define PIN_RMII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#endif #define PIN_MII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) #define PIN_FTM1_QD_PHA_3 (PIN_ALT6 | PIN_PORTB | PIN0) #define PIN_ADC0_SE9 (PIN_ANALOG | PIN_PORTB | PIN1) diff --git a/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h b/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h index 724761a6e8..3479099bf6 100644 --- a/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h +++ b/arch/arm/src/kinetis/chip/kinetis_k64pinmux.h @@ -398,14 +398,22 @@ #define PIN_MII0_COL (PIN_ALT4 | PIN_PORTA | PIN29) #define PIN_MII0_CRS (PIN_ALT4 | PIN_PORTA | PIN27) #define PIN_MII0_MDC (PIN_ALT4 | PIN_PORTB | PIN1) -#define PIN_MII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#ifdef CONFIG_KINETIS_ENET_MDIOPULLUP +# define PIN_MII0_MDIO (PIN_ALT4_PULLUP | PIN_PORTB | PIN0) +#else +# define PIN_MII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#endif #define PIN_MII0_RXCLK (PIN_ALT4 | PIN_PORTA | PIN11) #define PIN_MII0_RXD0 (PIN_ALT4 | PIN_PORTA | PIN13) #define PIN_MII0_RXD1 (PIN_ALT4 | PIN_PORTA | PIN12) #define PIN_MII0_RXD2 (PIN_ALT4 | PIN_PORTA | PIN10) #define PIN_MII0_RXD3 (PIN_ALT4 | PIN_PORTA | PIN9) #define PIN_MII0_RXDV (PIN_ALT4 | PIN_PORTA | PIN14) -#define PIN_MII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) +#ifdef CONFIG_KINETIS_ENET_NORXER +# define PIN_MII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) +#else +# define PIN_MII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) +#endif #define PIN_MII0_TXCLK (PIN_ALT4 | PIN_PORTA | PIN25) #define PIN_MII0_TXD0 (PIN_ALT4 | PIN_PORTA | PIN16) #define PIN_MII0_TXD1 (PIN_ALT4 | PIN_PORTA | PIN17) @@ -427,10 +435,18 @@ #define PIN_RMII0_CRS_DV (PIN_ALT4 | PIN_PORTA | PIN14) #define PIN_RMII0_MDC (PIN_ALT4 | PIN_PORTB | PIN1) -#define PIN_RMII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#ifdef CONFIG_KINETIS_ENET_MDIOPULLUP +# define PIN_RMII0_MDIO (PIN_ALT4_PULLUP | PIN_PORTB | PIN0) +#else +# define PIN_RMII0_MDIO (PIN_ALT4 | PIN_PORTB | PIN0) +#endif #define PIN_RMII0_RXD0 (PIN_ALT4 | PIN_PORTA | PIN13) #define PIN_RMII0_RXD1 (PIN_ALT4 | PIN_PORTA | PIN12) -#define PIN_RMII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) +#ifdef CONFIG_KINETIS_ENET_NORXER +# define PIN_RMII0_RXER (GPIO_PULLDOWN | PIN_PORTA | PIN5) +#else +# define PIN_RMII0_RXER (PIN_ALT4 | PIN_PORTA | PIN5) +#endif #define PIN_RMII0_TXD0 (PIN_ALT4 | PIN_PORTA | PIN16) #define PIN_RMII0_TXD1 (PIN_ALT4 | PIN_PORTA | PIN17) #define PIN_RMII0_TXEN (PIN_ALT4 | PIN_PORTA | PIN15) diff --git a/arch/arm/src/kinetis/kinetis_enet.c b/arch/arm/src/kinetis/kinetis_enet.c index c72c12951b..dc0be25e16 100644 --- a/arch/arm/src/kinetis/kinetis_enet.c +++ b/arch/arm/src/kinetis/kinetis_enet.c @@ -57,6 +57,10 @@ #include #include +#ifdef CONFIG_NET_NOINTS +# include +#endif + #ifdef CONFIG_NET_PKT # include #endif @@ -76,6 +80,14 @@ * Pre-processor Definitions ****************************************************************************/ +/* If processing is not done at the interrupt level, then high priority + * work queue support is required. + */ + +#if defined(CONFIG_NET_NOINTS) && !defined(CONFIG_SCHED_HPWORK) +# error High priority work queue support is required +#endif + /* CONFIG_KINETIS_ENETNETHIFS determines the number of physical interfaces * that will be supported. */ @@ -92,13 +104,16 @@ # error "Need at least one RX buffer" #endif -#define NENET_NBUFFERS (CONFIG_KINETIS_ENETNTXBUFFERS+CONFIG_KINETIS_ENETNRXBUFFERS) +#define NENET_NBUFFERS \ + (CONFIG_KINETIS_ENETNTXBUFFERS+CONFIG_KINETIS_ENETNRXBUFFERS) #ifndef CONFIG_NET_MULTIBUFFER # error "CONFIG_NET_MULTIBUFFER is required in the configuration" #endif -/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ +/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per + * second. + */ #define KINETIS_WDDELAY (1*CLK_TCK) @@ -193,8 +208,12 @@ struct kinetis_driver_s uint8_t txtail; /* The oldest busy TX descriptor */ uint8_t txhead; /* The next TX descriptor to use */ uint8_t rxtail; /* The next RX descriptor to use */ + uint8_t phyaddr; /* Selected PHY address */ WDOG_ID txpoll; /* TX poll timer */ WDOG_ID txtimeout; /* TX timeout timer */ +#ifdef CONFIG_NET_NOINTS + struct work_s work; /* For deferring work to the work queue */ +#endif struct enet_desc_s *txdesc; /* A pointer to the list of TX descriptor */ struct enet_desc_s *rxdesc; /* A pointer to the list of RX descriptors */ @@ -251,22 +270,43 @@ static int kinetis_txpoll(struct net_driver_s *dev); static void kinetis_receive(FAR struct kinetis_driver_s *priv); static void kinetis_txdone(FAR struct kinetis_driver_s *priv); + +static inline void kinetis_interrupt_process(FAR struct kinetis_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void kinetis_interrupt_work(FAR void *arg); +#endif static int kinetis_interrupt(int irq, FAR void *context); /* Watchdog timer expirations */ -static void kinetis_txtimeout(int argc, uint32_t arg, ...); -static void kinetis_polltimer(int argc, uint32_t arg, ...); +static inline void kinetis_txtimeout_process(FAR struct kinetis_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void kinetis_txtimeout_work(FAR void *arg); +#endif +static void kinetis_txtimeout_expiry(int argc, uint32_t arg, ...); + +static inline void kinetis_poll_process(FAR struct kinetis_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void kinetis_poll_work(FAR void *arg); +#endif +static void kinetis_polltimer_expiry(int argc, uint32_t arg, ...); /* NuttX callback functions */ static int kinetis_ifup(struct net_driver_s *dev); static int kinetis_ifdown(struct net_driver_s *dev); + +static inline void kinetis_txavail_process(FAR struct kinetis_driver_s *priv); +#ifdef CONFIG_NET_NOINTS +static void kinetis_txavail_work(FAR void *arg); +#endif static int kinetis_txavail(struct net_driver_s *dev); + #ifdef CONFIG_NET_IGMP static int kinetis_addmac(struct net_driver_s *dev, FAR const uint8_t *mac); static int kinetis_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac); #endif + #ifdef CONFIG_NETDEV_PHY_IOCTL static int kinetis_ioctl(struct net_driver_s *dev, int cmd, long arg); #endif @@ -278,7 +318,7 @@ static int kinetis_writemii(struct kinetis_driver_s *priv, uint8_t phyaddr, uint8_t regaddr, uint16_t data); static int kinetis_readmii(struct kinetis_driver_s *priv, uint8_t phyaddr, uint8_t regaddr, uint16_t *data); -static inline void kinetis_initphy(struct kinetis_driver_s *priv); +static inline int kinetis_initphy(struct kinetis_driver_s *priv); /* Initialization */ @@ -463,8 +503,8 @@ static int kinetis_transmit(FAR struct kinetis_driver_s *priv) /* Setup the TX timeout watchdog (perhaps restarting the timer) */ - (void)wd_start(priv->txtimeout, KINETIS_TXTIMEOUT, kinetis_txtimeout, 1, - (uint32_t)priv); + (void)wd_start(priv->txtimeout, KINETIS_TXTIMEOUT, kinetis_txtimeout_expiry, 1, + (wdparm_t)priv); return OK; } @@ -776,28 +816,25 @@ static void kinetis_txdone(FAR struct kinetis_driver_s *priv) } /**************************************************************************** - * Function: kinetis_interrupt + * Function: kinetis_interrupt_process * * Description: - * Three interrupt sources will vector this this function: - * 1. Ethernet MAC transmit interrupt handler - * 2. Ethernet MAC receive interrupt handler - * 3. + * Interrupt processing. This may be performed either within the interrupt + * handler or on the worker thread, depending upon the configuration * * Parameters: - * irq - Number of the IRQ that generated the interrupt - * context - Interrupt register state save info (architecture-specific) + * priv - Reference to the driver state structure * * Returned Value: - * OK on success + * None * * Assumptions: + * The network is locked. * ****************************************************************************/ -static int kinetis_interrupt(int irq, FAR void *context) +static inline void kinetis_interrupt_process(FAR struct kinetis_driver_s *priv) { - register FAR struct kinetis_driver_s *priv = &g_enet[0]; uint32_t pending; /* Get the set of unmasked, pending interrupt. */ @@ -847,33 +884,130 @@ static int kinetis_interrupt(int irq, FAR void *context) putreg32(ENET_RDAR, KINETIS_ENET_RDAR); } +} + +/**************************************************************************** + * Function: kinetis_interrupt_work + * + * Description: + * Perform interrupt related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() was called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void kinetis_interrupt_work(FAR void *arg) +{ + FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; + net_lock_t state; + + /* Process pending Ethernet interrupts */ + + state = net_lock(); + kinetis_interrupt_process(priv); + net_unlock(state); + + /* Re-enable Ethernet interrupts */ + +#if 0 + up_enable_irq(KINETIS_IRQ_EMACTMR); +#endif + up_enable_irq(KINETIS_IRQ_EMACTX); + up_enable_irq(KINETIS_IRQ_EMACRX); + up_enable_irq(KINETIS_IRQ_EMACMISC); +} +#endif + +/**************************************************************************** + * Function: kinetis_interrupt + * + * Description: + * Three interrupt sources will vector this this function: + * 1. Ethernet MAC transmit interrupt handler + * 2. Ethernet MAC receive interrupt handler + * 3. + * + * Parameters: + * irq - Number of the IRQ that generated the interrupt + * context - Interrupt register state save info (architecture-specific) + * + * Returned Value: + * OK on success + * + * Assumptions: + * + ****************************************************************************/ + +static int kinetis_interrupt(int irq, FAR void *context) +{ + register FAR struct kinetis_driver_s *priv = &g_enet[0]; + +#ifdef CONFIG_NET_NOINTS + /* Disable further Ethernet interrupts. Because Ethernet interrupts are + * also disabled if the TX timeout event occurs, there can be no race + * condition here. + */ + + up_disable_irq(KINETIS_IRQ_EMACTMR); + up_disable_irq(KINETIS_IRQ_EMACTX); + up_disable_irq(KINETIS_IRQ_EMACRX); + up_disable_irq(KINETIS_IRQ_EMACMISC); + + /* TODO: Determine if a TX transfer just completed */ + + { + /* If a TX transfer just completed, then cancel the TX timeout so + * there will be do race condition between any subsequent timeout + * expiration and the deferred interrupt processing. + */ + + wd_cancel(priv->txtimeout); + } + + /* Cancel any pending poll work */ + + work_cancel(HPWORK, &priv->work); + + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(HPWORK, &priv->work, kinetis_interrupt_work, priv, 0); + +#else + /* Process the interrupt now */ + + kinetis_interrupt_process(priv); +#endif return OK; } /**************************************************************************** - * Function: kinetis_txtimeout + * Function: kinetis_txtimeout_process * * Description: - * Our TX watchdog timed out. Called from the timer interrupt handler. - * The last TX never completed. Reset the hardware and start again. + * Process a TX timeout. Called from the either the watchdog timer + * expiration logic or from the worker thread, depending upon the + * configuration. The timeout means that the last TX never completed. + * Reset the hardware and start again. * * Parameters: - * argc - The number of available arguments - * arg - The first argument + * priv - Reference to the driver state structure * * Returned Value: * None * - * Assumptions: - * Global interrupts are disabled by the watchdog logic. - * ****************************************************************************/ -static void kinetis_txtimeout(int argc, uint32_t arg, ...) +static inline void kinetis_txtimeout_process(FAR struct kinetis_driver_s *priv) { - FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; - /* Increment statistics and dump debug info */ NETDEV_TXTIMEOUTS(&priv->dev); @@ -891,10 +1025,42 @@ static void kinetis_txtimeout(int argc, uint32_t arg, ...) } /**************************************************************************** - * Function: kinetis_polltimer + * Function: kinetis_txtimeout_work * * Description: - * Periodic timer handler. Called from the timer interrupt handler. + * Perform TX timeout related work from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void kinetis_txtimeout_work(FAR void *arg) +{ + FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; + net_lock_t state; + + /* Process pending Ethernet interrupts */ + + state = net_lock(); + kinetis_txtimeout_process(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: kinetis_txtimeout_expiry + * + * Description: + * Our TX watchdog timed out. Called from the timer interrupt handler. + * The last TX never completed. Reset the hardware and start again. * * Parameters: * argc - The number of available arguments @@ -908,10 +1074,56 @@ static void kinetis_txtimeout(int argc, uint32_t arg, ...) * ****************************************************************************/ -static void kinetis_polltimer(int argc, uint32_t arg, ...) +static void kinetis_txtimeout_expiry(int argc, uint32_t arg, ...) { FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; +#ifdef CONFIG_NET_NOINTS + /* Disable further Ethernet interrupts. This will prevent some race + * conditions with interrupt work. There is still a potential race + * condition with interrupt work that is already queued and in progress. + */ + + up_disable_irq(KINETIS_IRQ_EMACTMR); + up_disable_irq(KINETIS_IRQ_EMACTX); + up_disable_irq(KINETIS_IRQ_EMACRX); + up_disable_irq(KINETIS_IRQ_EMACMISC); + + /* Cancel any pending poll or interrupt work. This will have no effect + * on work that has already been started. + */ + + work_cancel(HPWORK, &priv->work); + + /* Schedule to perform the TX timeout processing on the worker thread. */ + + work_queue(HPWORK, &priv->work, kinetis_txtimeout_work, priv, 0); +#else + /* Process the timeout now */ + + kinetis_txtimeout_process(priv); +#endif +} + +/**************************************************************************** + * Function: kinetis_poll_process + * + * Description: + * Perform the periodic poll. This may be called either from watchdog + * timer logic or from the worker thread, depending upon the configuration. + * + * Parameters: + * priv - Reference to the driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * + ****************************************************************************/ + +static inline void kinetis_poll_process(FAR struct kinetis_driver_s *priv) +{ /* Check if there is there is a transmission in progress. We cannot perform * the TX poll if he are unable to accept another packet for transmission. */ @@ -928,7 +1140,89 @@ static void kinetis_polltimer(int argc, uint32_t arg, ...) /* Setup the watchdog poll timer again in any case */ - (void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, arg); + (void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer_expiry, + 1, (wdparm_t)priv); +} + +/**************************************************************************** + * Function: kinetis_poll_work + * + * Description: + * Perform periodic polling from the worker thread + * + * Parameters: + * arg - The argument passed when work_queue() as called. + * + * Returned Value: + * OK on success + * + * Assumptions: + * The network is locked. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void kinetis_poll_work(FAR void *arg) +{ + FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; + net_lock_t state; + + /* Perform the poll */ + + state = net_lock(); + kinetis_poll_process(priv); + net_unlock(state); +} +#endif + +/**************************************************************************** + * Function: kinetis_polltimer_expiry + * + * Description: + * Periodic timer handler. Called from the timer interrupt handler. + * + * Parameters: + * argc - The number of available arguments + * arg - The first argument + * + * Returned Value: + * None + * + * Assumptions: + * Global interrupts are disabled by the watchdog logic. + * + ****************************************************************************/ + +static void kinetis_polltimer_expiry(int argc, uint32_t arg, ...) +{ + FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; + +#ifdef CONFIG_NET_NOINTS + /* Is our single work structure available? It may not be if there are + * pending interrupt actions. + */ + + if (work_available(&priv->work)) + { + /* Schedule to perform the interrupt processing on the worker thread. */ + + work_queue(HPWORK, &priv->work, kinetis_poll_work, priv, 0); + } + else + { + /* No.. Just re-start the watchdog poll timer, missing one polling + * cycle. + */ + + (void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer_expiry, + 1, (wdparm_t)arg); + } + +#else + /* Process the interrupt now */ + + kinetis_poll_process(priv); +#endif } /**************************************************************************** @@ -954,6 +1248,7 @@ static int kinetis_ifup(struct net_driver_s *dev) (FAR struct kinetis_driver_s *)dev->d_private; uint8_t *mac = dev->d_mac.ether_addr_octet; uint32_t regval; + int ret; ninfo("Bringing up: %d.%d.%d.%d\n", dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff, @@ -986,7 +1281,12 @@ static int kinetis_ifup(struct net_driver_s *dev) /* Configure the PHY */ - kinetis_initphy(priv); + ret = kinetis_initphy(priv); + if (ret < 0) + { + nerr("ERROR: Failed to configure the PHY: %d\n", ret); + return ret; + } /* Handle promiscuous mode */ @@ -1032,8 +1332,8 @@ static int kinetis_ifup(struct net_driver_s *dev) /* Set and activate a timer process */ - (void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer, 1, - (uint32_t)priv); + (void)wd_start(priv->txpoll, KINETIS_WDDELAY, kinetis_polltimer_expiry, 1, + (wdparm_t)priv); /* Clear all pending ENET interrupt */ @@ -1108,6 +1408,77 @@ static int kinetis_ifdown(struct net_driver_s *dev) return OK; } +/**************************************************************************** + * Function: kinetis_txavail_process + * + * Description: + * Perform an out-of-cycle poll. + * + * Parameters: + * dev - Reference to the NuttX driver state structure + * + * Returned Value: + * None + * + * Assumptions: + * Called in normal user mode + * + ****************************************************************************/ + +static inline void kinetis_txavail_process(FAR struct kinetis_driver_s *priv) +{ + net_lock_t state; + + /* Ignore the notification if the interface is not yet up */ + + state = net_lock(); + if (priv->bifup) + { + /* Check if there is room in the hardware to hold another outgoing + * packet. + */ + + if (!kinetics_txringfull(priv)) + { + /* No, there is space for another transfer. Poll the network for new + * XMIT data. + */ + + (void)devif_poll(&priv->dev, kinetis_txpoll); + } + } + + net_unlock(state); +} + +/**************************************************************************** + * Function: kinetis_txavail_work + * + * Description: + * Perform an out-of-cycle poll on the worker thread. + * + * Parameters: + * arg - Reference to the NuttX driver state structure (cast to void*) + * + * Returned Value: + * None + * + * Assumptions: + * Called on the higher priority worker thread. + * + ****************************************************************************/ + +#ifdef CONFIG_NET_NOINTS +static void kinetis_txavail_work(FAR void *arg) +{ + FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)arg; + + /* Perform the poll */ + + kinetis_txavail_process(priv); +} +#endif + /**************************************************************************** * Function: kinetis_txavail * @@ -1131,33 +1502,26 @@ static int kinetis_txavail(struct net_driver_s *dev) { FAR struct kinetis_driver_s *priv = (FAR struct kinetis_driver_s *)dev->d_private; - irqstate_t flags; - /* Disable interrupts because this function may be called from interrupt - * level processing. +#ifdef CONFIG_NET_NOINTS + /* Is our single work structure available? It may not be if there are + * pending interrupt actions and we will have to ignore the Tx + * availability action. */ - flags = enter_critical_section(); - - /* Ignore the notification if the interface is not yet up */ - - if (priv->bifup) + if (work_available(&priv->work)) { - /* Check if there is room in the hardware to hold another outgoing - * packet. - */ + /* Schedule to serialize the poll on the worker thread. */ - if (!kinetics_txringfull(priv)) - { - /* No, there is space for another transfer. Poll the network for new - * XMIT data. - */ - - (void)devif_poll(&priv->dev, kinetis_txpoll); - } + work_queue(HPWORK, &priv->work, kinetis_txavail_work, priv, 0); } - leave_critical_section(flags); +#else + /* Perform the out-of-cycle poll now */ + + kinetis_txavail_process(priv); +#endif + return OK; } @@ -1253,7 +1617,7 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd, long arg) { struct mii_ioctl_data_s *req = (struct mii_ioctl_data_s *)((uintptr_t)arg); - req->phy_id = CONFIG_KINETIS_ENETPHYADDR; + req->phy_id = priv->phyaddr; ret = OK; } break; @@ -1418,6 +1782,7 @@ static int kinetis_readmii(struct kinetis_driver_s *priv, uint8_t phyaddr, if (timeout >= MII_MAXPOLLS) { + nerr("ERROR: Timed out waiting for transfer to complete\n"); return -ETIMEDOUT; } @@ -1441,31 +1806,59 @@ static int kinetis_readmii(struct kinetis_driver_s *priv, uint8_t phyaddr, * priv - Reference to the private ENET driver state structure * * Returned Value: - * None + * Zero (OK) returned on success; a negated errno value is returned on any + * failure; * * Assumptions: * ****************************************************************************/ -static inline void kinetis_initphy(struct kinetis_driver_s *priv) +static inline int kinetis_initphy(struct kinetis_driver_s *priv) { uint32_t rcr; uint32_t tcr; uint16_t phydata; + uint8_t phyaddr; + int retries; + int ret; /* Loop (potentially infinitely?) until we successfully communicate with * the PHY. */ - do + for (phyaddr = 0; phyaddr < 32; phyaddr++) { - usleep(LINK_WAITUS); - phydata = 0xffff; - kinetis_readmii(priv, CONFIG_KINETIS_ENETPHYADDR, MII_PHYID1, &phydata); - } - while (phydata == 0xffff); + ninfo("%s: Try phyaddr: %u\n", BOARD_PHY_NAME, phyaddr); + + /* Try to read PHYID1 few times using this address */ + + retries = 0; + do + { + usleep(LINK_WAITUS); + ninfo("%s: Read PHYID1, retries=%d\n", BOARD_PHY_NAME, retries + 1); + phydata = 0xffff; + ret = kinetis_readmii(priv, phyaddr, MII_PHYID1, &phydata); + } + while ((ret < 0 || phydata == 0xffff) && ++retries < 3); + + /* If we successfully read anything then break out, using this PHY address */ + + if (retries < 3) + { + break; + } + } + + if (phyaddr >= 32) + { + nerr("ERROR: Failed to read %s PHYID1 at any address\n"); + return -ENOENT; + } + + ninfo("%s: Using PHY address %u\n", BOARD_PHY_NAME, phyaddr); + priv->phyaddr = phyaddr; -#if CONFIG_DEBUG_NET_ERROR /* Verify PHYID1. Compare OUI bits 3-18 */ ninfo("%s: PHYID1: %04x\n", BOARD_PHY_NAME, phydata); @@ -1473,29 +1866,35 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv) { nerr("ERROR: PHYID1=%04x incorrect for %s. Expected %04x\n", phydata, BOARD_PHY_NAME, BOARD_PHYID1); + return -ENXIO; } - else + + /* Read PHYID2 */ + + ret = kinetis_readmii(priv, phyaddr, MII_PHYID2, &phydata); + if (ret < 0) { - /* Read PHYID2 */ - - kinetis_readmii(priv, CONFIG_KINETIS_ENETPHYADDR, MII_PHYID2, &phydata); - ninfo("%s: PHYID2: %04x\n", BOARD_PHY_NAME, phydata); - - /* Verify PHYID2: Compare OUI bits 19-24 and the 6-bit model number - * (ignoring the 4-bit revision number). - */ - - if ((phydata & 0xfff0) != (BOARD_PHYID2 & 0xfff0)) - { - nerr("ERROR: PHYID2=%04x incorrect for %s. Expected %04x\n", - (phydata & 0xfff0), BOARD_PHY_NAME, (BOARD_PHYID2 & 0xfff0)); - } + nerr("ERROR: Failed to read %s PHYID2: %d\n", BOARD_PHY_NAME, ret); + return ret; + } + + ninfo("%s: PHYID2: %04x\n", BOARD_PHY_NAME, phydata); + + /* Verify PHYID2: Compare OUI bits 19-24 and the 6-bit model number + * (ignoring the 4-bit revision number). + */ + + if ((phydata & 0xfff0) != (BOARD_PHYID2 & 0xfff0)) + { + nerr("ERROR: PHYID2=%04x incorrect for %s. Expected %04x\n", + (phydata & 0xfff0), BOARD_PHY_NAME, (BOARD_PHYID2 & 0xfff0)); + return -ENXIO; } -#endif /* Start auto negotiation */ - kinetis_writemii(priv, CONFIG_KINETIS_ENETPHYADDR, MII_MCR, + ninfo("%s: Start autonegotiation...\n", BOARD_PHY_NAME); + kinetis_writemii(priv, phyaddr, MII_MCR, (MII_MCR_ANRESTART | MII_MCR_ANENABLE)); /* Wait (potentially forever) for auto negotiation to complete */ @@ -1503,16 +1902,30 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv) do { usleep(LINK_WAITUS); - kinetis_readmii(priv, CONFIG_KINETIS_ENETPHYADDR, MII_MSR, &phydata); + ret = kinetis_readmii(priv, phyaddr, MII_MSR, &phydata); + if (ret < 0) + { + nerr("ERROR: Failed to read %s MII_MSR: %d\n", + BOARD_PHY_NAME, ret); + return ret; + } } while ((phydata & MII_MSR_ANEGCOMPLETE) == 0); + ninfo("%s: Autonegotiation complete\n", BOARD_PHY_NAME); ninfo("%s: MII_MSR: %04x\n", BOARD_PHY_NAME, phydata); /* When we get here we have a link - Find the negotiated speed and duplex. */ phydata = 0; - kinetis_readmii(priv, CONFIG_KINETIS_ENETPHYADDR, BOARD_PHY_STATUS, &phydata); + ret = kinetis_readmii(priv, phyaddr, BOARD_PHY_STATUS, &phydata); + if (ret < 0) + { + nerr("ERROR: Failed to read %s BOARD_PHY_STATUS{%02x]: %d\n", + BOARD_PHY_NAME, BOARD_PHY_STATUS, ret); + return ret; + } + ninfo("%s: BOARD_PHY_STATUS: %04x\n", BOARD_PHY_NAME, phydata); @@ -1540,29 +1953,42 @@ static inline void kinetis_initphy(struct kinetis_driver_s *priv) { /* Full duplex */ + ninfo("%s: Full duplex\n", BOARD_PHY_NAME); tcr |= ENET_TCR_FDEN; } else { /* Half duplex */ + ninfo("%s: Half duplex\n", BOARD_PHY_NAME); rcr |= ENET_RCR_DRT; } if (BOARD_PHY_10BASET(phydata)) { - /* 10Mbps */ + /* 10 Mbps */ + ninfo("%s: 10 Base-T\n", BOARD_PHY_NAME); rcr |= ENET_RCR_RMII_10T; } else if (!BOARD_PHY_100BASET(phydata)) { + /* 100 Mbps */ + + ninfo("%s: 100 Base-T\n", BOARD_PHY_NAME); + } + else + { + /* This might happen if autonegotiation did not complete(?) */ + nerr("ERROR: Neither 10- nor 100-BaseT reported: PHY STATUS=%04x\n", phydata); + return -EIO; } putreg32(rcr, KINETIS_ENET_RCR); putreg32(tcr, KINETIS_ENET_TCR); + return OK; } /**************************************************************************** diff --git a/arch/arm/src/stm32l4/stm32l4_serial.c b/arch/arm/src/stm32l4/stm32l4_serial.c index aa21ada61d..e85e73a3e3 100644 --- a/arch/arm/src/stm32l4/stm32l4_serial.c +++ b/arch/arm/src/stm32l4/stm32l4_serial.c @@ -90,13 +90,13 @@ # if defined(CONFIG_USART2_RXDMA) || defined(CONFIG_USART3_RXDMA) # ifndef CONFIG_STM32L4_DMA1 -# error STM32 USART2/3 receive DMA requires CONFIG_STM32L4_DMA1 +# error STM32L4 USART2/3 receive DMA requires CONFIG_STM32L4_DMA1 # endif # endif # if defined(CONFIG_UART4_RXDMA) || defined(CONFIG_UART5_RXDMA) # ifndef CONFIG_STM32L4_DMA2 -# error STM32 USART4/5 receive DMA requires CONFIG_STM32L4_DMA2 +# error STM32L4 USART4/5 receive DMA requires CONFIG_STM32L4_DMA2 # endif # endif @@ -139,65 +139,27 @@ /* DMA priority */ # ifndef CONFIG_USART_DMAPRIO -# if defined(CONFIG_STM32L4_STM32L15XX) || defined(CONFIG_STM32L4_STM32F10XX) || \ - defined(CONFIG_STM32L4_STM32F30XX) || defined(CONFIG_STM32L4_STM32F37XX) -# define CONFIG_USART_DMAPRIO DMA_CCR_PRIMED -# elif defined(CONFIG_STM32L4_STM32F20XX) || defined(CONFIG_STM32L4_STM32F40XX) -# define CONFIG_USART_DMAPRIO DMA_SCR_PRIMED -# else -# error "Unknown STM32 DMA" -# endif +# define CONFIG_USART_DMAPRIO DMA_CCR_PRIMED # endif -# if defined(CONFIG_STM32L4_STM32L15XX) || defined(CONFIG_STM32L4_STM32F10XX) || \ - defined(CONFIG_STM32L4_STM32F30XX) || defined(CONFIG_STM32L4_STM32F37XX) -# if (CONFIG_USART_DMAPRIO & ~DMA_CCR_PL_MASK) != 0 -# error "Illegal value for CONFIG_USART_DMAPRIO" -# endif -# elif defined(CONFIG_STM32L4_STM32F20XX) || defined(CONFIG_STM32L4_STM32F40XX) -# if (CONFIG_USART_DMAPRIO & ~DMA_SCR_PL_MASK) != 0 -# error "Illegal value for CONFIG_USART_DMAPRIO" -# endif -# else -# error "Unknown STM32 DMA" +# if (CONFIG_USART_DMAPRIO & ~DMA_CCR_PL_MASK) != 0 +# error "Illegal value for CONFIG_USART_DMAPRIO" # endif /* DMA control words */ -# if defined(CONFIG_STM32L4_STM32F20XX) || defined(CONFIG_STM32L4_STM32F40XX) -# define SERIAL_DMA_CONTROL_WORD \ - (DMA_SCR_DIR_P2M | \ - DMA_SCR_CIRC | \ - DMA_SCR_MINC | \ - DMA_SCR_PSIZE_8BITS | \ - DMA_SCR_MSIZE_8BITS | \ - CONFIG_USART_DMAPRIO | \ - DMA_SCR_PBURST_SINGLE | \ - DMA_SCR_MBURST_SINGLE) -# ifdef CONFIG_SERIAL_IFLOWCONTROL -# define SERIAL_DMA_IFLOW_CONTROL_WORD \ - (DMA_SCR_DIR_P2M | \ - DMA_SCR_MINC | \ - DMA_SCR_PSIZE_8BITS | \ - DMA_SCR_MSIZE_8BITS | \ - CONFIG_USART_DMAPRIO | \ - DMA_SCR_PBURST_SINGLE | \ - DMA_SCR_MBURST_SINGLE) -# endif -# else -# define SERIAL_DMA_CONTROL_WORD \ - (DMA_CCR_CIRC | \ - DMA_CCR_MINC | \ - DMA_CCR_PSIZE_8BITS | \ - DMA_CCR_MSIZE_8BITS | \ - CONFIG_USART_DMAPRIO) -# ifdef CONFIG_SERIAL_IFLOWCONTROL -# define SERIAL_DMA_IFLOW_CONTROL_WORD \ - (DMA_CCR_MINC | \ - DMA_CCR_PSIZE_8BITS | \ - DMA_CCR_MSIZE_8BITS | \ - CONFIG_USART_DMAPRIO) -# endif -# endif +# define SERIAL_DMA_CONTROL_WORD \ + (DMA_CCR_CIRC | \ + DMA_CCR_MINC | \ + DMA_CCR_PSIZE_8BITS | \ + DMA_CCR_MSIZE_8BITS | \ + CONFIG_USART_DMAPRIO) +# ifdef CONFIG_SERIAL_IFLOWCONTROL +# define SERIAL_DMA_IFLOW_CONTROL_WORD \ + (DMA_CCR_MINC | \ + DMA_CCR_PSIZE_8BITS | \ + DMA_CCR_MSIZE_8BITS | \ + CONFIG_USART_DMAPRIO) +# endif #endif @@ -216,7 +178,7 @@ * register. It must not collide with USART_CR1_USED_INTS or USART_CR3_EIE * 2) USART_CR3_EIE is also carried in the up_dev_s ie member. * - * See up_restoreusartint where the masking is done. + * See stm32l4serial_restoreusartint where the masking is done. */ #ifdef CONFIG_STM32L4_SERIALBRK_BSDCOMPAT @@ -231,7 +193,7 @@ * Private Types ****************************************************************************/ -struct up_dev_s +struct stm32l4_serial_s { struct uart_dev_s dev; /* Generic UART device */ uint16_t ie; /* Saved interrupt mask bits value */ @@ -302,57 +264,63 @@ struct up_dev_s * Private Function Prototypes ****************************************************************************/ -static void up_set_format(struct uart_dev_s *dev); -static int up_setup(struct uart_dev_s *dev); -static void up_shutdown(struct uart_dev_s *dev); -static int up_attach(struct uart_dev_s *dev); -static void up_detach(struct uart_dev_s *dev); -static int up_interrupt_common(struct up_dev_s *dev); -static int up_ioctl(struct file *filep, int cmd, unsigned long arg); +#ifndef CONFIG_SUPPRESS_UART_CONFIG +static void stm32l4serial_setformat(FAR struct uart_dev_s *dev); +#endif +static int stm32l4serial_setup(FAR struct uart_dev_s *dev); +static void stm32l4serial_shutdown(FAR struct uart_dev_s *dev); +static int stm32l4serial_attach(FAR struct uart_dev_s *dev); +static void stm32l4serial_detach(FAR struct uart_dev_s *dev); +static int up_interrupt_common(FAR struct stm32l4_serial_s *dev); +static int stm32l4serial_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); #ifndef SERIAL_HAVE_ONLY_DMA -static int up_receive(struct uart_dev_s *dev, unsigned int *status); -static void up_rxint(struct uart_dev_s *dev, bool enable); -static bool up_rxavailable(struct uart_dev_s *dev); +static int stm32l4serial_receive(FAR struct uart_dev_s *dev, + FAR unsigned int *status); +static void stm32l4serial_rxint(FAR struct uart_dev_s *dev, bool enable); +static bool stm32l4serial_rxavailable(FAR struct uart_dev_s *dev); #endif #ifdef CONFIG_SERIAL_IFLOWCONTROL -static bool up_rxflowcontrol(struct uart_dev_s *dev, unsigned int nbuffered, - bool upper); +static bool stm32l4serial_rxflowcontrol(FAR struct uart_dev_s *dev, + unsigned int nbuffered, bool upper); #endif -static void up_send(struct uart_dev_s *dev, int ch); -static void up_txint(struct uart_dev_s *dev, bool enable); -static bool up_txready(struct uart_dev_s *dev); +static void stm32l4serial_send(FAR struct uart_dev_s *dev, int ch); +static void stm32l4serial_txint(FAR struct uart_dev_s *dev, bool enable); +static bool stm32l4serial_txready(FAR struct uart_dev_s *dev); #ifdef SERIAL_HAVE_DMA -static int up_dma_setup(struct uart_dev_s *dev); -static void up_dma_shutdown(struct uart_dev_s *dev); -static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status); -static void up_dma_rxint(struct uart_dev_s *dev, bool enable); -static bool up_dma_rxavailable(struct uart_dev_s *dev); +static int stm32l4serial_dmasetup(FAR struct uart_dev_s *dev); +static void stm32l4serial_dmashutdown(FAR struct uart_dev_s *dev); +static int stm32l4serial_dmareceive(FAR struct uart_dev_s *dev, + FAR unsigned int *status); +static void stm32l4serial_dmarxint(FAR struct uart_dev_s *dev, bool enable); +static bool stm32l4serial_dmarxavailable(struct uart_dev_s *dev); -static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg); +static void stm32l4serial_dmarxcallback(DMA_HANDLE handle, uint8_t status, + FAR void *arg); #endif #ifdef CONFIG_PM -static void up_pm_notify(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate); -static int up_pm_prepare(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate); +static void stm32l4serial_pmnotify(FAR struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +static int stm32l4serial_pmprepare(FAR struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); #endif #ifdef CONFIG_STM32L4_USART1 -static int up_interrupt_usart1(int irq, void *context); +static int up_interrupt_usart1(int irq, FAR void *context); #endif #ifdef CONFIG_STM32L4_USART2 -static int up_interrupt_usart2(int irq, void *context); +static int up_interrupt_usart2(int irq, FAR void *context); #endif #ifdef CONFIG_STM32L4_USART3 -static int up_interrupt_usart3(int irq, void *context); +static int up_interrupt_usart3(int irq, FAR void *context); #endif #ifdef CONFIG_STM32L4_UART4 -static int up_interrupt_uart4(int irq, void *context); +static int up_interrupt_uart4(int irq, FAR void *context); #endif #ifdef CONFIG_STM32L4_UART5 -static int up_interrupt_uart5(int irq, void *context); +static int up_interrupt_uart5(int irq, FAR void *context); #endif /**************************************************************************** @@ -362,42 +330,42 @@ static int up_interrupt_uart5(int irq, void *context); #ifndef SERIAL_HAVE_ONLY_DMA static const struct uart_ops_s g_uart_ops = { - .setup = up_setup, - .shutdown = up_shutdown, - .attach = up_attach, - .detach = up_detach, - .ioctl = up_ioctl, - .receive = up_receive, - .rxint = up_rxint, - .rxavailable = up_rxavailable, + .setup = stm32l4serial_setup, + .shutdown = stm32l4serial_shutdown, + .attach = stm32l4serial_attach, + .detach = stm32l4serial_detach, + .ioctl = stm32l4serial_ioctl, + .receive = stm32l4serial_receive, + .rxint = stm32l4serial_rxint, + .rxavailable = stm32l4serial_rxavailable, #ifdef CONFIG_SERIAL_IFLOWCONTROL - .rxflowcontrol = up_rxflowcontrol, + .rxflowcontrol = stm32l4serial_rxflowcontrol, #endif - .send = up_send, - .txint = up_txint, - .txready = up_txready, - .txempty = up_txready, + .send = stm32l4serial_send, + .txint = stm32l4serial_txint, + .txready = stm32l4serial_txready, + .txempty = stm32l4serial_txready, }; #endif #ifdef SERIAL_HAVE_DMA static const struct uart_ops_s g_uart_dma_ops = { - .setup = up_dma_setup, - .shutdown = up_dma_shutdown, - .attach = up_attach, - .detach = up_detach, - .ioctl = up_ioctl, - .receive = up_dma_receive, - .rxint = up_dma_rxint, - .rxavailable = up_dma_rxavailable, + .setup = stm32l4serial_dmasetup, + .shutdown = stm32l4serial_dmashutdown, + .attach = stm32l4serial_attach, + .detach = stm32l4serial_detach, + .ioctl = stm32l4serial_ioctl, + .receive = stm32l4serial_dmareceive, + .rxint = stm32l4serial_dmarxint, + .rxavailable = stm32l4serial_dmarxavailable, #ifdef CONFIG_SERIAL_IFLOWCONTROL - .rxflowcontrol = up_rxflowcontrol, + .rxflowcontrol = stm32l4serial_rxflowcontrol, #endif - .send = up_send, - .txint = up_txint, - .txready = up_txready, - .txempty = up_txready, + .send = stm32l4serial_send, + .txint = stm32l4serial_txint, + .txready = stm32l4serial_txready, + .txempty = stm32l4serial_txready, }; #endif @@ -446,7 +414,7 @@ static char g_uart5rxfifo[RXDMA_BUFFER_SIZE]; /* This describes the state of the STM32 USART1 ports. */ #ifdef CONFIG_STM32L4_USART1 -static struct up_dev_s g_usart1priv = +static struct stm32l4_serial_s g_usart1priv = { .dev = { @@ -508,7 +476,7 @@ static struct up_dev_s g_usart1priv = /* This describes the state of the STM32 USART2 port. */ #ifdef CONFIG_STM32L4_USART2 -static struct up_dev_s g_usart2priv = +static struct stm32l4_serial_s g_usart2priv = { .dev = { @@ -570,7 +538,7 @@ static struct up_dev_s g_usart2priv = /* This describes the state of the STM32 USART3 port. */ #ifdef CONFIG_STM32L4_USART3 -static struct up_dev_s g_usart3priv = +static struct stm32l4_serial_s g_usart3priv = { .dev = { @@ -632,7 +600,7 @@ static struct up_dev_s g_usart3priv = /* This describes the state of the STM32 UART4 port. */ #ifdef CONFIG_STM32L4_UART4 -static struct up_dev_s g_uart4priv = +static struct stm32l4_serial_s g_uart4priv = { .dev = { @@ -698,7 +666,7 @@ static struct up_dev_s g_uart4priv = /* This describes the state of the STM32 UART5 port. */ #ifdef CONFIG_STM32L4_UART5 -static struct up_dev_s g_uart5priv = +static struct stm32l4_serial_s g_uart5priv = { .dev = { @@ -763,7 +731,7 @@ static struct up_dev_s g_uart5priv = /* This table lets us iterate over the configured USARTs */ -static struct up_dev_s * const uart_devs[STM32L4_NUSART] = +FAR static struct stm32l4_serial_s * const uart_devs[STM32L4_NUSART] = { #ifdef CONFIG_STM32L4_USART1 [0] = &g_usart1priv, @@ -785,8 +753,8 @@ static struct up_dev_s * const uart_devs[STM32L4_NUSART] = #ifdef CONFIG_PM static struct pm_callback_s g_serialcb = { - .notify = up_pm_notify, - .prepare = up_pm_prepare, + .notify = stm32l4serial_pmnotify, + .prepare = stm32l4serial_pmprepare, }; #endif @@ -795,28 +763,31 @@ static struct pm_callback_s g_serialcb = ****************************************************************************/ /**************************************************************************** - * Name: up_serialin + * Name: stm32l4serial_getreg ****************************************************************************/ -static inline uint32_t up_serialin(struct up_dev_s *priv, int offset) +static inline uint32_t stm32l4serial_getreg(FAR struct stm32l4_serial_s *priv, + int offset) { return getreg32(priv->usartbase + offset); } /**************************************************************************** - * Name: up_serialout + * Name: stm32l4serial_putreg ****************************************************************************/ -static inline void up_serialout(struct up_dev_s *priv, int offset, uint32_t value) +static inline void stm32l4serial_putreg(FAR struct stm32l4_serial_s *priv, + int offset, uint32_t value) { putreg32(value, priv->usartbase + offset); } /**************************************************************************** - * Name: up_restoreusartint + * Name: stm32l4serial_restoreusartint ****************************************************************************/ -static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie) +static void stm32l4serial_restoreusartint(FAR struct stm32l4_serial_s *priv, + uint16_t ie) { uint32_t cr; @@ -826,22 +797,23 @@ static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie) /* And restore the interrupt state (see the interrupt enable/usage table above) */ - cr = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + cr = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); cr &= ~(USART_CR1_USED_INTS); cr |= (ie & (USART_CR1_USED_INTS)); - up_serialout(priv, STM32L4_USART_CR1_OFFSET, cr); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, cr); - cr = up_serialin(priv, STM32L4_USART_CR3_OFFSET); + cr = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); cr &= ~USART_CR3_EIE; cr |= (ie & USART_CR3_EIE); - up_serialout(priv, STM32L4_USART_CR3_OFFSET, cr); + stm32l4serial_putreg(priv, STM32L4_USART_CR3_OFFSET, cr); } /**************************************************************************** - * Name: up_disableusartint + * Name: stm32l4serial_disableusartint ****************************************************************************/ -static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie) +static inline void stm32l4serial_disableusartint(FAR struct stm32l4_serial_s *priv, + FAR uint16_t *ie) { if (ie) { @@ -866,8 +838,8 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie) * USART_CR3_CTSIE USART_ISR_CTS CTS flag (not used) */ - cr1 = up_serialin(priv, STM32L4_USART_CR1_OFFSET); - cr3 = up_serialin(priv, STM32L4_USART_CR3_OFFSET); + cr1 = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); + cr3 = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); /* Return the current interrupt mask value for the used interrupts. Notice * that this depends on the fact that none of the used interrupt enable bits @@ -879,11 +851,11 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie) /* Disable all interrupts */ - up_restoreusartint(priv, 0); + stm32l4serial_restoreusartint(priv, 0); } /**************************************************************************** - * Name: up_dma_nextrx + * Name: stm32l4serial_dmanextrx * * Description: * Returns the index into the RX FIFO where the DMA will place the next @@ -892,7 +864,7 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static int up_dma_nextrx(struct up_dev_s *priv) +static int stm32l4serial_dmanextrx(FAR struct stm32l4_serial_s *priv) { size_t dmaresidual; @@ -903,7 +875,7 @@ static int up_dma_nextrx(struct up_dev_s *priv) #endif /**************************************************************************** - * Name: up_set_format + * Name: stm32l4serial_setformat * * Description: * Set the serial line format and speed. @@ -911,9 +883,9 @@ static int up_dma_nextrx(struct up_dev_s *priv) ****************************************************************************/ #ifndef CONFIG_SUPPRESS_UART_CONFIG -static void up_set_format(struct uart_dev_s *dev) +static void stm32l4serial_setformat(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; uint32_t regval; /* This first implementation is for U[S]ARTs that support oversampling @@ -942,7 +914,7 @@ static void up_set_format(struct uart_dev_s *dev) /* Use oversamply by 8 only if the divisor is small. But what is small? */ - cr1 = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + cr1 = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); if (usartdiv8 > 100) { /* Use usartdiv16 */ @@ -966,12 +938,12 @@ static void up_set_format(struct uart_dev_s *dev) cr1 |= USART_CR1_OVER8; } - up_serialout(priv, STM32L4_USART_CR1_OFFSET, cr1); - up_serialout(priv, STM32L4_USART_BRR_OFFSET, brr); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, cr1); + stm32l4serial_putreg(priv, STM32L4_USART_BRR_OFFSET, brr); /* Configure parity mode */ - regval = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); regval &= ~(USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0 | USART_CR1_M1); if (priv->parity == 1) /* Odd parity */ @@ -1008,11 +980,11 @@ static void up_set_format(struct uart_dev_s *dev) * 1 start, 8 data (no parity), n stop. */ - up_serialout(priv, STM32L4_USART_CR1_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, regval); /* Configure STOP bits */ - regval = up_serialin(priv, STM32L4_USART_CR2_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR2_OFFSET); regval &= ~(USART_CR2_STOP_MASK); if (priv->stopbits2) @@ -1020,11 +992,11 @@ static void up_set_format(struct uart_dev_s *dev) regval |= USART_CR2_STOP2; } - up_serialout(priv, STM32L4_USART_CR2_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR2_OFFSET, regval); /* Configure hardware flow control */ - regval = up_serialin(priv, STM32L4_USART_CR3_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); regval &= ~(USART_CR3_CTSE | USART_CR3_RTSE); #if defined(CONFIG_SERIAL_IFLOWCONTROL) && !defined(CONFIG_STM32L4_FLOWCONTROL_BROKEN) @@ -1041,12 +1013,12 @@ static void up_set_format(struct uart_dev_s *dev) } #endif - up_serialout(priv, STM32L4_USART_CR3_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR3_OFFSET, regval); } #endif /* CONFIG_SUPPRESS_UART_CONFIG */ /**************************************************************************** - * Name: up_set_apb_clock + * Name: stm32l4serial_setapbclock * * Description: * Enable or disable APB clock for the USART peripheral @@ -1057,9 +1029,9 @@ static void up_set_format(struct uart_dev_s *dev) * ****************************************************************************/ -static void up_set_apb_clock(struct uart_dev_s *dev, bool on) +static void stm32l4serial_setapbclock(FAR struct uart_dev_s *dev, bool on) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; uint32_t rcc_en; uint32_t regaddr; @@ -1114,7 +1086,7 @@ static void up_set_apb_clock(struct uart_dev_s *dev, bool on) } /**************************************************************************** - * Name: up_setup + * Name: stm32l4serial_setup * * Description: * Configure the USART baud, bits, parity, etc. This method is called the @@ -1122,9 +1094,9 @@ static void up_set_apb_clock(struct uart_dev_s *dev, bool on) * ****************************************************************************/ -static int up_setup(struct uart_dev_s *dev) +static int stm32l4serial_setup(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; #ifndef CONFIG_SUPPRESS_UART_CONFIG uint32_t regval; @@ -1135,7 +1107,7 @@ static int up_setup(struct uart_dev_s *dev) /* Enable USART APB1/2 clock */ - up_set_apb_clock(dev, true); + stm32l4serial_setapbclock(dev, true); /* Configure pins for USART use */ @@ -1174,7 +1146,7 @@ static int up_setup(struct uart_dev_s *dev) /* Configure CR2 */ /* Clear STOP, CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */ - regval = up_serialin(priv, STM32L4_USART_CR2_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR2_OFFSET); regval &= ~(USART_CR2_STOP_MASK | USART_CR2_CLKEN | USART_CR2_CPOL | USART_CR2_CPHA | USART_CR2_LBCL | USART_CR2_LBDIE); @@ -1185,33 +1157,34 @@ static int up_setup(struct uart_dev_s *dev) regval |= USART_CR2_STOP2; } - up_serialout(priv, STM32L4_USART_CR2_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR2_OFFSET, regval); /* Configure CR1 */ /* Clear TE, REm and all interrupt enable bits */ - regval = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); regval &= ~(USART_CR1_TE | USART_CR1_RE | USART_CR1_ALLINTS); - up_serialout(priv, STM32L4_USART_CR1_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, regval); /* Configure CR3 */ /* Clear CTSE, RTSE, and all interrupt enable bits */ - regval = up_serialin(priv, STM32L4_USART_CR3_OFFSET); - regval &= ~(USART_CR3_CTSIE | USART_CR3_CTSE | USART_CR3_RTSE | USART_CR3_EIE); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); + regval &= ~(USART_CR3_CTSIE | USART_CR3_CTSE | USART_CR3_RTSE | + USART_CR3_EIE); - up_serialout(priv, STM32L4_USART_CR3_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR3_OFFSET, regval); /* Configure the USART line format and speed. */ - up_set_format(dev); + stm32l4serial_setformat(dev); /* Enable Rx, Tx, and the USART */ - regval = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); regval |= (USART_CR1_UE | USART_CR1_TE | USART_CR1_RE); - up_serialout(priv, STM32L4_USART_CR1_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, regval); #endif /* CONFIG_SUPPRESS_UART_CONFIG */ @@ -1222,7 +1195,7 @@ static int up_setup(struct uart_dev_s *dev) } /**************************************************************************** - * Name: up_dma_setup + * Name: stm32l4serial_dmasetup * * Description: * Configure the USART baud, bits, parity, etc. This method is called the @@ -1231,9 +1204,9 @@ static int up_setup(struct uart_dev_s *dev) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static int up_dma_setup(struct uart_dev_s *dev) +static int stm32l4serial_dmasetup(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; int result; uint32_t regval; @@ -1241,7 +1214,7 @@ static int up_dma_setup(struct uart_dev_s *dev) if (!dev->isconsole) { - result = up_setup(dev); + result = stm32l4serial_setup(dev); if (result != OK) { return result; @@ -1283,9 +1256,9 @@ static int up_dma_setup(struct uart_dev_s *dev) /* Enable receive DMA for the UART */ - regval = up_serialin(priv, STM32L4_USART_CR3_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); regval |= USART_CR3_DMAR; - up_serialout(priv, STM32L4_USART_CR3_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR3_OFFSET, regval); #ifdef CONFIG_SERIAL_IFLOWCONTROL if (priv->iflow) @@ -1295,7 +1268,8 @@ static int up_dma_setup(struct uart_dev_s *dev) * in and DMA transfer is stopped. */ - stm32l4_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, false); + stm32l4_dmastart(priv->rxdma, stm32l4serial_dmarxcallback, + (void *)priv, false); } else #endif @@ -1305,7 +1279,8 @@ static int up_dma_setup(struct uart_dev_s *dev) * worth of time to claim bytes before they are overwritten. */ - stm32l4_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, true); + stm32l4_dmastart(priv->rxdma, stm32l4serial_dmarxcallback, + (void *)priv, true); } return OK; @@ -1313,7 +1288,7 @@ static int up_dma_setup(struct uart_dev_s *dev) #endif /**************************************************************************** - * Name: up_shutdown + * Name: stm32l4serial_shutdown * * Description: * Disable the USART. This method is called when the serial @@ -1321,24 +1296,24 @@ static int up_dma_setup(struct uart_dev_s *dev) * ****************************************************************************/ -static void up_shutdown(struct uart_dev_s *dev) +static void stm32l4serial_shutdown(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; uint32_t regval; /* Disable all interrupts */ - up_disableusartint(priv, NULL); + stm32l4serial_disableusartint(priv, NULL); /* Disable USART APB1/2 clock */ - up_set_apb_clock(dev, false); + stm32l4serial_setapbclock(dev, false); /* Disable Rx, Tx, and the UART */ - regval = up_serialin(priv, STM32L4_USART_CR1_OFFSET); + regval = stm32l4serial_getreg(priv, STM32L4_USART_CR1_OFFSET); regval &= ~(USART_CR1_UE | USART_CR1_TE | USART_CR1_RE); - up_serialout(priv, STM32L4_USART_CR1_OFFSET, regval); + stm32l4serial_putreg(priv, STM32L4_USART_CR1_OFFSET, regval); /* Release pins. "If the serial-attached device is powered down, the TX * pin causes back-powering, potentially confusing the device to the point @@ -1374,7 +1349,7 @@ static void up_shutdown(struct uart_dev_s *dev) } /**************************************************************************** - * Name: up_dma_shutdown + * Name: stm32l4serial_dmashutdown * * Description: * Disable the USART. This method is called when the serial @@ -1383,13 +1358,13 @@ static void up_shutdown(struct uart_dev_s *dev) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static void up_dma_shutdown(struct uart_dev_s *dev) +static void stm32l4serial_dmashutdown(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; /* Perform the normal UART shutdown */ - up_shutdown(dev); + stm32l4serial_shutdown(dev); /* Stop the DMA channel */ @@ -1403,7 +1378,7 @@ static void up_dma_shutdown(struct uart_dev_s *dev) #endif /**************************************************************************** - * Name: up_attach + * Name: stm32l4serial_attach * * Description: * Configure the USART to operation in interrupt driven mode. This method is @@ -1417,9 +1392,9 @@ static void up_dma_shutdown(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_attach(struct uart_dev_s *dev) +static int stm32l4serial_attach(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; int ret; /* Attach and enable the IRQ */ @@ -1437,7 +1412,7 @@ static int up_attach(struct uart_dev_s *dev) } /**************************************************************************** - * Name: up_detach + * Name: stm32l4serial_detach * * Description: * Detach USART interrupts. This method is called when the serial port is @@ -1446,9 +1421,9 @@ static int up_attach(struct uart_dev_s *dev) * ****************************************************************************/ -static void up_detach(struct uart_dev_s *dev) +static void stm32l4serial_detach(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; up_disable_irq(priv->irq); irq_detach(priv->irq); } @@ -1465,7 +1440,7 @@ static void up_detach(struct uart_dev_s *dev) * ****************************************************************************/ -static int up_interrupt_common(struct up_dev_s *priv) +static int up_interrupt_common(FAR struct stm32l4_serial_s *priv) { int passes; bool handled; @@ -1487,7 +1462,7 @@ static int up_interrupt_common(struct up_dev_s *priv) /* Get the masked USART status word. */ - priv->sr = up_serialin(priv, STM32L4_USART_ISR_OFFSET); + priv->sr = stm32l4serial_getreg(priv, STM32L4_USART_ISR_OFFSET); /* USART interrupts: * @@ -1522,7 +1497,7 @@ static int up_interrupt_common(struct up_dev_s *priv) (priv->ie & USART_CR1_TXEIE) == 0) { stm32l4_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity); - up_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE); + stm32l4serial_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE); } #endif @@ -1548,8 +1523,8 @@ static int up_interrupt_common(struct up_dev_s *priv) * interrupt clear register (ICR). */ - up_serialout(priv, STM32L4_USART_ICR_OFFSET, - (USART_ICR_NCF | USART_ICR_ORECF | USART_ICR_FECF)); + stm32l4serial_putreg(priv, STM32L4_USART_ICR_OFFSET, + (USART_ICR_NCF | USART_ICR_ORECF | USART_ICR_FECF)); } /* Handle outgoing, transmit bytes */ @@ -1567,22 +1542,22 @@ static int up_interrupt_common(struct up_dev_s *priv) } /**************************************************************************** - * Name: up_ioctl + * Name: stm32l4serial_ioctl * * Description: * All ioctl calls will be routed through this method * ****************************************************************************/ -static int up_ioctl(struct file *filep, int cmd, unsigned long arg) +static int stm32l4serial_ioctl(FAR struct file *filep, int cmd, + unsigned long arg) { -#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) \ - || defined(CONFIG_STM32F7_SERIALBRK_BSDCOMPAT) - struct inode *inode = filep->f_inode; - struct uart_dev_s *dev = inode->i_private; +#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_SERIAL_TIOCSERGSTRUCT) + FAR struct inode *inode = filep->f_inode; + FAR struct uart_dev_s *dev = inode->i_private; #endif -#if defined(CONFIG_SERIAL_TERMIOS) || defined(CONFIG_STM32F7_SERIALBRK_BSDCOMPAT) - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; +#if defined(CONFIG_SERIAL_TERMIOS) + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; #endif int ret = OK; @@ -1591,40 +1566,29 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) #ifdef CONFIG_SERIAL_TIOCSERGSTRUCT case TIOCSERGSTRUCT: { - struct up_dev_s *user = (struct up_dev_s *)arg; + FAR struct stm32l4_serial_s *user = (FAR struct stm32l4_serial_s *)arg; if (!user) { ret = -EINVAL; } else { - memcpy(user, dev, sizeof(struct up_dev_s)); + memcpy(user, dev, sizeof(struct stm32l4_serial_s)); } } break; #endif #ifdef CONFIG_STM32L4_USART_SINGLEWIRE +#warning please review the potential use of ALTERNATE_FUNCTION_OPENDRAIN case TIOCSSINGLEWIRE: { /* Change the TX port to be open-drain/push-pull and enable/disable * half-duplex mode. */ - uint32_t cr = up_serialin(priv, STM32L4_USART_CR3_OFFSET); + uint32_t cr = stm32l4serial_getreg(priv, STM32L4_USART_CR3_OFFSET); -#if defined(CONFIG_STM32L4_STM32F10XX) - if (arg == SER_SINGLEWIRE_ENABLED) - { - stm32l4_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) | GPIO_CNF_AFOD); - cr |= USART_CR3_HDSEL; - } - else - { - stm32l4_configgpio((priv->tx_gpio & ~(GPIO_CNF_MASK)) | GPIO_CNF_AFPP); - cr &= ~USART_CR3_HDSEL; - } -#else if (arg == SER_SINGLEWIRE_ENABLED) { stm32l4_configgpio(priv->tx_gpio | GPIO_OPENDRAIN); @@ -1635,9 +1599,8 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) stm32l4_configgpio(priv->tx_gpio | GPIO_PUSHPULL); cr &= ~USART_CR3_HDSEL; } -#endif - up_serialout(priv, STM32L4_USART_CR3_OFFSET, cr); + stm32l4serial_putreg(priv, STM32L4_USART_CR3_OFFSET, cr); } break; #endif @@ -1645,7 +1608,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) #ifdef CONFIG_SERIAL_TERMIOS case TCGETS: { - struct termios *termiosp = (struct termios *)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -1677,7 +1640,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) case TCSETS: { - struct termios *termiosp = (struct termios *)arg; + FAR struct termios *termiosp = (FAR struct termios *)arg; if (!termiosp) { @@ -1732,7 +1695,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) * TCSADRAIN / TCSAFLUSH */ - up_set_format(dev); + stm32l4serial_setformat(dev); } break; #endif /* CONFIG_SERIAL_TERMIOS */ @@ -1750,7 +1713,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) priv->ie |= USART_CR1_IE_BREAK_INPROGRESS; - up_txint(dev, false); + stm32l4serial_txint(dev, false); /* Configure TX as a GPIO output pin and Send a break signal*/ @@ -1775,7 +1738,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) /* Enable further tx activity */ - up_txint(dev, true); + stm32l4serial_txint(dev, true); leave_critical_section(flags); } @@ -1787,8 +1750,8 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) irqstate_t flags; flags = enter_critical_section(); - cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET); - up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 | USART_CR1_SBK); + cr1 = stm32l4serial_getreg(priv, STM32_USART_CR1_OFFSET); + stm32l4serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 | USART_CR1_SBK); leave_critical_section(flags); } break; @@ -1799,8 +1762,8 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) irqstate_t flags; flags = enter_critical_section(); - cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET); - up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 & ~USART_CR1_SBK); + cr1 = stm32l4serial_getreg(priv, STM32_USART_CR1_OFFSET); + stm32l4serial_putreg(priv, STM32_USART_CR1_OFFSET, cr1 & ~USART_CR1_SBK); leave_critical_section(flags); } break; @@ -1816,7 +1779,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) } /**************************************************************************** - * Name: up_receive + * Name: stm32l4serial_receive * * Description: * Called (usually) from the interrupt level to receive one @@ -1826,14 +1789,15 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg) ****************************************************************************/ #ifndef SERIAL_HAVE_ONLY_DMA -static int up_receive(struct uart_dev_s *dev, unsigned int *status) +static int stm32l4serial_receive(FAR struct uart_dev_s *dev, + FAR unsigned int *status) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; uint32_t rdr; /* Get the Rx byte */ - rdr = up_serialin(priv, STM32L4_USART_RDR_OFFSET); + rdr = stm32l4serial_getreg(priv, STM32L4_USART_RDR_OFFSET); /* Get the Rx byte plux error information. Return those in status */ @@ -1847,7 +1811,7 @@ static int up_receive(struct uart_dev_s *dev, unsigned int *status) #endif /**************************************************************************** - * Name: up_rxint + * Name: stm32l4serial_rxint * * Description: * Call to enable or disable RX interrupts @@ -1855,9 +1819,9 @@ static int up_receive(struct uart_dev_s *dev, unsigned int *status) ****************************************************************************/ #ifndef SERIAL_HAVE_ONLY_DMA -static void up_rxint(struct uart_dev_s *dev, bool enable) +static void stm32l4serial_rxint(FAR struct uart_dev_s *dev, bool enable) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; irqstate_t flags; uint16_t ie; @@ -1899,13 +1863,13 @@ static void up_rxint(struct uart_dev_s *dev, bool enable) /* Then set the new interrupt state */ - up_restoreusartint(priv, ie); + stm32l4serial_restoreusartint(priv, ie); leave_critical_section(flags); } #endif /**************************************************************************** - * Name: up_rxavailable + * Name: stm32l4serial_rxavailable * * Description: * Return true if the receive register is not empty @@ -1913,15 +1877,15 @@ static void up_rxint(struct uart_dev_s *dev, bool enable) ****************************************************************************/ #ifndef SERIAL_HAVE_ONLY_DMA -static bool up_rxavailable(struct uart_dev_s *dev) +static bool stm32l4serial_rxavailable(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; - return ((up_serialin(priv, STM32L4_USART_ISR_OFFSET) & USART_ISR_RXNE) != 0); + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; + return ((stm32l4serial_getreg(priv, STM32L4_USART_ISR_OFFSET) & USART_ISR_RXNE) != 0); } #endif /**************************************************************************** - * Name: up_rxflowcontrol + * Name: stm32l4serial_rxflowcontrol * * Description: * Called when Rx buffer is full (or exceeds configured watermark levels @@ -1944,10 +1908,10 @@ static bool up_rxavailable(struct uart_dev_s *dev) ****************************************************************************/ #ifdef CONFIG_SERIAL_IFLOWCONTROL -static bool up_rxflowcontrol(struct uart_dev_s *dev, - unsigned int nbuffered, bool upper) +static bool stm32l4serial_rxflowcontrol(FAR struct uart_dev_s *dev, + unsigned int nbuffered, bool upper) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; #if defined(CONFIG_SERIAL_IFLOWCONTROL_WATERMARKS) && \ defined(CONFIG_STM32L4_FLOWCONTROL_BROKEN) @@ -2001,7 +1965,7 @@ static bool up_rxflowcontrol(struct uart_dev_s *dev, #endif /**************************************************************************** - * Name: up_dma_receive + * Name: stm32l4serial_dmareceive * * Description: * Called (usually) from the interrupt level to receive one @@ -2011,12 +1975,13 @@ static bool up_rxflowcontrol(struct uart_dev_s *dev, ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status) +static int stm32l4serial_dmareceive(FAR struct uart_dev_s *dev, + FAR unsigned int *status) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; int c = 0; - if (up_dma_nextrx(priv) != priv->rxdmanext) + if (stm32l4serial_dmanextrx(priv) != priv->rxdmanext) { c = priv->rxfifo[priv->rxdmanext]; @@ -2043,7 +2008,7 @@ static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status) #endif /**************************************************************************** - * Name: up_dma_reenable + * Name: stm32l4serial_dmareenable * * Description: * Call to re-enable RX DMA. @@ -2051,7 +2016,7 @@ static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status) ****************************************************************************/ #if defined(SERIAL_HAVE_DMA) && defined(CONFIG_SERIAL_IFLOWCONTROL) -static void up_dma_reenable(struct up_dev_s *priv) +static void stm32l4serial_dmareenable(FAR struct stm32l4_serial_s *priv) { /* Configure for non-circular DMA reception into the RX fifo */ @@ -2072,12 +2037,13 @@ static void up_dma_reenable(struct up_dev_s *priv) * DMA transfer is stopped. */ - stm32l4_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, false); + stm32l4_dmastart(priv->rxdma, stm32l4serial_dmarxcallback, (FAR void *)priv, + false); } #endif /**************************************************************************** - * Name: up_dma_rxint + * Name: stm32l4serial_dmarxint * * Description: * Call to enable or disable RX interrupts @@ -2085,9 +2051,9 @@ static void up_dma_reenable(struct up_dev_s *priv) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static void up_dma_rxint(struct uart_dev_s *dev, bool enable) +static void stm32l4serial_dmarxint(FAR struct uart_dev_s *dev, bool enable) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; /* En/disable DMA reception. * @@ -2104,14 +2070,14 @@ static void up_dma_rxint(struct uart_dev_s *dev, bool enable) { /* Re-enable RX DMA. */ - up_dma_reenable(priv); + stm32l4serial_dmareenable(priv); } #endif } #endif /**************************************************************************** - * Name: up_dma_rxavailable + * Name: stm32l4serial_dmarxavailable * * Description: * Return true if the receive register is not empty @@ -2119,29 +2085,29 @@ static void up_dma_rxint(struct uart_dev_s *dev, bool enable) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static bool up_dma_rxavailable(struct uart_dev_s *dev) +static bool stm32l4serial_dmarxavailable(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; /* Compare our receive pointer to the current DMA pointer, if they * do not match, then there are bytes to be received. */ - return (up_dma_nextrx(priv) != priv->rxdmanext); + return (stm32l4serial_dmanextrx(priv) != priv->rxdmanext); } #endif /**************************************************************************** - * Name: up_send + * Name: stm32l4serial_send * * Description: * This method will send one byte on the USART * ****************************************************************************/ -static void up_send(struct uart_dev_s *dev, int ch) +static void stm32l4serial_send(FAR struct uart_dev_s *dev, int ch) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; #ifdef HAVE_RS485 if (priv->rs485_dir_gpio != 0) @@ -2150,20 +2116,20 @@ static void up_send(struct uart_dev_s *dev, int ch) } #endif - up_serialout(priv, STM32L4_USART_TDR_OFFSET, (uint32_t)ch); + stm32l4serial_putreg(priv, STM32L4_USART_TDR_OFFSET, (uint32_t)ch); } /**************************************************************************** - * Name: up_txint + * Name: stm32l4serial_txint * * Description: * Call to enable or disable TX interrupts * ****************************************************************************/ -static void up_txint(struct uart_dev_s *dev, bool enable) +static void stm32l4serial_txint(FAR struct uart_dev_s *dev, bool enable) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; irqstate_t flags; /* USART transmit interrupts: @@ -2201,7 +2167,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable) } # endif - up_restoreusartint(priv, ie); + stm32l4serial_restoreusartint(priv, ie); /* Fake a TX interrupt here by just calling uart_xmitchars() with * interrupts disabled (note this may recurse). @@ -2214,24 +2180,24 @@ static void up_txint(struct uart_dev_s *dev, bool enable) { /* Disable the TX interrupt */ - up_restoreusartint(priv, priv->ie & ~USART_CR1_TXEIE); + stm32l4serial_restoreusartint(priv, priv->ie & ~USART_CR1_TXEIE); } leave_critical_section(flags); } /**************************************************************************** - * Name: up_txready + * Name: stm32l4serial_txready * * Description: * Return true if the transmit data register is empty * ****************************************************************************/ -static bool up_txready(struct uart_dev_s *dev) +static bool stm32l4serial_txready(FAR struct uart_dev_s *dev) { - struct up_dev_s *priv = (struct up_dev_s *)dev->priv; - return ((up_serialin(priv, STM32L4_USART_ISR_OFFSET) & USART_ISR_TXE) != 0); + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)dev->priv; + return ((stm32l4serial_getreg(priv, STM32L4_USART_ISR_OFFSET) & USART_ISR_TXE) != 0); } /**************************************************************************** @@ -2243,42 +2209,42 @@ static bool up_txready(struct uart_dev_s *dev) ****************************************************************************/ #ifdef CONFIG_STM32L4_USART1 -static int up_interrupt_usart1(int irq, void *context) +static int up_interrupt_usart1(int irq, FAR void *context) { return up_interrupt_common(&g_usart1priv); } #endif #ifdef CONFIG_STM32L4_USART2 -static int up_interrupt_usart2(int irq, void *context) +static int up_interrupt_usart2(int irq, FAR void *context) { return up_interrupt_common(&g_usart2priv); } #endif #ifdef CONFIG_STM32L4_USART3 -static int up_interrupt_usart3(int irq, void *context) +static int up_interrupt_usart3(int irq, FAR void *context) { return up_interrupt_common(&g_usart3priv); } #endif #ifdef CONFIG_STM32L4_UART4 -static int up_interrupt_uart4(int irq, void *context) +static int up_interrupt_uart4(int irq, FAR void *context) { return up_interrupt_common(&g_uart4priv); } #endif #ifdef CONFIG_STM32L4_UART5 -static int up_interrupt_uart5(int irq, void *context) +static int up_interrupt_uart5(int irq, FAR void *context) { return up_interrupt_common(&g_uart5priv); } #endif /**************************************************************************** - * Name: up_dma_rxcallback + * Name: stm32l4serial_dmarxcallback * * Description: * This function checks the current DMA state and calls the generic @@ -2287,11 +2253,12 @@ static int up_interrupt_uart5(int irq, void *context) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg) +static void stm32l4serial_dmarxcallback(DMA_HANDLE handle, uint8_t status, + FAR void *arg) { - struct up_dev_s *priv = (struct up_dev_s *)arg; + FAR struct stm32l4_serial_s *priv = (FAR struct stm32l4_serial_s *)arg; - if (priv->rxenable && up_dma_rxavailable(&priv->dev)) + if (priv->rxenable && stm32l4serial_dmarxavailable(&priv->dev)) { uart_recvchars(&priv->dev); @@ -2301,7 +2268,7 @@ static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg) { /* Re-enable RX DMA. */ - up_dma_reenable(priv); + stm32l4serial_dmareenable(priv); } #endif } @@ -2309,7 +2276,7 @@ static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg) #endif /**************************************************************************** - * Name: up_pm_notify + * Name: stm32l4serial_pmnotify * * Description: * Notify the driver of new power state. This callback is called after @@ -2331,8 +2298,8 @@ static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg) ****************************************************************************/ #ifdef CONFIG_PM -static void up_pm_notify(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate) +static void stm32l4serial_pmnotify(FAR struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) { switch (pmstate) { @@ -2372,7 +2339,7 @@ static void up_pm_notify(struct pm_callback_s *cb, int domain, #endif /**************************************************************************** - * Name: up_pm_prepare + * Name: stm32l4serial_pmprepare * * Description: * Request the driver to prepare for a new power state. This is a warning @@ -2405,8 +2372,8 @@ static void up_pm_notify(struct pm_callback_s *cb, int domain, ****************************************************************************/ #ifdef CONFIG_PM -static int up_pm_prepare(struct pm_callback_s *cb, int domain, - enum pm_state_e pmstate) +static int stm32l4serial_pmprepare(FAR struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) { /* Logic to prepare for a reduced power state goes here. */ @@ -2428,7 +2395,7 @@ static int up_pm_prepare(struct pm_callback_s *cb, int domain, * Description: * Performs the low level USART initialization early in debug so that the * serial console will be available during bootup. This must be called - * before up_serialinit. + * before stm32l4serial_getregit. * ****************************************************************************/ @@ -2444,21 +2411,21 @@ void up_earlyserialinit(void) { if (uart_devs[i]) { - up_disableusartint(uart_devs[i], NULL); + stm32l4serial_disableusartint(uart_devs[i], NULL); } } /* Configure whichever one is the console */ #if CONSOLE_UART > 0 - up_setup(&uart_devs[CONSOLE_UART - 1]->dev); + stm32l4serial_setup(&uart_devs[CONSOLE_UART - 1]->dev); #endif #endif /* HAVE UART */ } #endif /**************************************************************************** - * Name: up_serialinit + * Name: stm32l4serial_getregit * * Description: * Register serial console and serial ports. This assumes @@ -2501,7 +2468,7 @@ void up_serialinit(void) #ifdef SERIAL_HAVE_CONSOLE_DMA /* If we need to re-initialise the console to enable DMA do that here. */ - up_dma_setup(&uart_devs[CONSOLE_UART - 1]->dev); + stm32l4serial_dmasetup(&uart_devs[CONSOLE_UART - 1]->dev); #endif #endif /* CONSOLE_UART > 0 */ @@ -2536,7 +2503,7 @@ void up_serialinit(void) } /**************************************************************************** - * Name: stm32l4_serial_dma_poll + * Name: stm32l4serial_dmapoll * * Description: * Checks receive DMA buffers for received bytes that have not accumulated @@ -2547,7 +2514,7 @@ void up_serialinit(void) ****************************************************************************/ #ifdef SERIAL_HAVE_DMA -void stm32l4_serial_dma_poll(void) +void stm32l4serial_dmapoll(void) { irqstate_t flags; @@ -2556,35 +2523,35 @@ void stm32l4_serial_dma_poll(void) #ifdef CONFIG_USART1_RXDMA if (g_usart1priv.rxdma != NULL) { - up_dma_rxcallback(g_usart1priv.rxdma, 0, &g_usart1priv); + stm32l4serial_dmarxcallback(g_usart1priv.rxdma, 0, &g_usart1priv); } #endif #ifdef CONFIG_USART2_RXDMA if (g_usart2priv.rxdma != NULL) { - up_dma_rxcallback(g_usart2priv.rxdma, 0, &g_usart2priv); + stm32l4serial_dmarxcallback(g_usart2priv.rxdma, 0, &g_usart2priv); } #endif #ifdef CONFIG_USART3_RXDMA if (g_usart3priv.rxdma != NULL) { - up_dma_rxcallback(g_usart3priv.rxdma, 0, &g_usart3priv); + stm32l4serial_dmarxcallback(g_usart3priv.rxdma, 0, &g_usart3priv); } #endif #ifdef CONFIG_UART4_RXDMA if (g_uart4priv.rxdma != NULL) { - up_dma_rxcallback(g_uart4priv.rxdma, 0, &g_uart4priv); + stm32l4serial_dmarxcallback(g_uart4priv.rxdma, 0, &g_uart4priv); } #endif #ifdef CONFIG_UART5_RXDMA if (g_uart5priv.rxdma != NULL) { - up_dma_rxcallback(g_uart5priv.rxdma, 0, &g_uart5priv); + stm32l4serial_dmarxcallback(g_uart5priv.rxdma, 0, &g_uart5priv); } #endif @@ -2603,10 +2570,10 @@ void stm32l4_serial_dma_poll(void) int up_putc(int ch) { #if CONSOLE_UART > 0 - struct up_dev_s *priv = uart_devs[CONSOLE_UART - 1]; + struct stm32l4_serial_s *priv = uart_devs[CONSOLE_UART - 1]; uint16_t ie; - up_disableusartint(priv, &ie); + stm32l4serial_disableusartint(priv, &ie); /* Check for LF */ @@ -2618,7 +2585,7 @@ int up_putc(int ch) } up_lowputc(ch); - up_restoreusartint(priv, ie); + stm32l4serial_restoreusartint(priv, ie); #endif return ch; } diff --git a/configs/freedom-k64f/README.txt b/configs/freedom-k64f/README.txt index cfdac464d1..0aaeb99a9c 100644 --- a/configs/freedom-k64f/README.txt +++ b/configs/freedom-k64f/README.txt @@ -10,7 +10,7 @@ Contents o Freedom K64F Features o Serial Console o LEDs and Buttons - o Ethernet + o Networking Support o Development Environment o GNU Toolchain Options o Freedom K64F Configuration Options @@ -129,40 +129,286 @@ LEDs and Buttons SW2 PTC6/SPI0_SOUT/PD0_EXTRG/I2S0_RX_BCLK/FB_AD9/I2S0_MCLK/LLWU_P10 SW3 PTA4/FTM0_CH1/NMI_b/LLWU_P3 -Ethernet -======== +Networking Support +================== + Ethernet MAC/KSZ8081 PHY + ------------------------ ------------ ----------------- -------------------------------------------- KSZ8081 Board Signal(s) K64F Pin - Pin Signal Function + Pin Signal Function pinmux Name --- -------- ----------------- -------------------------------------------- - 1 VDD_1V2 VDDPLL_1.2V --- - 2 VDDA_3V3 VDDA_ENET --- - 3 RXM ENET1_RX- --- - 4 RXP ENET1_RX+ --- - 5 TXM ENET1_TX- --- - 6 TXP ENET1_TX+ --- - 7 X0 RMII_XTAL0 --- - 8 XI RMII_XTAL1 --- - 9 REXT --- ---, Apparently not connected - 10 MDIO RMII0_MDIO PTB0/RMII0_MDIO - 11 MDC RMII0_MDC PTB1/RMII0_MDC - 12 RXD1 RMII0_RXD_1 PTA12/RMII0_RXD1 - 13 RXD0 RMII0_RXD_0 PTA13/RMII0_RXD0 - 14 VDDIO VDDIO_ENET --- - 15 CRS_DIV PTA14/RMII0_CRS_DV - 16 REF_CLK RMII_RXCLK PTA18/EXTAL0, PHY clock input - 17 RXER RMII0_RXER PTA5/RMII0_RXER - 18 INTRP RMII0_INT_B, J14 Pin 2, Apparently not available unless jumpered - PHY_INT_1 - 19 TXEN RMII0_TXEN PTA15/RMII0_TXEN - 20 TXD0 RMII0_TXD_0 PTA16/RMII0_TXD0 - 21 TXD1 RMII0_TXD_1 PTA17/RMII0_TXD1 - 22 GND1 --- --- - 24 nRST PHY_RST_B --- - 25 GND2 --- --- + 1 VDD_1V2 VDDPLL_1.2V --- --- + 2 VDDA_3V3 VDDA_ENET --- --- + 3 RXM ENET1_RX- --- --- + 4 RXP ENET1_RX+ --- --- + 5 TXM ENET1_TX- --- --- + 6 TXP ENET1_TX+ --- --- + 7 X0 RMII_XTAL0 --- --- + 8 XI RMII_XTAL1 --- --- + 9 REXT --- ---, Apparently not connected --- + 10 MDIO RMII0_MDIO PTB0/RMII0_MDIO PIN_RMII0_MDIO + 11 MDC RMII0_MDC PTB1/RMII0_MDC PIN_RMII0_MDC + 12 RXD1 RMII0_RXD_1 PTA12/RMII0_RXD1 PIN_RMII0_RXD1 + 13 RXD0 RMII0_RXD_0 PTA13/RMII0_RXD0 PIN_RMII0_RXD0 + 14 VDDIO VDDIO_ENET --- --- + 15 CRS_DIV PTA14/RMII0_CRS_DV PIN_RMII0_CRS_DV + 16 REF_CLK RMII_RXCLK PTA18/EXTAL0, PHY clock input --- + 17 RXER RMII0_RXER PTA5/RMII0_RXER PIN_RMII0_RXER + 18 INTRP RMII0_INT_B, J14 Pin 2, Apparently not --- + PHY_INT_1 available unless jumpered + 19 TXEN RMII0_TXEN PTA15/RMII0_TXEN PIN_RMII0_TXEN + 20 TXD0 RMII0_TXD_0 PTA16/RMII0_TXD0 PIN_RMII0_TXD0 + 21 TXD1 RMII0_TXD_1 PTA17/RMII0_TXD1 PIN_RMII0_TXD1 + 22 GND1 --- --- --- + 24 nRST PHY_RST_B --- --- + 25 GND2 --- --- --- --- -------- ----------------- -------------------------------------------- + No external pullup is available on MDIO signal when MK64FN1M0VLL12 MCU is + requests status of the Ethernet link connection. Internal pullup is required + when port configuration for MDIO signal is enabled: + + CONFIG_KINETIS_ENET_MDIOPULLUP=y + + Networking support via the can be added to NSH by selecting the following + configuration options. + + Selecting the EMAC peripheral + ----------------------------- + + System Type -> Kinetis Peripheral Support + CONFIG_KINETIS_ENET=y : Enable the EThernet MAC peripheral + + System Type -> Ethernet Configuration + CONFIG_KINETIS_ENETNETHIFS=1 + CONFIG_KINETIS_ENETNRXBUFFERS=6 + CONFIG_KINETIS_ENETNTXBUFFERS=2 + CONFIG_KINETIS_ENET_MDIOPULLUP=y + + Networking Support + CONFIG_NET=y : Enable Neworking + CONFIG_NET_ETHERNET=y : Support Ethernet data link + CONFIG_NET_NOINTS=y : Should operative at non-interrupt level + CONFIG_NET_SOCKOPTS=y : Enable socket operations + CONFIG_NET_MULTIBUFFER=y : Multi-packet buffer option required + CONFIG_NET_ETH_MTU=590 : Maximum packet size (MTU) 1518 is more standard + CONFIG_NET_ETH_TCP_RECVWNDO=536 : Should be the same as CONFIG_NET_ETH_MTU + CONFIG_NET_ARP=y : Enable ARP + CONFIG_NET_ARPTAB_SIZE=16 : ARP table size + CONFIG_NET_ARP_IPIN=y : Enable ARP address harvesting + CONFIG_NET_ARP_SEND=y : Send ARP request before sending data + CONFIG_NET_TCP=y : Enable TCP/IP networking + CONFIG_NET_TCP_READAHEAD=y : Support TCP read-ahead + CONFIG_NET_TCP_WRITE_BUFFERS=y : Support TCP write-buffering + CONFIG_NET_TCPBACKLOG=y : Support TCP/IP backlog + CONFIG_NET_MAX_LISTENPORTS=20 : + CONFIG_NET_TCP_READAHEAD_BUFSIZE=536 Read-ahead buffer size + CONFIG_NET_UDP=y : Enable UDP networking + CONFIG_NET_BROADCAST=y : Needed for DNS name resolution + CONFIG_NET_ICMP=y : Enable ICMP networking + CONFIG_NET_ICMP_PING=y : Needed for NSH ping command + : Defaults should be okay for other options +f Application Configuration -> Network Utilities + CONFIG_NETDB_DNSCLIENT=y : Enable host address resolution + CONFIG_NETUTILS_TELNETD=y : Enable the Telnet daemon + CONFIG_NETUTILS_TFTPC=y : Enable TFTP data file transfers for get and put commands + CONFIG_NETUTILS_NETLIB=y : Network library support is needed + CONFIG_NETUTILS_WEBCLIENT=y : Needed for wget support + : Defaults should be okay for other options + Application Configuration -> NSH Library + CONFIG_NSH_TELNET=y : Enable NSH session via Telnet + CONFIG_NSH_IPADDR=0x0a000002 : Select a fixed IP address + CONFIG_NSH_DRIPADDR=0x0a000001 : IP address of gateway/host PC + CONFIG_NSH_NETMASK=0xffffff00 : Netmask + CONFIG_NSH_NOMAC=y : Need to make up a bogus MAC address + : Defaults should be okay for other options + + You can also enable enable the DHCPC client for networks that use + dynamically assigned address: + + Application Configuration -> Network Utilities + CONFIG_NETUTILS_DHCPC=y : Enables the DHCP client + + Networking Support + CONFIG_NET_UDP=y : Depends on broadcast UDP + + Application Configuration -> NSH Library + CONFIG_NET_BROADCAST=y + CONFIG_NSH_DHCPC=y : Tells NSH to use DHCPC, not + : the fixed addresses + + Using the network with NSH + -------------------------- + + So what can you do with this networking support? First you see that + NSH has several new network related commands: + + ifconfig, ifdown, ifup: Commands to help manage your network + get and put: TFTP file transfers + wget: HTML file transfers + ping: Check for access to peers on the network + Telnet console: You can access the NSH remotely via telnet. + + You can also enable other add on features like full FTP or a Web + Server or XML RPC and others. There are also other features that + you can enable like DHCP client (or server) or network name + resolution. + + By default, the IP address of the DK-TM4C129X will be 10.0.0.2 and + it will assume that your host is the gateway and has the IP address + 10.0.0.1. + + nsh> ifconfig + eth0 HWaddr 00:e0:de:ad:be:ef at UP + IPaddr:10.0.0.2 DRaddr:10.0.0.1 Mask:255.255.255.0 + + You can use ping to test for connectivity to the host (Careful, + Window firewalls usually block ping-related ICMP traffic). On the + target side, you can: + + nsh> ping 10.0.0.1 + PING 10.0.0.1 56 bytes of data + 56 bytes from 10.0.0.1: icmp_seq=1 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=2 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=3 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=4 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=5 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=6 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=7 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=8 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=9 time=0 ms + 56 bytes from 10.0.0.1: icmp_seq=10 time=0 ms + 10 packets transmitted, 10 received, 0% packet loss, time 10100 ms + + NOTE: In this configuration is is normal to have packet loss > 0% + the first time you ping due to the default handling of the ARP + table. + + On the host side, you should also be able to ping the DK-TM4C129X: + + $ ping 10.0.0.2 + + You can also log into the NSH from the host PC like this: + + $ telnet 10.0.0.2 + Trying 10.0.0.2... + Connected to 10.0.0.2. + Escape character is '^]'. + sh_telnetmain: Session [3] Started + + NuttShell (NSH) NuttX-6.31 + nsh> help + help usage: help [-v] [] + + [ echo ifconfig mkdir mw sleep + ? exec ifdown mkfatfs ping test + cat exit ifup mkfifo ps umount + cp free kill mkrd put usleep + cmp get losetup mh rm wget + dd help ls mount rmdir xd + df hexdump mb mv sh + + Builtin Apps: + nsh> + + NOTE: If you enable this networking as described above, you will + experience a delay on booting NSH. That is because the start-up logic + waits for the network connection to be established before starting + NuttX. In a real application, you would probably want to do the + network bringup on a separate thread so that access to the NSH prompt + is not delayed. + + This delay will be especially long if the board is not connected to + a network. On the order of minutes! You will probably think that + NuttX has crashed! And then, when it finally does come up after + numerous timeouts and retries, the network will not be available -- + even if the network cable is plugged in later. + + The long delays can be eliminated by using a separate the network + initialization thread discussed below. Recovering after the network + becomes available requires the network monitor feature, also discussed + below. + + Network Initialization Thread + ----------------------------- + There is a configuration option enabled by CONFIG_NSH_NETINIT_THREAD + that will do the NSH network bring-up asynchronously in parallel on + a separate thread. This eliminates the (visible) networking delay + altogether. This current implementation, however, has some limitations: + + - If no network is connected, the network bring-up will fail and + the network initialization thread will simply exit. There are no + retries and no mechanism to know if the network initialization was + successful (it could perform a network Ioctl to see if the link is + up and it now, keep trying, but it does not do that now). + + - Furthermore, there is currently no support for detecting loss of + network connection and recovery of the connection (similarly, this + thread could poll periodically for network status, but does not). + + Both of these shortcomings could be eliminated by enabling the network + monitor: + + Network Monitor + --------------- + By default the network initialization thread will bring-up the network + then exit, freeing all of the resources that it required. This is a + good behavior for systems with limited memory. + + If the CONFIG_NSH_NETINIT_MONITOR option is selected, however, then the + network initialization thread will persist forever; it will monitor the + network status. In the event that the network goes down (for example, if + a cable is removed), then the thread will monitor the link status and + attempt to bring the network back up. In this case the resources + required for network initialization are never released. + + Pre-requisites: + + - CONFIG_NSH_NETINIT_THREAD as described above. + + - The K64F EMAC block does not support PHY interrupts. The KSZ8081 + PHY interrupt line is brought to a jumper block and it should be + possible to connect that some some interrupt port pin. You would + need to provide some custom logic in the Freedcom K64F + configuration to set up that PHY interrupt. + + - In addtion to the PHY interrupt, the Network Monitor also requires the + following setting: + + CONFIG_NETDEV_PHY_IOCTL. Enable PHY IOCTL commands in the Ethernet + device driver. Special IOCTL commands must be provided by the Ethernet + driver to support certain PHY operations that will be needed for link + management. There operations are not complex and are implemented for + the Atmel SAMA5 family. + + CONFIG_ARCH_PHY_INTERRUPT. This is not a user selectable option. + Rather, it is set when you select a board that supports PHY + interrupts. For the K64F, like most other architectures, the PHY + interrupt must be provided via some board-specific GPIO. In any + event, the board-specific logic must provide support for the PHY + interrupt. To do this, the board logic must do two things: (1) It + must provide the function arch_phy_irq() as described and prototyped + in the nuttx/include/nuttx/arch.h, and (2) it must select + CONFIG_ARCH_PHY_INTERRUPT in the board configuration file to + advertise that it supports arch_phy_irq(). + + And a few other things: UDP support is required (CONFIG_NET_UDP) and + signals must not be disabled (CONFIG_DISABLE_SIGNALS). + + Given those prerequisites, the network monitor can be selected with these + additional settings. + + System Type -> Kinetis Ethernet Configuration + CONFIG_ARCH_PHY_INTERRUPT=y : (auto-selected) + CONFIG_NETDEV_PHY_IOCTL=y : (auto-selected) + + Application Configuration -> NSH Library -> Networking Configuration + CONFIG_NSH_NETINIT_THREAD : Enable the network initialization thread + CONFIG_NSH_NETINIT_MONITOR=y : Enable the network monitor + CONFIG_NSH_NETINIT_RETRYMSEC=2000 : Configure the network monitor as you like + CONFIG_NSH_NETINIT_SIGNO=18 + Development Environment ======================= @@ -400,6 +646,24 @@ Where is one of the following: CONFIG_ARMV7M_TOOLCHAIN_GNU_EABIW=y : ARM/mbed toolcahin (arm-none-elf-gcc) CONFIG_INTELHEX_BINARY=y : Output formats: Intel hex binary + 3. No external pullup is available on MDIO signal when MK64FN1M0VLL12 MCU + is requests status of the Ethernet link connection. Internal pullup is + required when port configuration for MDIO signal is enabled: + + CONFIG_KINETIS_ENET_MDIOPULLUP=y + + 4. Configured to use a fixed IPv4 address: + + CONFIG_NSH_IPADDR=0x0a000002 + CONFIG_NSH_DRIPADDR=0x0a000001 + CONFIG_NSH_NETMASK=0xffffff00 + + And a bogus MAC address: + + CONFIG_NSH_NOMAC=y + CONFIG_NSH_SWMAC=y + CONFIG_NSH_MACADDR=0x00e0deadbeef + nsh: --- Configures the NuttShell (nsh) located at apps/examples/nsh using a @@ -455,5 +719,13 @@ Status NSH configuration is working and LEDs are working. The only odd behavior that I see is that pressing SW3 causes an unexpected interrupt error. + 2016-07-12: Added support for the KSZ8081 PHY and added the netnsh - configuration. Untested as of this writing. + configuration. The network is basically functional, but a lot more + testing is needed to confirm that. + + In testing, I notice a strange thing. If I run at full optimization the + code runs (albeit with bugs-to-be-solved). But with no optimization or + even at -O1, the system fails to boot. This seems to be related to the + watchdog timer. + diff --git a/configs/freedom-k64f/include/board.h b/configs/freedom-k64f/include/board.h index 7dcb29fc43..198915caa9 100644 --- a/configs/freedom-k64f/include/board.h +++ b/configs/freedom-k64f/include/board.h @@ -41,8 +41,9 @@ ************************************************************************************/ #include + #ifndef __ASSEMBLY__ -# include +# include #endif /************************************************************************************ @@ -68,7 +69,7 @@ * * PLL Input frequency: PLLIN = REFCLK / PRDIV = 50 Mhz / 20 = 2.5 MHz * PLL Output frequency: PLLOUT = PLLIN * VDIV = 2.5 Mhz * 48 = 120 MHz - * MCG Frequency: PLLOUT = 96MHz + * MCG Frequency: PLLOUT = 120 MHz * * PRDIV register value is the divider minus one. So 20 -> 19 * VDIV regiser value is offset by 24. So 28 -> 24 @@ -100,36 +101,37 @@ * SDCLK frequency = (base clock) / (prescaler * divisor) * * The SDHC module is always configure configured so that the core clock is the base - * clock. + * clock. Possible values for presscaler and divisor are: + * + * SDCLKFS: {2, 4, 8, 16, 32, 63, 128, 256} + * DVS: {1..16} */ -/* Identification mode: 400KHz = 96MHz / ( 16 * 15) */ +/* Identification mode: Optimal 400KHz, Actual 120MHz / (32 * 10) = 375 Khz */ -#define BOARD_SDHC_IDMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV16 -#define BOARD_SDHC_IDMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(15) +#define BOARD_SDHC_IDMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV32 +#define BOARD_SDHC_IDMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(10) -/* MMC normal mode: 16MHz = 96MHz / (2 * 3) */ +/* MMC normal mode: Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz */ #define BOARD_SDHC_MMCMODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2 #define BOARD_SDHC_MMCMODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3) -/* SD normal mode (1-bit): 16MHz = 96MHz / (2 * 3) */ +/* SD normal mode (1-bit): Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz */ #define BOARD_SDHC_SD1MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2 #define BOARD_SDHC_SD1MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3) -/* SD normal mode (4-bit): 24MHz = 96MHz / (2 * 2) (with DMA) - * SD normal mode (4-bit): 16MHz = 96MHz / (2 * 3) (no DMA) +/* SD normal mode (4-bit): Optimal 25MHz, Actual 120MHz / (2 * 3) = 20 MHz (with DMA) + * SD normal mode (4-bit): Optimal 20MHz, Actual 120MHz / (2 * 3) = 20 MHz (no DMA) */ #ifdef CONFIG_SDIO_DMA # define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2 -# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(2) +# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3) #else -//# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2 -//# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3) -# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV16 -# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(15) +# define BOARD_SDHC_SD4MODE_PRESCALER SDHC_SYSCTL_SDCLKFS_DIV2 +# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3) #endif /* LED definitions ******************************************************************/ diff --git a/configs/freedom-k64f/netnsh/defconfig b/configs/freedom-k64f/netnsh/defconfig index 0cb2657d58..a4a8968bdd 100644 --- a/configs/freedom-k64f/netnsh/defconfig +++ b/configs/freedom-k64f/netnsh/defconfig @@ -245,8 +245,9 @@ CONFIG_KINETIS_ENET=y CONFIG_KINETIS_ENETNETHIFS=1 CONFIG_KINETIS_ENETNRXBUFFERS=6 CONFIG_KINETIS_ENETNTXBUFFERS=2 -CONFIG_KINETIS_ENETPHYADDR=1 # CONFIG_KINETIS_ENETUSEMII is not set +CONFIG_KINETIS_ENET_MDIOPULLUP=y +# CONFIG_KINETIS_ENET_NORXER is not set # # Kinetis UART Configuration @@ -331,7 +332,14 @@ CONFIG_ARCH_HAVE_IRQBUTTONS=y # Board-Specific Options # # CONFIG_BOARD_CRASHDUMP is not set -# CONFIG_LIB_BOARDCTL is not set +CONFIG_LIB_BOARDCTL=y +# CONFIG_BOARDCTL_RESET is not set +# CONFIG_BOARDCTL_UNIQUEID is not set +# CONFIG_BOARDCTL_TSCTEST is not set +# CONFIG_BOARDCTL_ADCTEST is not set +# CONFIG_BOARDCTL_PWMTEST is not set +# CONFIG_BOARDCTL_GRAPHICS is not set +# CONFIG_BOARDCTL_IOCTL is not set # # RTOS Features @@ -403,6 +411,7 @@ CONFIG_NAME_MAX=32 # CONFIG_SCHED_STARTHOOK is not set # CONFIG_SCHED_ATEXIT is not set # CONFIG_SCHED_ONEXIT is not set +# CONFIG_SIG_EVTHREAD is not set # # Signal Numbers @@ -411,6 +420,7 @@ CONFIG_SIG_SIGUSR1=1 CONFIG_SIG_SIGUSR2=2 CONFIG_SIG_SIGALARM=3 CONFIG_SIG_SIGCONDTIMEDOUT=16 +CONFIG_SIG_SIGWORK=17 # # POSIX Message Queue Options @@ -422,8 +432,11 @@ CONFIG_MQ_MAXMSGSIZE=32 # # Work queue support # -# CONFIG_SCHED_WORKQUEUE is not set -# CONFIG_SCHED_HPWORK is not set +CONFIG_SCHED_WORKQUEUE=y +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKPRIORITY=224 +CONFIG_SCHED_HPWORKPERIOD=50000 +CONFIG_SCHED_HPWORKSTACKSIZE=2048 # CONFIG_SCHED_LPWORK is not set # @@ -615,7 +628,7 @@ CONFIG_SYSLOG_CONSOLE=y CONFIG_ARCH_HAVE_NET=y CONFIG_ARCH_HAVE_PHY=y CONFIG_NET=y -# CONFIG_NET_NOINTS is not set +CONFIG_NET_NOINTS=y # CONFIG_NET_PROMISCUOUS is not set # @@ -759,7 +772,16 @@ CONFIG_FS_FAT=y # CONFIG_FS_ROMFS is not set # CONFIG_FS_TMPFS is not set # CONFIG_FS_SMARTFS is not set -# CONFIG_FS_PROCFS is not set +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y + +# +# Exclude individual procfs entries +# +# CONFIG_FS_PROCFS_EXCLUDE_PROCESS is not set +# CONFIG_FS_PROCFS_EXCLUDE_UPTIME is not set +# CONFIG_FS_PROCFS_EXCLUDE_MOUNTS is not set +# CONFIG_FS_PROCFS_EXCLUDE_NET is not set # CONFIG_FS_UNIONFS is not set # @@ -918,6 +940,7 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_TOUCHSCREEN is not set # CONFIG_EXAMPLES_UDP is not set # CONFIG_EXAMPLES_UDPBLASTER is not set +# CONFIG_EXAMPLES_USBSERIAL is not set # CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set # CONFIG_EXAMPLES_WEBSERVER is not set @@ -1057,6 +1080,7 @@ CONFIG_NSH_MMCSDMINOR=0 CONFIG_NSH_CMDOPT_DF_H=y CONFIG_NSH_CODECS_BUFSIZE=128 CONFIG_NSH_CMDOPT_HEXDUMP=y +CONFIG_NSH_PROC_MOUNTPOINT="/proc" CONFIG_NSH_FILEIOSIZE=512 # @@ -1070,7 +1094,7 @@ CONFIG_NSH_FILEIOSIZE=512 # Console Configuration # CONFIG_NSH_CONSOLE=y -# CONFIG_NSH_ARCHINIT is not set +CONFIG_NSH_ARCHINIT=y # # Networking Configuration diff --git a/configs/freedom-k64f/nsh/defconfig b/configs/freedom-k64f/nsh/defconfig index 085afbde09..7fb687ca4a 100644 --- a/configs/freedom-k64f/nsh/defconfig +++ b/configs/freedom-k64f/nsh/defconfig @@ -192,6 +192,8 @@ CONFIG_ARCH_FAMILY_K64=y CONFIG_KINETIS_UART3=y # CONFIG_KINETIS_UART4 is not set # CONFIG_KINETIS_UART5 is not set +# CONFIG_KINETIS_ENET is not set +# CONFIG_KINETIS_RNGB is not set # CONFIG_KINETIS_FLEXCAN0 is not set # CONFIG_KINETIS_FLEXCAN1 is not set # CONFIG_KINETIS_SPI0 is not set @@ -312,7 +314,14 @@ CONFIG_ARCH_HAVE_IRQBUTTONS=y # Board-Specific Options # # CONFIG_BOARD_CRASHDUMP is not set -# CONFIG_LIB_BOARDCTL is not set +CONFIG_LIB_BOARDCTL=y +# CONFIG_BOARDCTL_RESET is not set +# CONFIG_BOARDCTL_UNIQUEID is not set +# CONFIG_BOARDCTL_TSCTEST is not set +# CONFIG_BOARDCTL_ADCTEST is not set +# CONFIG_BOARDCTL_PWMTEST is not set +# CONFIG_BOARDCTL_GRAPHICS is not set +# CONFIG_BOARDCTL_IOCTL is not set # # RTOS Features @@ -545,6 +554,7 @@ CONFIG_SYSLOG_SERIAL_CONSOLE=y CONFIG_SYSLOG_CONSOLE=y # CONFIG_SYSLOG_NONE is not set # CONFIG_SYSLOG_FILE is not set +# CONFIG_SYSLOG_CHARDEV is not set # # Networking Support @@ -584,7 +594,15 @@ CONFIG_FS_FAT=y # CONFIG_FS_ROMFS is not set # CONFIG_FS_TMPFS is not set # CONFIG_FS_SMARTFS is not set -# CONFIG_FS_PROCFS is not set +CONFIG_FS_PROCFS=y +CONFIG_FS_PROCFS_REGISTER=y + +# +# Exclude individual procfs entries +# +# CONFIG_FS_PROCFS_EXCLUDE_PROCESS is not set +# CONFIG_FS_PROCFS_EXCLUDE_UPTIME is not set +# CONFIG_FS_PROCFS_EXCLUDE_MOUNTS is not set # CONFIG_FS_UNIONFS is not set # @@ -730,6 +748,7 @@ CONFIG_EXAMPLES_NSH=y # CONFIG_EXAMPLES_TELNETD is not set # CONFIG_EXAMPLES_TIFF is not set # CONFIG_EXAMPLES_TOUCHSCREEN is not set +# CONFIG_EXAMPLES_USBSERIAL is not set # CONFIG_EXAMPLES_USBTERM is not set # CONFIG_EXAMPLES_WATCHDOG is not set # CONFIG_EXAMPLES_WEBSERVER is not set @@ -829,7 +848,6 @@ CONFIG_NSH_DISABLE_LOSMART=y # CONFIG_NSH_DISABLE_MV is not set # CONFIG_NSH_DISABLE_MW is not set # CONFIG_NSH_DISABLE_PS is not set -# CONFIG_NSH_DISABLE_PSSTACKUSAGE is not set # CONFIG_NSH_DISABLE_PUT is not set # CONFIG_NSH_DISABLE_PWD is not set # CONFIG_NSH_DISABLE_RM is not set @@ -853,6 +871,7 @@ CONFIG_NSH_MMCSDMINOR=0 CONFIG_NSH_CMDOPT_DF_H=y CONFIG_NSH_CODECS_BUFSIZE=128 CONFIG_NSH_CMDOPT_HEXDUMP=y +CONFIG_NSH_PROC_MOUNTPOINT="/proc" CONFIG_NSH_FILEIOSIZE=512 # @@ -867,7 +886,7 @@ CONFIG_NSH_FILEIOSIZE=512 # CONFIG_NSH_CONSOLE=y # CONFIG_NSH_ALTCONDEV is not set -# CONFIG_NSH_ARCHINIT is not set +CONFIG_NSH_ARCHINIT=y # CONFIG_NSH_LOGIN is not set # CONFIG_NSH_CONSOLE_LOGIN is not set diff --git a/configs/freedom-k64f/src/freedom-k64f.h b/configs/freedom-k64f/src/freedom-k64f.h index a253dd3be4..a6758ebb0f 100644 --- a/configs/freedom-k64f/src/freedom-k64f.h +++ b/configs/freedom-k64f/src/freedom-k64f.h @@ -49,6 +49,65 @@ * Pre-processor Definitions ************************************************************************************/ +/* Application Configuration ********************************************************/ + +/* Assume we have everything */ + +#define HAVE_PROC 1 +#define NSH_HAVEUSBDEV 1 +#define NSH_HAVEMMCSD 1 + +/* Automount procfs */ + +#if !defined(CONFIG_FS_PROCFS) +# undef HAVE_PROC +#endif + +#if defined(HAVE_PROC) && defined(CONFIG_DISABLE_MOUNTPOINT) +# warning Mountpoints disabled. No procfs support +# undef HAVE_PROC +#endif + +#if defined(CONFIG_NSH_PROC_MOUNTPOINT) +# define PROCFS_MOUNTPOUNT CONFIG_NSH_PROC_MOUNTPOINT +#else +# define PROCFS_MOUNTPOUNT "/proc" +#endif + +/* SD card support */ + +#define MMCSD_SLOTNO 0 + +/* Can't support MMC/SD features if mountpoints are disabled or if SDHC support + * is not enabled. + */ + +#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_KINETIS_SDHC) +# undef NSH_HAVEMMCSD +#endif + +#ifdef NSH_HAVEMMCSD +# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0 +# error "Only one MMC/SD slot, slot 0" +# endif + +/* We expect to receive GPIO interrupts for card insertion events */ + +# ifndef CONFIG_GPIO_IRQ +# error "CONFIG_GPIO_IRQ required for card detect interrupt" +# endif + +# ifndef CONFIG_KINETIS_PORTEINTS +# error "CONFIG_KINETIS_PORTEINTS required for card detect interrupt" +# endif +#endif + +/* Can't support USB features if USB is not enabled */ + +#ifndef CONFIG_USBDEV +# undef NSH_HAVEUSBDEV +#endif + /* How many SPI modules does this chip support? The LM3S6918 supports 2 SPI * modules (others may support more -- in such case, the following must be * expanded). diff --git a/configs/freedom-k64f/src/k64_bringup.c b/configs/freedom-k64f/src/k64_bringup.c index 0739f95d00..0cbbb1bb28 100644 --- a/configs/freedom-k64f/src/k64_bringup.c +++ b/configs/freedom-k64f/src/k64_bringup.c @@ -39,6 +39,7 @@ #include +#include #include #include #include @@ -54,58 +55,6 @@ #if defined(CONFIG_LIB_BOARDCTL) || defined(CONFIG_BOARD_INITIALIZE) -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/* Configuration ************************************************************/ - -/* PORT and SLOT number probably depend on the board configuration */ - -#ifdef CONFIG_ARCH_BOARD_FREEDOM_K64F -# define NSH_HAVEUSBDEV 1 -# define NSH_HAVEMMCSD 1 -# if defined(CONFIG_NSH_MMCSDSLOTNO) && CONFIG_NSH_MMCSDSLOTNO != 0 -# error "Only one MMC/SD slot, slot 0" -# undef CONFIG_NSH_MMCSDSLOTNO -# endif -# ifndef CONFIG_NSH_MMCSDSLOTNO -# define CONFIG_NSH_MMCSDSLOTNO 0 -# endif -#else - /* Add configuration for new Kinetis boards here */ -# error "Unrecognized Kinetis board" -# undef NSH_HAVEUSBDEV -# undef NSH_HAVEMMCSD -#endif - -/* Can't support USB features if USB is not enabled */ - -#ifndef CONFIG_USBDEV -# undef NSH_HAVEUSBDEV -#endif - -/* Can't support MMC/SD features if mountpoints are disabled or if SDHC support - * is not enabled. - */ - -#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_KINETIS_SDHC) -# undef NSH_HAVEMMCSD -#endif - -#ifndef CONFIG_NSH_MMCSDMINOR -# define CONFIG_NSH_MMCSDMINOR 0 -#endif - -/* We expect to receive GPIO interrupts for card insertion events */ - -#ifndef CONFIG_GPIO_IRQ -# error "CONFIG_GPIO_IRQ required for card detect interrupt" -#endif - -#ifndef CONFIG_KINETIS_PORTEINTS -# error "CONFIG_KINETIS_PORTEINTS required for card detect interrupt" -#endif - /**************************************************************************** * Private Types ****************************************************************************/ @@ -199,9 +148,24 @@ static int k64_cdinterrupt(int irq, FAR void *context) int k64_bringup(void) { -#ifdef NSH_HAVEMMCSD int ret; +#ifdef HAVE_PROC + /* Mount the proc filesystem */ + + syslog(LOG_INFO, "Mounting procfs to /proc\n"); + + ret = mount(NULL, PROCFS_MOUNTPOUNT, "procfs", 0, NULL); + if (ret < 0) + { + syslog(LOG_ERR, + "ERROR: Failed to mount the PROC filesystem: %d (%d)\n", + ret, errno); + return ret; + } +#endif + +#ifdef NSH_HAVEMMCSD /* Configure GPIO pins */ /* Attached the card detect interrupt (but don't enable it yet) */ @@ -211,19 +175,18 @@ int k64_bringup(void) /* Configure the write protect GPIO */ - kinetis_pinconfig(GPIO_SD_WRPROTECT); + //kinetis_pinconfig(GPIO_SD_WRPROTECT); /* Mount the SDHC-based MMC/SD block driver */ /* First, get an instance of the SDHC interface */ - syslog(LOG_INFO, "Initializing SDHC slot %d\n", - CONFIG_NSH_MMCSDSLOTNO); + syslog(LOG_INFO, "Initializing SDHC slot %d\n", MMCSD_SLOTNO); - g_nsh.sdhc = sdhc_initialize(CONFIG_NSH_MMCSDSLOTNO); + g_nsh.sdhc = sdhc_initialize(MMCSD_SLOTNO); if (!g_nsh.sdhc) { syslog(LOG_ERR, "ERROR: Failed to initialize SDHC slot %d\n", - CONFIG_NSH_MMCSDSLOTNO); + MMCSD_SLOTNO); return -ENODEV; } @@ -249,6 +212,8 @@ int k64_bringup(void) kinetis_pinirqenable(GPIO_SD_CARDDETECT); #endif + + UNUSED(ret); return OK; } diff --git a/fs/smartfs/smartfs_smart.c b/fs/smartfs/smartfs_smart.c index c5390d4201..c269031d27 100644 --- a/fs/smartfs/smartfs_smart.c +++ b/fs/smartfs/smartfs_smart.c @@ -1691,6 +1691,11 @@ static int smartfs_unlink(struct inode *mountpt, const char *relpath) ret = OK; errout_with_semaphore: + if (entry.name != NULL) + { + kmm_free(entry.name); + } + smartfs_semgive(fs); return ret; } @@ -1856,6 +1861,11 @@ int smartfs_rmdir(struct inode *mountpt, const char *relpath) ret = OK; errout_with_semaphore: + if (entry.name != NULL) + { + kmm_free(entry.name); + } + smartfs_semgive(fs); return ret; }