Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19268: shell_lock: don't set CONFIG_SHELL_SHUTDOWN_ON_EXIT r=benpicco a=benpicco



19629: cpu/stm32/periph/adc: fix setting ADC clock r=benpicco a=Enoch247

### Contribution description

The current implementation uses the core clock frequency to calculate the needed prescalar to achieve a given ADC clock frequency. This is incorrect. This patch fixes the calculation to use the correct source clock (PCKLK2 ie APB2). It also changes the defined max clock rate to use the frequency macro to improve readability.

I based on code similarity. I believe the gd32v CPU may need this same fix, but I am not familiar with that MCU.

### Testing procedure

I tested this on a nucleo-f767zi. The the MCU's reference manual is in agreement with what I have implemented here. I spot checked references manuals for a random [STM32F1](https://www.st.com/resource/en/reference_manual/cd00171190-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf) and [STM32F2](https://www.st.com/resource/en/reference_manual/rm0033-stm32f205xx-stm32f207xx-stm32f215xx-and-stm32f217xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf), and they are clocked similar to the F7 I have.

### Issues/PRs references

None known.


19670: cpu/stm32: stm32f4 BRR from BSRR r=benpicco a=kfessel

### Contribution description

sometimes one wants to save one instruction :) 
just write the bits we need to write.

### Testing procedure

tests/periph/gpio_ll tests this 

### Issues/PRs references

`@maribu` might know some reference

maybe #19407

Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Joshua DeWeese <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
  • Loading branch information
5 people authored May 27, 2023
4 parents 1710650 + c0a4acf + fe28f93 + ce88a96 commit 5812713
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cpu/stm32/include/gpio_ll_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static inline void gpio_ll_clear(gpio_port_t port, uword_t mask)
#if defined(GPIO_BRR_BR0) && !defined(CPU_FAM_STM32F4)
p->BRR = mask;
#else
p->BSRR = mask << 16;
uint16_t *brr = (void *)&(p->BSRR);
brr[1] = (uint16_t)mask;
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32/periph/adc_f1.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @brief Maximum allowed ADC clock speed
*/
#define MAX_ADC_SPEED (14000000U)
#define MAX_ADC_SPEED MHZ(14)

/**
* @brief Allocate locks for all three available ADC devices
Expand Down Expand Up @@ -93,7 +93,7 @@ int adc_init(adc_t line)
}
/* set clock prescaler to get the maximal possible ADC clock value */
for (clk_div = 2; clk_div < 8; clk_div += 2) {
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
if ((periph_apb_clk(APB2) / clk_div) <= MAX_ADC_SPEED) {
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32/periph/adc_f2.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* @brief Maximum allowed ADC clock speed
*/
#define MAX_ADC_SPEED (12000000U)
#define MAX_ADC_SPEED MHZ(12)

/**
* @brief Default VBAT undefined value
Expand Down Expand Up @@ -86,7 +86,7 @@ int adc_init(adc_t line)
}
/* set clock prescaler to get the maximal possible ADC clock value */
for (clk_div = 2; clk_div < 8; clk_div += 2) {
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
if ((periph_apb_clk(APB2) / clk_div) <= MAX_ADC_SPEED) {
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpu/stm32/periph/adc_f4_f7.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @brief Maximum allowed ADC clock speed
*/
#define MAX_ADC_SPEED (12000000U)
#define MAX_ADC_SPEED MHZ(12)

/**
* @brief Maximum sampling time for each channel (480 cycles)
Expand Down Expand Up @@ -94,7 +94,7 @@ int adc_init(adc_t line)
dev(line)->CR2 = ADC_CR2_ADON;
/* set clock prescaler to get the maximal possible ADC clock value */
for (clk_div = 2; clk_div < 8; clk_div += 2) {
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
if ((periph_apb_clk(APB2) / clk_div) <= MAX_ADC_SPEED) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion sys/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C" {
* Instead terminate RIOT, which is also the behavior a user would
* expect from a CLI application.
*/
# if defined(CPU_NATIVE)
# if defined(CPU_NATIVE) && !IS_ACTIVE(MODULE_SHELL_LOCK)
# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 1
# else
# define CONFIG_SHELL_SHUTDOWN_ON_EXIT 0
Expand Down
5 changes: 5 additions & 0 deletions sys/include/shell_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ void shell_lock_checkpoint(char *line_buf, int buf_size);
*/
bool shell_lock_is_locked(void);

/**
* @brief Lock the shell
*/
void shell_lock_do_lock(void);

#ifdef MODULE_SHELL_LOCK_AUTO_LOCKING
/**
* @brief Restart the timeout interval before the shell is locked
Expand Down
3 changes: 3 additions & 0 deletions sys/shell/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ void shell_run_once(const shell_command_t *shell_commands,
switch (res) {

case EOF:
if (IS_USED(MODULE_SHELL_LOCK)) {
shell_lock_do_lock();
}
return;

case -ENOBUFS:
Expand Down
7 changes: 6 additions & 1 deletion sys/shell_lock/shell_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ static void _login_barrier(char *line_buf, size_t buf_size)
#ifdef MODULE_STDIO_TELNET
void telnet_cb_disconneced(void)
{
_shell_is_locked = true;
shell_lock_do_lock();
}
#endif

void shell_lock_do_lock(void)
{
_shell_is_locked = true;
}

#ifdef MODULE_SHELL_LOCK_AUTO_LOCKING
static void _shell_auto_lock_ztimer_callback(void *arg)
{
Expand Down
4 changes: 0 additions & 4 deletions tests/sys/shell_lock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ CFLAGS += -DCONFIG_SHELL_LOCK_PASSWORD=\"password\"
CFLAGS += -DCONFIG_SHELL_LOCK_AUTO_LOCK_TIMEOUT_MS=7000
endif

# This config defaults to 1 on native, such that pm_off() would be called as soon as
# shell_run_once is terminated in shell_run_forever. We do not want this behavior for this test.
CFLAGS += -DCONFIG_SHELL_SHUTDOWN_ON_EXIT=0

# test_utils_interactive_sync_shell assumes that the prompt is always '> ' which breaks
# with the password prompt of the shell_lock module which is different from the shell's prompt
DISABLE_MODULE += test_utils_interactive_sync_shell
Expand Down

0 comments on commit 5812713

Please sign in to comment.