Fixed LPUART and USB device initialization issue. Added _kill, _exit and _getpid functions required by gcc-arm-none-eabi-4.8 toolchain.

pull/589/head
Martin Olejar 2014-10-17 22:20:12 +02:00
parent 98faa3f908
commit 185ce5bfe4
4 changed files with 57 additions and 20 deletions

View File

@ -122,6 +122,9 @@ USBHAL::USBHAL(void) {
epCallback[29] = &USBHAL::EP15_IN_callback; epCallback[29] = &USBHAL::EP15_IN_callback;
#if defined(TARGET_KL43Z) #if defined(TARGET_KL43Z)
// enable USBFS clock
SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK;
// enable the IRC48M clock // enable the IRC48M clock
USB0->CLK_RECOVER_IRC_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK; USB0->CLK_RECOVER_IRC_EN |= USB_CLK_RECOVER_IRC_EN_IRC_EN_MASK;
@ -130,9 +133,6 @@ USBHAL::USBHAL(void) {
// choose usb src clock // choose usb src clock
SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK; SIM->SOPT2 |= SIM_SOPT2_USBSRC_MASK;
// enable USBFS clock
SIM->SCGC4 |= SIM_SCGC4_USBFS_MASK;
#else #else
// choose usb src as PLL // choose usb src as PLL
SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK); SIM->SOPT2 |= (SIM_SOPT2_USBSRC_MASK | SIM_SOPT2_PLLFLLSEL_MASK);

View File

@ -0,0 +1,32 @@
/* mbed Microcontroller Library - stackheap
* Copyright (C) 2009-2011 ARM Limited. All rights reserved.
*
* Setup a fixed single stack/heap memory model,
* between the top of the RW/ZI region and the stackpointer
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <errno.h>
extern void exit(int return_code);
int _kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
void _exit(int status) {
exit(status);
}
int _getpid(void) {
return 1;
}
#ifdef __cplusplus
}
#endif

View File

@ -49,18 +49,27 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
// enable clk // enable clk
switch (uart) { switch (uart) {
case UART_0: SIM->SOPT2 |= SIM_SOPT2_LPUART0SRC(1); break; case UART_0:
case UART_1: SIM->SOPT2 |= SIM_SOPT2_LPUART1SRC(1); break; SIM->SOPT2 |= SIM_SOPT2_LPUART0SRC(1);
case UART_2: break; SIM->SCGC5 |= SIM_SCGC5_LPUART0_MASK;
break;
case UART_1:
SIM->SOPT2 |= SIM_SOPT2_LPUART1SRC(1);
SIM->SCGC5 |= SIM_SCGC5_LPUART1_MASK;
break;
case UART_2: /* TODO: add UART2 support */ break;
} }
// Disable UART before changing registers // reset UART registers
obj->uart->CTRL &= ~(LPUART_CTRL_RE_MASK | LPUART_CTRL_TE_MASK); obj->uart->BAUD = 0x0F000004;
obj->uart->STAT = 0xC01FC000;
obj->uart->CTRL = 0x00000000;
obj->uart->MATCH = 0x00000000;
switch (uart) { switch (uart) {
case UART_0: obj->index = 0; break; case UART_0: obj->index = 0; break;
case UART_1: obj->index = 1; break; case UART_1: obj->index = 1; break;
case UART_2: break; case UART_2: /* TODO: add UART2 support */ break;
} }
// set default baud rate and format // set default baud rate and format
@ -72,12 +81,8 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) {
pinmap_pinout(rx, PinMap_UART_RX); pinmap_pinout(rx, PinMap_UART_RX);
// set rx/tx pins in PullUp mode // set rx/tx pins in PullUp mode
if (tx != NC) { if (tx != NC) pin_mode(tx, PullUp);
pin_mode(tx, PullUp); if (rx != NC) pin_mode(rx, PullUp);
}
if (rx != NC) {
pin_mode(rx, PullUp);
}
obj->uart->CTRL |= (LPUART_CTRL_RE_MASK | LPUART_CTRL_TE_MASK); obj->uart->CTRL |= (LPUART_CTRL_RE_MASK | LPUART_CTRL_TE_MASK);