Skip to content

Commit

Permalink
cpu/nrf51822: some fixes and clean up
Browse files Browse the repository at this point in the history
- enabled power for uart and timer
- outsourced timer config values to periph_conf.h
- made linkerscript better readable
- adjusted default stack-sizes
- let RED_LED blink on hard_fault
  • Loading branch information
haukepetersen committed Sep 17, 2014
1 parent e0fec98 commit c9c7bfa
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cpu/nrf51822/include/cpu-conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
* TODO: measure and adjust for the cortex-m0
* @{
*/
#define KERNEL_CONF_STACKSIZE_PRINTF (1024)
#define KERNEL_CONF_STACKSIZE_PRINTF (524)

#ifndef KERNEL_CONF_STACKSIZE_DEFAULT
#define KERNEL_CONF_STACKSIZE_DEFAULT (1024)
#define KERNEL_CONF_STACKSIZE_DEFAULT (524)
#endif

#define KERNEL_CONF_STACKSIZE_IDLE (256)
Expand Down
4 changes: 2 additions & 2 deletions cpu/nrf51822/nrf51822qfaa_linkerscript.ld
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ SEARCH_DIR(.)
/* Memory Spaces Definitions */
MEMORY
{
rom (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 /* 256K flash */
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 /* 16K ram */
rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
}

/* The stack size used by the application. NOTE: you need to adjust */
Expand Down
17 changes: 11 additions & 6 deletions cpu/nrf51822/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,32 @@ static timer_conf_t timer_config[TIMER_NUMOF];

int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int))
{

NRF_TIMER_Type *timer;

switch (dev) {
#if TIMER_0_EN
case TIMER_0:
timer = TIMER_0_DEV;
timer->BITMODE = TIMER_BITMODE_BITMODE_32Bit; /* 32 Bit Mode */
timer->POWER = 1;
timer->BITMODE = TIMER_0_BITMODE;
NVIC_SetPriority(TIMER_0_IRQ, TIMER_IRQ_PRIO);
NVIC_EnableIRQ(TIMER_0_IRQ);
break;
#endif
#if TIMER_1_EN
case TIMER_1:
timer = TIMER_1_DEV;
timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit; /* 16 Bit Mode */
timer->POWER = 1;
timer->BITMODE = TIEMR_1_BITMODE;
NVIC_SetPriority(TIMER_1_IRQ, TIMER_IRQ_PRIO);
NVIC_EnableIRQ(TIMER_1_IRQ);
break;
#endif
#if TIMER_2_EN
case TIMER_2:
timer = TIMER_2_DEV;
timer->BITMODE = TIMER_BITMODE_BITMODE_16Bit; /* 16 Bit Mode */
timer->POWER = 1;
timer->BITMODE = TIMER_2_BITMODE;
NVIC_SetPriority(TIMER_2_IRQ, TIMER_IRQ_PRIO);
NVIC_EnableIRQ(TIMER_2_IRQ);
break;
Expand Down Expand Up @@ -102,14 +104,17 @@ int timer_init(tim_t dev, unsigned int ticks_per_us, void (*callback)(int))
default:
return -1;
}
/* timer->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos; */

/* clear all compare channels */
timer->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);
timer->SHORTS = (TIMER_SHORTS_COMPARE1_CLEAR_Enabled << TIMER_SHORTS_COMPARE1_CLEAR_Pos);
timer->SHORTS = (TIMER_SHORTS_COMPARE2_CLEAR_Enabled << TIMER_SHORTS_COMPARE2_CLEAR_Pos);
timer->SHORTS = (TIMER_SHORTS_COMPARE3_CLEAR_Enabled << TIMER_SHORTS_COMPARE3_CLEAR_Pos);

/* start the timer */
timer->TASKS_START = 1;

return 1;
return 0;
}

int timer_set(tim_t dev, int channel, unsigned int timeout)
Expand Down
40 changes: 38 additions & 2 deletions cpu/nrf51822/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @author Christian Kühling <kuehling@zedat.fu-berlin.de>
* @author Timo Ziegler <timo.ziegler@fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
Expand Down Expand Up @@ -117,18 +118,29 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
switch (uart) {
#if UART_0_EN
case UART_0:
/* power on UART device */
UART_0_DEV->POWER = 1;

/* reset configuration registers */
UART_0_DEV->CONFIG = 0;

/* select baudrate */
UART_0_DEV->BAUDRATE = baudrate_real;

/* configure RX/TX pin modes */
NRF_GPIO->DIRSET = (1 << UART_0_PIN_TX);
NRF_GPIO->DIRCLR = (1 << UART_0_PIN_RX);

/* configure UART pins to use */
UART_0_DEV->PSELTXD = UART_0_PIN_TX;
UART_0_DEV->PSELRXD = UART_0_PIN_RX;

/* enable hw-flow control if defined */
#if UART_0_HWFLOWCTRL
/* set pin mode for RTS and CTS pins */
NRF_GPIO->DIRSET = (1 << UART_0_PIN_RTS);
NRF_GPIO->DIRSET = (1 << UART_0_PIN_CTS);
/* configure RTS and CTS pins to use */
UART_0_DEV->PSELRTS = UART_0_PIN_RTS;
UART_0_DEV->PSELCTS = UART_0_PIN_CTS;
UART_0_DEV->CONFIG |= 1; /* enable HW flow control */
Expand All @@ -147,8 +159,6 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
#endif
}

DEBUG("UART INITIALIZATION complete\n");

return 0;
}

Expand Down Expand Up @@ -208,4 +218,30 @@ int uart_write_blocking(uart_t uart, char data)
return 1;
}

void uart_poweron(uart_t uart)
{
switch (uart) {
#if UART_0_EN
case UART_0:
UART_0_DEV->POWER = 1;
break;
#endif
default:
return;
}
}

void uart_poweroff(uart_t uart)
{
switch (uart) {
#if UART_0_EN
case UART_0:
UART_0_DEV->POWER = 0;
break;
#endif
default:
return;
}
}

#endif /* UART_NUMOF */
8 changes: 6 additions & 2 deletions cpu/nrf51822/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ void isr_nmi(void)

void isr_hard_fault(void)
{
LED_RED_ON;
while (1) {asm ("nop");}
while (1) {
for (int i = 0; i < 500000; i++) {
asm("nop");
}
LED_RED_TOGGLE;
}
}

/* Cortex-M specific interrupt vectors */
Expand Down

0 comments on commit c9c7bfa

Please sign in to comment.