Skip to content

Commit

Permalink
Merge #19558 #19598
Browse files Browse the repository at this point in the history
19558: boards: support for Olimex MSP430-H1611 board r=maribu a=maribu

### Contribution description

- implement a clock driver so that boards declare their clock configuration, rather than initializing the CPU clock in `board_init()` by hand
    - Note: A board can still overwrite the weak symbol `clock_init()` in case some really crazy things should happen
- add support for the Olimex-H1611 board


19598: dist/tools/insufficient_memory: fix collection of app folders r=maribu a=maribu

### Contribution description

There is actually a make target to list the applications in the repo. Let's just use that.


Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
  • Loading branch information
bors[bot] and maribu authored May 16, 2023
3 parents 77b1547 + e7d1c4a + 4f4616b commit 070025f
Show file tree
Hide file tree
Showing 96 changed files with 1,072 additions and 341 deletions.
98 changes: 0 additions & 98 deletions boards/common/msb-430/board_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
#include "msp430.h"
#include "debug.h"

static volatile uint32_t __msp430_cpu_speed = MSP430_INITIAL_CPU_SPEED;

void msp430_init_dco(void);

static void msb_ports_init(void)
{
/* Port 1: Free port, for energy saving all outputs are set to zero. */
Expand Down Expand Up @@ -99,101 +95,7 @@ static void msb_ports_init(void)
/* 1 - P6.7 [OUT] - unused */
}

void msp430_set_cpu_speed(uint32_t speed)
{
irq_disable();
__msp430_cpu_speed = speed;
msp430_init_dco();
irq_enable();
}

/*---------------------------------------------------------------------------*/
void msp430_init_dco(void)
{
#if MSP430_HAS_EXTERNAL_CRYSTAL
/*------------------ use external oszillator -----------------------*/
uint16_t i;

/* Stop watchdog */
WDTCTL = WDTPW + WDTHOLD;

/* Init crystal for mclk */
/* XT2 = HF XTAL */
BCSCTL1 = RSEL2;

/* Wait for xtal to stabilize */
do {
IFG1 &= ~OFIFG; /* Clear oscillator fault flag */

for (i = 0xFF; i > 0; i--); /* Time for flag to set */
}
while ((IFG1 & OFIFG) != 0); /* Oscillator fault flag still set? */

BCSCTL2 = SELM_2 + SELS; /* MCLK und SMCLK = XT2 (safe) */
#else
unsigned int delta = __msp430_cpu_speed >> 12;
unsigned int oldcapture = 0;
unsigned int i;

BCSCTL1 = 0xa4; /* ACLK is divided by 4. RSEL=6 no division for MCLK
and SSMCLK. XT2 is off. */

/* Init FLL to desired frequency using the 32762Hz crystal */
#if MSP430_HAS_DCOR
BCSCTL2 = 0x01;
#else
BCSCTL2 = 0x00;
#endif

WDTCTL = WDTPW + WDTHOLD; /* Stop WDT */
BCSCTL1 |= DIVA1 + DIVA0; /* ACLK = LFXT1CLK/8 */

for (i = 0xffff; i > 0; i--); /* Delay for XTAL to settle */

CCTL2 = CCIS0 + CM0 + CAP; /* Define CCR2, CAP, ACLK */
TACTL = TASSEL1 + TACLR + MC1; /* SMCLK, continuous mode */

while (1) {
unsigned int compare;

while ((CCTL2 & CCIFG) != CCIFG); /* Wait until capture occurred! */

CCTL2 &= ~CCIFG; /* Capture occurred, clear flag */
compare = CCR2; /* Get current captured SMCLK */
compare = compare - oldcapture; /* SMCLK difference */
oldcapture = CCR2; /* Save current captured SMCLK */

if (delta == compare) {
break; /* if equal, leave "while(1)" */
}
else if (delta < compare) { /* DCO is too fast, slow it down */
DCOCTL--;

if (DCOCTL == 0xFF) { /* Did DCO role under? */
BCSCTL1--;
}
}
else { /* -> Select next lower RSEL */
DCOCTL++;

if (DCOCTL == 0x00) { /* Did DCO role over? */
BCSCTL1++;
}

/* -> Select next higher RSEL */
}
}

CCTL2 = 0; /* Stop CCR2 function */
TACTL = 0; /* Stop Timer_A */

BCSCTL1 &= ~(DIVA1 + DIVA0); /* remove /8 divisor from ACLK again */
#endif
}

void board_init(void)
{
msb_ports_init();

msp430_set_cpu_speed(CLOCK_CORECLOCK);
}
12 changes: 0 additions & 12 deletions boards/msb-430/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ extern "C" {
#define __MSP430F1612__
#endif

/**
* @name CPU core configuration
* @{
*/
/** @todo Move this to the periph_conf.h */
#define MSP430_INITIAL_CPU_SPEED 2457600uL
#define F_CPU MSP430_INITIAL_CPU_SPEED
#define F_RC_OSCILLATOR 32768
#define MSP430_HAS_DCOR 1
#define MSP430_HAS_EXTERNAL_CRYSTAL 0
/** @} */

/**
* @name Configure on-board SHT11 device
* @{
Expand Down
23 changes: 16 additions & 7 deletions boards/msb-430/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,28 @@
#ifndef PERIPH_CONF_H
#define PERIPH_CONF_H

#include "periph_cpu.h"
#include "macros/units.h"

#ifdef __cplusplus
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq

/**
* @name Clock configuration
* @{
* @brief Clock configuration
*/
/** @todo Move all clock configuration code here from the board.h */
#define CLOCK_CORECLOCK (7372800U)

#define CLOCK_CMCLK CLOCK_CORECLOCK /* no divider programmed */
/** @} */
static const msp430_fxyz_clock_params_t clock_params = {
.target_dco_frequency = 7372800U,
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
.submain_clock_source = SUBMAIN_CLOCK_SOURCE_DCOCLK,
.main_clock_divier = MAIN_CLOCK_DIVIDE_BY_1,
.submain_clock_divier = SUBMAIN_CLOCK_DIVIDE_BY_1,
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
.has_r_osc = true,
};

/**
* @name Timer configuration
Expand Down
12 changes: 0 additions & 12 deletions boards/msb-430h/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ extern "C" {
#define __MSP430F1612__
#endif

/**
* @name CPU core configuration
* @{
*/
/** @todo Move this to the periph_conf.h */
#define MSP430_INITIAL_CPU_SPEED 7372800uL
#define F_CPU MSP430_INITIAL_CPU_SPEED
#define F_RC_OSCILLATOR 32768
#define MSP430_HAS_DCOR 1
#define MSP430_HAS_EXTERNAL_CRYSTAL 1
/** @} */

/**
* @name Configure on-board SHT11 device
* @{
Expand Down
20 changes: 13 additions & 7 deletions boards/msb-430h/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@
extern "C" {
#endif

/**
* @name Clock configuration
* @{
*/
/** @todo Move all clock configuration code here from the board.h */
#define CLOCK_CORECLOCK (7372800U)

#define CLOCK_CMCLK CLOCK_CORECLOCK /* no divider programmed */
/** @} */
/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
.xt2_frequency = CLOCK_CORECLOCK,
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_XT2CLK,
.submain_clock_source = SUBMAIN_CLOCK_SOURCE_XT2CLK,
.main_clock_divier = MAIN_CLOCK_DIVIDE_BY_1,
.submain_clock_divier = SUBMAIN_CLOCK_DIVIDE_BY_1,
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
.has_r_osc = true,
};

/**
* @name Timer configuration
Expand Down
18 changes: 18 additions & 0 deletions boards/olimex-msp430-h1611/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 HAW Hamburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.

config BOARD
default "olimex-msp430-h1611" if BOARD_OLIMEX_MSP430_H1611

config BOARD_OLIMEX_MSP430_H1611
bool
default y
select CPU_MODEL_MSP430F1611
select HAS_PERIPH_GPIO
select HAS_PERIPH_GPIO_IRQ
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
3 changes: 3 additions & 0 deletions boards/olimex-msp430-h1611/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE = board

include $(RIOTBASE)/Makefile.base
10 changes: 10 additions & 0 deletions boards/olimex-msp430-h1611/Makefile.features
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CPU = msp430fxyz
CPU_MODEL = msp430f1611

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart

# Various other features (if any)
26 changes: 26 additions & 0 deletions boards/olimex-msp430-h1611/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial-MXV*)))

# flash tool configuration
PROGRAMMER ?= mspdebug
MSPDEBUG_PROGRAMMER ?= olimex

PROGRAMMERS_SUPPORTED += mspdebug

# When freshly plugged in the Olimex MSP430-JTAG-Tiny debugger provides a
# ttyACM interface, which is only available until the first flashing. A
# `make term` or even a `make flash term` may pick the JTAG debugger instead
# of the correct USB TTL adapter when the JTAG programmer is plugged in after
# the TTL adapter and `MOST_RECENT_PORT=1` is used.
#
# To fix that, we filter first by the most common USB TTL adapter drivers and
# fall back to all TTY when no such TTL adapter is found.
TTY_BOARD_FILTER := --driver 'cp210x|ch341|ftdi_sio'
TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path serial \
$(TTY_BOARD_FILTER) || \
$(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path serial
97 changes: 97 additions & 0 deletions boards/olimex-msp430-h1611/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
@defgroup boards_olimex_msp430_h1611 Olimex MSP430-H1611
@ingroup boards
@brief Support for the Olimex MSP430-H1611 board

<img src="https://github.com/maribu/images/raw/master/Olimex%20MSP430-H1611.jpeg" alt="Photo of Olimex MSP430-H1611 Board" style="width: 512px; max-width: 100%;">

## MCU

| MCU | TI MSP430F1611 |
|:----------------- |:------------------------------------------------------------- |
| Family | MSP430 |
| Vendor | Texas Instruments |
| Package | 64 QFN |
| RAM | 10 KiB |
| Flash | 48 KiB |
| Frequency | 8 MHz |
| FPU | no |
| Timers | 2 (2x 16bit) |
| ADCs | 1x 8 channel 12-bit |
| UARTs | 2 |
| SPIs | 2 |
| I2Cs | 1 |
| Vcc | 2.0V - 3.6V |
| Datasheet MCU | [Datasheet](https://www.ti.com/product/MSP430F1611) |
| User Guide MCU | [User Guide](https://www.ti.com/lit/ug/slau049f/slau049f.pdf) |
| Datasheet Board | [MSP430-H1611 Datasheet](https://www.olimex.com/Products/MSP430/Header/_resources/MSP430-Hxxx-e.pdf) |
| Website | [MSP430-H1611 Website](https://www.olimex.com/Products/MSP430/Header/MSP430-H1611/) |

## Schematics

<img src="https://www.olimex.com/Products/MSP430/Header/_resources/MSP430-Hxxx-sch.gif" alt="Schematics of the Olimex MSP430-H1611 Board" style="max-width: 100%;">

## Pinout

The 64 pins on the edges of the PCB are connected to the corresponding MCU pins.
Hence, the following pinout of the naked MSP430-F1611 MCU chip matches the
pinout of the header board:

<img src="https://github.com/maribu/images/raw/master/MSP430F1611%20Pinout.svg" alt="Pinout of the naked MSP430-F1611 MCU" style="width: 512px; max-width: 100%;">

## Flashing RIOT

<img src="https://github.com/maribu/images/raw/master/Olimex%20MSP430-H1611%20with%20Debugger.jpeg" alt="Photo of Olimex MSP430-H1611 Board connected to a JTAG Debugger" style="width: 512px; max-width: 100%;">

Connect the board to a JTAG debugger supported by
[mspdebug](https://dlbeer.co.nz/mspdebug/); by default the
Olimex MSP430-JTAG-Tiny (as shown in the picture above) is assumed, which is
among the less expensive options.

@note If you are not using the Olimex MSP430-JTAG-Tiny (or a compatible
programmer), set `MSPDEBUG_PROGRAMMER` to the correct value via
an environment variable or as parameter to make. E.g. use
`make BOARD=olimex-msp430-h1611 MSPDEBUG_PROGRAMMER=bus-pirate` to
flash using the bus pirate.

@warning You can power the board via the JTAG programmer by placing a
jumper at `P_IN`. However, the JTAG programmer will only be able
to provide a limited current. You may want to disconnect the
header board from devices consuming a lot of power prior to
flashing.

@warning If the board is powered externally, make sure to place the jumper
in `P_OUT` position, not in `P_IN` position.

@warning A jumper in `P_OUT` is mutually exclusive to a jumper in `P_IN`.
Never connect both at the same time.

@note While the JTAG connector has no markings, you can easily spot pin 1
on to bottom of the board by the square pad; all other JTAG pins
have a circular pad.

Once the jumper is correctly placed in either `P_IN` or in `P_OUT` and the
JTAG cable is connected just run

```
make BOARD=olimex-msp430-h1611 flash
```

## Using the shell

stdio is available via the UART interface with `TXD = P3.6`
(pin 35 on the header) and `RXD = P3.7` (pin 34 on the header) at 115,200 Baud.

The easiest way is to connect an USB TTL adapter (such as the cheap `cp210x`
or `ch341` based adapters) as follows:

```
TTL adapter Olimex MSP430-H1611
----------- -------------------

GND --- 63 (DV_SS)
TXD --- 35 (P3.7)
RXD --- 34 (P3.6)
```

*/
22 changes: 22 additions & 0 deletions boards/olimex-msp430-h1611/include/board-conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2014 INRIA
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

#ifndef BOARD_CONF_H
#define BOARD_CONF_H

#ifdef __cplusplus
extern "C" {
#endif

#define INFOMEM (0x1000)

#ifdef __cplusplus
}
#endif

#endif /* BOARD_CONF_H */
Loading

0 comments on commit 070025f

Please sign in to comment.