embox
1/**
2* @file
3* @brief
4*
5* @author Anton Kozlov
6* @date 25.03.2014
7*/
8
9/***************************************************************************//**10* @file
11* @brief Provide BSP (board support package) configuration parameters.
12* @author Energy Micro AS
13* @version 3.20.3
14*******************************************************************************
15* @section License
16* <b>(C) Copyright 2013 Energy Micro AS, http://www.energymicro.com</b>
17*******************************************************************************
18*
19* Permission is granted to anyone to use this software for any purpose,
20* including commercial applications, and to alter it and redistribute it
21* freely, subject to the following restrictions:
22*
23* 1. The origin of this software must not be misrepresented; you must not
24* claim that you wrote the original software.
25* 2. Altered source versions must be plainly marked as such, and must not be
26* misrepresented as being the original software.
27* 3. This notice may not be removed or altered from any source distribution.
28* 4. The source and compiled code may only be used on Energy Micro "EFM32"
29* microcontrollers and "EFR4" radios.
30*
31* DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
32* obligation to support this Software. Energy Micro AS is providing the
33* Software "AS IS", with no express or implied warranties of any kind,
34* including, but not limited to, any implied warranties of merchantability
35* or fitness for any particular purpose or warranties against infringement
36* of any proprietary rights of a third party.
37*
38* Energy Micro AS will not be liable for any consequential, incidental, or
39* special damages, or any other relief, or for any claim by any third party,
40* arising from your use of this Software.
41*
42*****************************************************************************/
43
44#include <stdint.h>45
46/*#include <drivers/gpio.h>*/
47#include <hal/reg.h>48#include <hal/system.h>49#include <drivers/diag.h>50#include <drivers/serial/diag_serial.h>51#include <embox/unit.h>52
53#include <drivers/serial/uart_dev.h>54
55#include <em_leuart.h>56#include <em_cmu.h>57#include <em_gpio.h>58
59#define BSP_BCC_LEUART LEUART060#define BSP_BCC_CLK cmuClock_LEUART061#define BSP_BCC_LOCATION LEUART_ROUTE_LOCATION_LOC062#define BSP_BCC_TXPORT gpioPortD63#define BSP_BCC_TXPIN 464#define BSP_BCC_RXPORT gpioPortD65#define BSP_BCC_RXPIN 566#define BSP_BCC_ENABLE_PORT gpioPortA67#define BSP_BCC_ENABLE_PIN 968
69static int efm32_uart_putc(struct uart *dev, int ch) {70LEUART_Tx((void *) dev->base_addr, ch);71return 0;72}
73
74static int efm32_uart_hasrx(struct uart *dev) {75#if 176static unsigned int neg_cnt;77while (1)78if (!GPIO_PinInGet(BSP_BCC_RXPORT, BSP_BCC_RXPIN)) {79LEUART_Tx((void *) dev->base_addr, '0');80neg_cnt++;81}82#endif83return 1;84}
85
86static int efm32_uart_getc(struct uart *dev) {87return LEUART_Rx((void *) dev->base_addr);88}
89
90static int efm32_uart_setup(struct uart *dev, const struct uart_params *params) {91
92LEUART_TypeDef *leuart = (void *) dev->base_addr;93LEUART_Init_TypeDef init = LEUART_INIT_DEFAULT;94
95/* Enable CORE LE clock in order to access LE modules */96CMU_ClockEnable(cmuClock_HFPER, true);97
98/* Enable CORE LE clock in order to access LE modules */99CMU_ClockEnable(cmuClock_GPIO, true);100
101/* Enable CORE LE clock in order to access LE modules */102CMU_ClockEnable(cmuClock_CORELE, true);103
104/* Select LFXO for LEUARTs (and wait for it to stabilize) */105CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO);106
107CMU_ClockEnable(cmuClock_LEUART0, true);108
109/* Do not prescale clock */110CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_1);111
112/* Configure GPIO pin for UART TX */113/* To avoid false start, configure output as high. */114GPIO_PinModeSet( BSP_BCC_TXPORT, BSP_BCC_TXPIN, gpioModePushPull, 1 );115/* Configure GPIO pin for UART RX */116GPIO_PinModeSet( BSP_BCC_RXPORT, BSP_BCC_RXPIN, gpioModeInput, 1 );117
118/* Configure LEUART */119init.enable = leuartDisable;120init.baudrate = 9600;121LEUART_Init(leuart, &init);122
123/* Enable the switch that enables UART communication. */124GPIO_PinModeSet( BSP_BCC_ENABLE_PORT, BSP_BCC_ENABLE_PIN, gpioModePushPull, 1 );125BSP_BCC_LEUART->ROUTE |= LEUART_ROUTE_RXPEN | LEUART_ROUTE_TXPEN | BSP_BCC_LOCATION;126
127/* Finally enable it */128LEUART_Enable(leuart, leuartEnable);129
130return 0;131}
132
133static const struct uart_ops efm32_uart_ops = {134.uart_getc = efm32_uart_getc,135.uart_putc = efm32_uart_putc,136.uart_hasrx = efm32_uart_hasrx,137.uart_setup = efm32_uart_setup,138};139
140static struct uart efm32_uart0 = {141.uart_ops = &efm32_uart_ops,142.irq_num = 0,143.base_addr = (unsigned long) LEUART0,144};145
146static const struct uart_params uart_defparams = {147.baud_rate = 115200,148.uart_param_flags = UART_PARAM_FLAGS_8BIT_WORD,149};150
151DIAG_SERIAL_DEF(&efm32_uart0, &uart_defparams);152