/** * @brief Low level serial driver stop. * @details De-initializes the USART, stops the associated clock, resets the * interrupt vector. * * @param[in] sdp pointer to a @p SerialDriver object * * @notapi */ void sd_lld_stop(SerialDriver *sdp) { if (sdp->state == SD_READY) { usart_deinit(sdp->usart); #if USE_SAM7_USART0 if (&SD1 == sdp) { AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US0); AIC_DisableIT(AT91C_ID_US0); return; } #endif #if USE_SAM7_USART1 if (&SD2 == sdp) { AT91C_BASE_PMC->PMC_PCDR = (1 << AT91C_ID_US1); AIC_DisableIT(AT91C_ID_US1); return; } #endif #if USE_SAM7_DBGU_UART if (&SD3 == sdp) { AT91C_BASE_DBGU->DBGU_IDR = 0xFFFFFFFF; return; } #endif } }
/** Initialize the USART peripheral. * * @param obj_s The serial object */ static void usart_init(struct serial_s *obj_s) { if (obj_s->index >= USART_NUM) { return; } /* USART configuration */ usart_deinit(obj_s->uart); usart_word_length_set(obj_s->uart, obj_s->databits); usart_baudrate_set(obj_s->uart, obj_s->baudrate); usart_stop_bit_set(obj_s->uart, obj_s->stopbits); usart_parity_config(obj_s->uart, obj_s->parity); #if DEVICE_SERIAL_FC if (obj_s->hw_flow_ctl == USART_HWCONTROL_NONE) { usart_hardware_flow_cts_config(obj_s->uart, USART_CTS_DISABLE); usart_hardware_flow_rts_config(obj_s->uart, USART_RTS_DISABLE); } else if (obj_s->hw_flow_ctl == USART_HWCONTROL_RTS) { usart_hardware_flow_cts_config(obj_s->uart, USART_CTS_DISABLE); usart_hardware_flow_rts_config(obj_s->uart, USART_RTS_ENABLE); } else if (obj_s->hw_flow_ctl == USART_HWCONTROL_CTS) { usart_hardware_flow_cts_config(obj_s->uart, USART_CTS_ENABLE); usart_hardware_flow_rts_config(obj_s->uart, USART_RTS_DISABLE); } else if (obj_s->hw_flow_ctl == USART_HWCONTROL_RTS_CTS) { usart_hardware_flow_cts_config(obj_s->uart, USART_CTS_ENABLE); usart_hardware_flow_rts_config(obj_s->uart, USART_RTS_ENABLE); } #endif /* DEVICE_SERIAL_FC */ usart_receive_config(obj_s->uart, USART_RECEIVE_ENABLE); usart_transmit_config(obj_s->uart, USART_TRANSMIT_ENABLE); usart_enable(obj_s->uart); }
/** * @brief Low level serial driver stop. * @details De-initializes the USART, stops the associated clock, resets the * interrupt vector. * * @param[in] sdp pointer to a @p SerialDriver object * * @notapi */ void sd_lld_stop(SerialDriver *sdp) { if (sdp->state == SD_READY) { /* UART is de-initialized then clocks are disabled.*/ usart_deinit(sdp->usart); #if STM32_SERIAL_USE_USART1 if (&SD1 == sdp) { rccDisableUSART1(FALSE); return; } #endif #if STM32_SERIAL_USE_USART2 if (&SD2 == sdp) { rccDisableUSART2(FALSE); return; } #endif #if STM32_SERIAL_USE_USART3 if (&SD3 == sdp) { rccDisableUSART3(FALSE); return; } #endif #if STM32_SERIAL_USE_UART4 if (&SD4 == sdp) { rccDisableUART4(FALSE); return; } #endif #if STM32_SERIAL_USE_UART5 if (&SD5 == sdp) { rccDisableUART5(FALSE); return; } #endif #if STM32_SERIAL_USE_USART6 if (&SD6 == sdp) { rccDisableUSART6(FALSE); return; } #endif #if STM32_SERIAL_USE_UART7 if (&SD7 == sdp) { rccDisableUART7(FALSE); return; } #endif #if STM32_SERIAL_USE_UART8 if (&SD8 == sdp) { rccDisableUART8(FALSE); return; } #endif } }
/** Release the serial peripheral, not currently invoked. It requires further * resource management. * * @param obj The serial object */ void serial_free(serial_t *obj) { struct serial_s *p_obj = GET_SERIAL_S(obj); rcu_periph_enum rcu_periph = usart_clk[p_obj->index]; /* reset USART and disable clock */ usart_deinit(p_obj->uart); rcu_periph_clock_disable(rcu_periph); serial_irq_ids[p_obj->index] = 0; /* reset the GPIO state */ pin_function(p_obj->pin_tx, MODE_IN_FLOATING); pin_function(p_obj->pin_rx, MODE_IN_FLOATING); }
/** * @brief Low level serial driver stop. * @details De-initializes the USART, stops the associated clock, resets the * interrupt vector. * * @param[in] sdp pointer to a @p SerialDriver object * * @notapi */ void sd_lld_stop(SerialDriver *sdp) { if (sdp->state == SD_READY) { usart_deinit(sdp->usart); #if STM32_SERIAL_USE_USART1 if (&SD1 == sdp) { rccDisableUSART1(FALSE); nvicDisableVector(STM32_USART1_NUMBER); return; } #endif #if STM32_SERIAL_USE_USART2 if (&SD2 == sdp) { rccDisableUSART2(FALSE); nvicDisableVector(STM32_USART2_NUMBER); return; } #endif #if STM32_SERIAL_USE_USART3 if (&SD3 == sdp) { rccDisableUSART3(FALSE); nvicDisableVector(STM32_USART3_NUMBER); return; } #endif #if STM32_SERIAL_USE_UART4 if (&SD4 == sdp) { rccDisableUART4(FALSE); nvicDisableVector(STM32_UART4_NUMBER); return; } #endif #if STM32_SERIAL_USE_UART5 if (&SD5 == sdp) { rccDisableUART5(FALSE); nvicDisableVector(STM32_UART5_NUMBER); return; } #endif #if STM32_SERIAL_USE_USART6 if (&SD6 == sdp) { rccDisableUSART6(FALSE); nvicDisableVector(STM32_USART6_NUMBER); return; } #endif } }