Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add (untested) support for UART output. #10

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*.dylib

# Executables
*.bin
*.exe
*.out
*.app
Expand All @@ -31,6 +32,9 @@
# Debug files
*.dSYM/
*.su
*.d
*.dump
*.map

# Tarballs/compressed files
*.zip
Expand Down
5 changes: 3 additions & 2 deletions efm32hg-blinky/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ LFLAGS = -mcpu=cortex-m0plus \
-Wl,--start-group \
-lgcc \
-lc_nano \
-lnosys \
-Wl,--end-group


Expand Down Expand Up @@ -133,7 +132,9 @@ deps:
GECKO_A_SRC = Gecko_SDK/Device/SiliconLabs/EFM32HG/Source/GCC/startup_efm32hg.S
GECKO_C_SRC = $(shell find Gecko_SDK/emlib/src -name \*.c) \
Gecko_SDK/Device/SiliconLabs/EFM32HG/Source/system_efm32hg.c \
Gecko_SDK/kits/common/drivers/capsense.c
Gecko_SDK/kits/common/drivers/capsense.c \
Gecko_SDK/kits/common/drivers/retargetio.c \
Gecko_SDK/kits/common/drivers/retargetserial.c
GECKO_OBJ = $(patsubst %.S,%.o,$(GECKO_A_SRC)) \
$(patsubst %.c,%.o,$(GECKO_C_SRC))

Expand Down
21 changes: 19 additions & 2 deletions efm32hg-blinky/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>

#include "capsense.h"
#include "retargetserial.h"

#include "em_chip.h"
#include "em_cmu.h"
#include "em_device.h"
Expand Down Expand Up @@ -46,31 +49,43 @@ int main() {
// errata (implements workarounds, etc).
CHIP_Init();

// Initialise the LEUART, and map output from printf() to it.
RETARGET_SerialInit();
RETARGET_SerialCrLf(1);

// Switch on the clock for GPIO. Even though there's no immediately obvious
// timing stuff going on beyond the SysTick below, it still needs to be
// enabled for the GPIO to work.
printf("Enabling GPIO clock\n");
CMU_ClockEnable(cmuClock_GPIO, true);

// Sets up and enable the `SysTick_Handler' interrupt to fire once every 1ms.
// ref: http://community.silabs.com/t5/Official-Blog-of-Silicon-Labs/Chapter-5-MCU-Clocking-Part-2-The-SysTick-Interrupt/ba-p/145297
printf("Starting systick timer\n");
if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) {
// Something went wrong.
printf("ERROR WHILST INITIALISING SYSTICK TIMER! HALTING.\n");
while (1);
}

// Set up two pins with the GPIO controller and configure them to be open
// drain:
// - PA0 == green
// - PB7 == red
printf("Setting up GPIO pins to be open-drain\n");
GPIO_PinModeSet(gpioPortA, 0, gpioModeWiredAnd, 0);
GPIO_PinModeSet(gpioPortB, 7, gpioModeWiredAnd, 0);

// Enable the capacitive touch sensor. Remember, this consumes TIMER0 and
// TIMER1, so those are off-limits to us.
printf("Initialising the capacitive touch sensor\n");
CAPSENSE_Init();

// Blink infinitely, in an aviation-like pattern.
// Blink infinitely.
printf("Beginning application loop.\n");
while (1) {
printf("Hello world\n");

// Clear the PA0 bit, allowing the FET to sink to ground and thus lighting
// up the green LED.
GPIO_PinOutClear(gpioPortA, 0);
Expand Down Expand Up @@ -102,6 +117,7 @@ int main() {
// touched, rapid blink the green LED ten times.
if (CAPSENSE_getPressed(BUTTON0_CHANNEL) &&
!CAPSENSE_getPressed(BUTTON1_CHANNEL)) {
printf("Detected touch near green LED\n");
int i;
for (i = 10; i > 0; i--) {
GPIO_PinOutClear(gpioPortA, 0);
Expand All @@ -113,6 +129,7 @@ int main() {
// touched, rapid blink the red LED ten times.
} else if (CAPSENSE_getPressed(BUTTON1_CHANNEL) &&
!CAPSENSE_getPressed(BUTTON0_CHANNEL)) {
printf("Detected touch near red LED\n");
int i;
for (i = 10; i > 0; i--) {
GPIO_PinOutClear(gpioPortB, 7);
Expand Down
35 changes: 35 additions & 0 deletions efm32hg-blinky/retargetserialconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This file contains configuration/settings for the Gecko SDK-provided
// "retargetserial" driver at Gecko_SDK/kits/common/drivers/retargetserial.c.

#ifndef _RETARGETSERIALCONFIG_H
#define _RETARGETSERIALCONFIG_H

#define RETARGET_CLK cmuClock_LEUART0
#define RETARGET_IRQ_NAME LEUART0_IRQHandler
#define RETARGET_IRQn LEUART0_IRQn
#define RETARGET_LEUART 1
#define RETARGET_LOCATION LEUART_ROUTE_LOCATION_LOC1
#define RETARGET_PERIPHERAL_ENABLE()
#define RETARGET_RX LEUART_Rx
#define RETARGET_RXPIN 14
#define RETARGET_RXPORT gpioPortB
#define RETARGET_TX LEUART_Tx
#define RETARGET_TXPIN 13
#define RETARGET_TXPORT gpioPortB
#define RETARGET_UART LEUART0

#endif /* _RETARGETSERIALCONFIG_H */