Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19770: cpu/nrf5x_common: reset all available CC channels r=maribu a=dylad

### Contribution description

Properly reset all CC channels of a given timer at initialization (except the last one which seems to be used for capture only in the driver).
The issue with the previous code was that some CCs were not clear on some nRF52 MCUs.
For instance, nRF52840 has 4 CCs for its two first timers, then 6 CCs for all others.
nRF9160 and nRF5340 also have 6 CCs for all its timer peripherals.
Thus, loop through the reported number of channels and clear the associated register instead of hardcoding the first 3 CC channels.


### Testing procedure
CI should be enough I think.

### Issues/PRs references
None.



19773: cpu/nrf{52,9160}: remove duplicate sevonpend bit r=maribu a=dylad

### Contribution description
This PR removes duplicate calls of `SCB_SCR_SEVONPEND` bit in nRF52 and nRF9160.
This call is already done [here](https://github.com/RIOT-OS/RIOT/blob/7c320055a1d83f8fc2a9e16562a72c700bb3e01c/cpu/cortexm_common/cortexm_init.c#L60) 

### Testing procedure
Flash a nRF52 or nRF9160-based board and check that the board is still alive.


### Issues/PRs references
None. I notice this duplicate call when porting nRF53.


19774: boards/frdm-k22f: fixes long lines in periph_conf.h r=maribu a=hugueslarrive



19775: boards/frdm-k64f: fixes long lines and comma separated by whitespaces… r=maribu a=hugueslarrive

… warnings



Co-authored-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Co-authored-by: dylad <dylan.laduranty@mesotic.com>
Co-authored-by: Hugues Larrive <hlarrive@pm.me>
  • Loading branch information
3 people authored Jul 4, 2023
5 parents e0361ab + a73ddbd + 1e0b58a + fcc7ce5 + d339437 commit 852e9c5
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 48 deletions.
62 changes: 48 additions & 14 deletions boards/frdm-k22f/include/periph_conf.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2017 Eistec AB
* 2021-2023 Hugues Larrive
*
* 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
Expand All @@ -14,6 +15,7 @@
* @name Peripheral MCU configuration for the FRDM-K22F
*
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
* @author Hugues Larrive <hugues.larrive@pm.me>
*/

#ifndef PERIPH_CONF_H
Expand Down Expand Up @@ -141,22 +143,54 @@ static const uart_conf_t uart_config[] = {
*/
static const adc_conf_t adc_config[] = {
/* dev, pin, channel */
[ 0] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC0_DP0 */
[ 1] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC0_DM0 */
[ 2] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC1_DP0 */
[ 3] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC1_DM0 */
[ 4] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 0), .chan = 8, .avg = ADC_AVG_MAX }, /* PTB0 (Arduino A0) */
[ 5] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 1), .chan = 9, .avg = ADC_AVG_MAX }, /* PTB1 (Arduino A1) */
[ 6] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 1), .chan = 15, .avg = ADC_AVG_MAX }, /* PTC1 (Arduino A2) */
[ 7] = { .dev = ADC0, .pin = GPIO_PIN(PORT_C, 2), .chan = 4, .avg = ADC_AVG_MAX }, /* PTC2 (Arduino A3) */
[0] = { /* ADC0_DP0 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 0, .avg = ADC_AVG_MAX
},
[1] = { /* ADC0_DM0 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 19, .avg = ADC_AVG_MAX
},
[2] = { /* ADC1_DP0 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 0, .avg = ADC_AVG_MAX
},
[3] = { /* ADC1_DM0 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 19, .avg = ADC_AVG_MAX
},
[4] = { /* PTB0 (Arduino A0) */
.dev = ADC0, .pin = GPIO_PIN(PORT_B, 0),
.chan = 8, .avg = ADC_AVG_MAX
},
[5] = { /* PTB1 (Arduino A1) */
.dev = ADC0, .pin = GPIO_PIN(PORT_B, 1),
.chan = 9, .avg = ADC_AVG_MAX
},
[6] = { /* PTC1 (Arduino A2) */
.dev = ADC0, .pin = GPIO_PIN(PORT_C, 1),
.chan = 15, .avg = ADC_AVG_MAX
},
[7] = { /* PTC2 (Arduino A3) */
.dev = ADC0, .pin = GPIO_PIN(PORT_C, 2),
.chan = 4, .avg = ADC_AVG_MAX
},
/* internal: temperature sensor */
/* The temperature sensor has a very high output impedance, it must not be
* sampled using hardware averaging, or the sampled values will be garbage */
[ 8] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 26, .avg = ADC_AVG_NONE },
/* The temperature sensor has a very high output impedance, it must
* not be sampled using hardware averaging, or the sampled values
* will be garbage */
[8] = {
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 26, .avg = ADC_AVG_NONE
},
/* internal: band gap */
/* Note: the band gap buffer uses a bit of current and is turned off by default,
* Set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading or the input will be floating */
[ 9] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 27, .avg = ADC_AVG_MAX },
/* Note: the band gap buffer uses a bit of current and is turned off
* by default, set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading
* or the input will be floating */
[9] = {
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 27, .avg = ADC_AVG_MAX
},
};

#define ADC_NUMOF ARRAY_SIZE(adc_config)
Expand Down
114 changes: 89 additions & 25 deletions boards/frdm-k64f/include/periph_conf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2015 PHYTEC Messtechnik GmbH
* 2015 PHYTEC Messtechnik GmbH
* 2023 Hugues Larrive
*
* 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
Expand All @@ -15,6 +16,7 @@
* @name Peripheral MCU configuration for the FRDM-K64F
*
* @author Johann Fischer <j.fischer@phytec.de>
* @author Hugues Larrive <hugues.larrive@pm.me>
*/

#ifndef PERIPH_CONF_H
Expand Down Expand Up @@ -127,32 +129,94 @@ static const uart_conf_t uart_config[] = {
* @{
*/
static const adc_conf_t adc_config[] = {
[ 0] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 2), .chan = 12, .avg = ADC_AVG_MAX }, /* PTB2 (Arduino A0) */
[ 1] = { .dev = ADC0, .pin = GPIO_PIN(PORT_B, 3), .chan = 13, .avg = ADC_AVG_MAX }, /* PTB3 (Arduino A1) */
[ 2] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 10), .chan = 14, .avg = ADC_AVG_MAX }, /* PTB10 (Arduino A2) */
[ 3] = { .dev = ADC1, .pin = GPIO_PIN(PORT_B, 11), .chan = 15, .avg = ADC_AVG_MAX }, /* PTB11 (Arduino A3) */
[ 4] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 11), .chan = 7, .avg = ADC_AVG_MAX }, /* PTC11 (Arduino A4) */
[ 5] = { .dev = ADC1, .pin = GPIO_PIN(PORT_C, 10), .chan = 6, .avg = ADC_AVG_MAX }, /* PTC10 (Arduino A5) */
[ 6] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC0_DP0 */
[ 7] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC0_DM0 */
[ 8] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC0_DP0 - ADC0_DM0 */
[ 9] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 0, .avg = ADC_AVG_MAX }, /* ADC1_DP0 */
[10] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 19, .avg = ADC_AVG_MAX }, /* ADC1_DM0 */
[11] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC1_DP0 - ADC1_DM0 */
[12] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 1, .avg = ADC_AVG_MAX }, /* ADC0_DP1 */
[13] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = 20, .avg = ADC_AVG_MAX }, /* ADC0_DM1 */
[14] = { .dev = ADC0, .pin = GPIO_UNDEF , .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC0_DP1 - ADC0_DM1 */
[15] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 1, .avg = ADC_AVG_MAX }, /* ADC1_DP1 */
[16] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = 20, .avg = ADC_AVG_MAX }, /* ADC1_DM1 */
[17] = { .dev = ADC1, .pin = GPIO_UNDEF , .chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX }, /* ADC1_DP1 - ADC1_DM1 */
[ 0] = { /* PTB2 (Arduino A0) */
.dev = ADC0, .pin = GPIO_PIN(PORT_B, 2),
.chan = 12, .avg = ADC_AVG_MAX
},
[ 1] = { /* PTB3 (Arduino A1) */
.dev = ADC0, .pin = GPIO_PIN(PORT_B, 3),
.chan = 13, .avg = ADC_AVG_MAX
},
[ 2] = { /* PTB10 (Arduino A2) */
.dev = ADC1, .pin = GPIO_PIN(PORT_B, 10),
.chan = 14, .avg = ADC_AVG_MAX
},
[ 3] = { /* PTB11 (Arduino A3) */
.dev = ADC1, .pin = GPIO_PIN(PORT_B, 11),
.chan = 15, .avg = ADC_AVG_MAX
},
[ 4] = { /* PTC11 (Arduino A4) */
.dev = ADC1, .pin = GPIO_PIN(PORT_C, 11),
.chan = 7, .avg = ADC_AVG_MAX
},
[ 5] = { /* PTC10 (Arduino A5) */
.dev = ADC1, .pin = GPIO_PIN(PORT_C, 10),
.chan = 6, .avg = ADC_AVG_MAX
},
[ 6] = { /* ADC0_DP0 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 0, .avg = ADC_AVG_MAX
},
[ 7] = { /* ADC0_DM0 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 19, .avg = ADC_AVG_MAX
},
[ 8] = { /* ADC0_DP0 - ADC0_DM0 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
},
[ 9] = { /* ADC1_DP0 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 0, .avg = ADC_AVG_MAX
},
[10] = { /* ADC1_DM0 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 19, .avg = ADC_AVG_MAX
},
[11] = { /* ADC1_DP0 - ADC1_DM0 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = (0 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
},
[12] = { /* ADC0_DP1 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 1, .avg = ADC_AVG_MAX
},
[13] = { /* ADC0_DM1 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 20, .avg = ADC_AVG_MAX
},
[14] = { /* ADC0_DP1 - ADC0_DM1 */
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
},
[15] = { /* ADC1_DP1 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 1, .avg = ADC_AVG_MAX
},
[16] = { /* ADC1_DM1 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = 20, .avg = ADC_AVG_MAX
},
[17] = { /* ADC1_DP1 - ADC1_DM1 */
.dev = ADC1, .pin = GPIO_UNDEF,
.chan = (1 | ADC_SC1_DIFF_MASK), .avg = ADC_AVG_MAX
},
/* internal: temperature sensor */
/* The temperature sensor has a very high output impedance, it must not be
* sampled using hardware averaging, or the sampled values will be garbage */
[18] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 26, .avg = ADC_AVG_NONE },
/* The temperature sensor has a very high output impedance, it must
* not be sampled using hardware averaging, or the sampled values
* will be garbage */
[18] = {
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 26, .avg = ADC_AVG_NONE
},
/* internal: band gap */
/* Note: the band gap buffer uses a bit of current and is turned off by default,
* Set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading or the input will be floating */
[19] = { .dev = ADC0, .pin = GPIO_UNDEF, .chan = 27, .avg = ADC_AVG_MAX },
/* Note: the band gap buffer uses a bit of current and is turned off
* by default, set PMC->REGSC |= PMC_REGSC_BGBE_MASK before reading
* or the input will be floating */
[19] = {
.dev = ADC0, .pin = GPIO_UNDEF,
.chan = 27, .avg = ADC_AVG_MAX
},
};

#define ADC_NUMOF ARRAY_SIZE(adc_config)
Expand Down
3 changes: 0 additions & 3 deletions cpu/nrf52/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ void cpu_init(void)
/* call cortexm default initialization */
cortexm_init();

/* enable wake up on events for __WFE CPU sleep */
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

/* initialize stdio prior to periph_init() to allow use of DEBUG() there */
early_init();

Expand Down
6 changes: 3 additions & 3 deletions cpu/nrf5x_common/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
}

/* reset compare state */
dev(tim)->EVENTS_COMPARE[0] = 0;
dev(tim)->EVENTS_COMPARE[1] = 0;
dev(tim)->EVENTS_COMPARE[2] = 0;
for (unsigned i = 0; i < timer_config[tim].channels; i++) {
dev(tim)->EVENTS_COMPARE[i] = 0;
}

/* enable interrupts */
NVIC_EnableIRQ(timer_config[tim].irqn);
Expand Down
3 changes: 0 additions & 3 deletions cpu/nrf9160/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ void cpu_init(void)
/* call cortexm default initialization */
cortexm_init();

/* enable wake up on events for __WFE CPU sleep */
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;

/* initialize stdio prior to periph_init() to allow use of DEBUG() there */
early_init();

Expand Down

0 comments on commit 852e9c5

Please sign in to comment.