Skip to content

Commit

Permalink
BlackPill buttons example
Browse files Browse the repository at this point in the history
Description:
Example to interact with KEY button and user external button connected to PA1.
For KEY button pull-up resistor is active, board schematic does not show any pull-up or pull-down resistor.

Results: Example working as expected.

BlackPill PWM example

Description:
PWM example using PB0 - Timer3 - Channel 3
Create default configuration for the example.

Controlling_RGB_LED

Description: Controlling a RGB LED on NuttX for Black Pill board [STM32F411]

Note: Example currently not working as expected.
  • Loading branch information
samudiio authored and xiaoxiang781216 committed Aug 27, 2024
1 parent 447f03c commit a6df724
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 5 deletions.
53 changes: 53 additions & 0 deletions boards/arm/stm32/stm32f411-minimum/configs/pwm/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_DISABLE_OS_API is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_STM32_SYSCFG is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f411-minimum"
CONFIG_ARCH_BOARD_STM32F411_MINIMUM=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F411CE=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_PWM=y
CONFIG_HAVE_CXX=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PWM=y
CONFIG_RAM_SIZE=131072
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2020
CONFIG_STM32_FLASH_CONFIG_E=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_TIM3=y
CONFIG_STM32_TIM3_CH3OUT=y
CONFIG_STM32_TIM3_CHANNEL=3
CONFIG_STM32_TIM3_PWM=y
CONFIG_STM32_USART1=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USART1_SERIAL_CONSOLE=y
69 changes: 69 additions & 0 deletions boards/arm/stm32/stm32f411-minimum/configs/rgbled/defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_DISABLE_OS_API is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_DISABLE_IFCONFIG is not set
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_STM32_SYSCFG is not set
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f411-minimum"
CONFIG_ARCH_BOARD_STM32F411_MINIMUM=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F411CE=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LOOPSPERMSEC=8499
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_RGBLED=y
CONFIG_HAVE_CXX=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_PWM=y
CONFIG_RAM_SIZE=131072
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RGBLED=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=6
CONFIG_START_YEAR=2020
CONFIG_STM32_FLASH_CONFIG_E=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_TIM1=y
CONFIG_STM32_TIM1_CH1OUT=y
CONFIG_STM32_TIM1_CHMODE=0
CONFIG_STM32_TIM1_PWM=y
CONFIG_STM32_TIM2=y
CONFIG_STM32_TIM2_CH2OUT=y
CONFIG_STM32_TIM2_CHANNEL=2
CONFIG_STM32_TIM2_CHMODE=0
CONFIG_STM32_TIM2_PWM=y
CONFIG_STM32_TIM3=y
CONFIG_STM32_TIM3_CH3OUT=y
CONFIG_STM32_TIM3_CHANNEL=3
CONFIG_STM32_TIM3_CHMODE=0
CONFIG_STM32_TIM3_PWM=y
CONFIG_STM32_TIM4=y
CONFIG_STM32_TIM4_CH4OUT=y
CONFIG_STM32_TIM4_CHANNEL=4
CONFIG_STM32_TIM4_CHMODE=0
CONFIG_STM32_TIM4_PWM=y
CONFIG_STM32_USART1=y
CONFIG_SYSTEM_NSH=y
CONFIG_TASK_NAME_SIZE=0
CONFIG_USART1_SERIAL_CONSOLE=y
30 changes: 28 additions & 2 deletions boards/arm/stm32/stm32f411-minimum/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@
#define GPIO_USART6_RX GPIO_USART6_RX_1 /* PC7 */
#define GPIO_USART6_TX GPIO_USART6_TX_1 /* PC6 */

/* PWM
*
* The STM32F4 Discovery has no real on-board PWM devices, but the board
* can be configured to output a pulse train using TIM4 CH2 on PD13.
*/
#define GPIO_TIM1_CH1OUT GPIO_TIM1_CH1OUT_1 //PA8
#define GPIO_TIM2_CH2OUT GPIO_TIM2_CH2OUT_1 //PA1
#define GPIO_TIM3_CH3OUT GPIO_TIM3_CH3OUT_1 //PB0
#define GPIO_TIM4_CH4OUT GPIO_TIM4_CH4OUT_1 //PB9

/* RGB LED
*
* R = TIM1 CH1 on PA8 | G = TIM2 CH2 on PA1 | B = TIM4 CH4 on PB9
*
* Note: Pin boards: GPIO_TIM1_CH1OUT ; GPIO_TIM2_CH2OUT ; GPIO_TIM4_CH4OUT
*/

#define RGBLED_RPWMTIMER 1
#define RGBLED_RPWMCHANNEL 1
#define RGBLED_GPWMTIMER 2
#define RGBLED_GPWMCHANNEL 2
#define RGBLED_BPWMTIMER 4
#define RGBLED_BPWMCHANNEL 4

/* UART RX DMA configurations */

#define DMAMAP_USART1_RX DMAMAP_USART1_RX_2
Expand Down Expand Up @@ -321,8 +345,10 @@
*/

#define BUTTON_USER 0
#define NUM_BUTTONS 1
#define BUTTON_EXTERNAL 1 //External user button connected to PA1
#define NUM_BUTTONS 2

#define BUTTON_USER_BIT (1 << BUTTON_USER)
#define BUTTON_USER_BIT (1 << BUTTON_USER)
#define BUTTON_EXTERNAL_BIT (1 << BUTTON_EXTERNAL)

#endif /* __BOARDS_ARM_STM32_STM32F411_MINIMUM_INCLUDE_BOARD_H */
12 changes: 12 additions & 0 deletions boards/arm/stm32/stm32f411-minimum/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ if(CONFIG_USERLED)
list(APPEND SRCS stm32_userleds.c)
endif()

if(CONFIG_ARCH_BUTTONS)
list(APPEND SRCS stm32_buttons.c)
endif()

if(CONFIG_PWM)
list(APPEND SRCS stm32_pwm.c)
endif()

if(CONFIG_RGBLED)
list(APPEND SRCS stm32_rgbled.c)
endif()

if(CONFIG_SPI)
list(APPEND SRCS stm32_spi.c)
endif()
Expand Down
12 changes: 12 additions & 0 deletions boards/arm/stm32/stm32f411-minimum/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ ifeq ($(CONFIG_USERLED),y)
CSRCS += stm32_userleds.c
endif

ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += stm32_buttons.c
endif

ifeq ($(CONFIG_PWM),y)
CSRCS += stm32_pwm.c
endif

ifeq ($(CONFIG_RGBLED),y)
CSRCS += stm32_rgbled.c
endif

ifeq ($(CONFIG_ADC_HX711),y)
CSRCS += stm32_hx711.c
endif
Expand Down
34 changes: 34 additions & 0 deletions boards/arm/stm32/stm32f411-minimum/src/stm32_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
# include <nuttx/leds/userled.h>
#endif

#ifdef CONFIG_INPUT_BUTTONS
# include <nuttx/input/buttons.h>
#endif

#ifdef CONFIG_STM32_OTGFS
# include "stm32_usbhost.h"
#endif
Expand Down Expand Up @@ -98,6 +102,36 @@ int stm32_bringup(void)
}
#endif

#ifdef CONFIG_INPUT_BUTTONS
/* Register the BUTTON driver */

ret = btn_lower_initialize("/dev/buttons");
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
}
#endif

#ifdef CONFIG_PWM
/* Initialize PWM and register the PWM device. */

ret = stm32_pwm_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_pwm_setup() failed: %d\n", ret);
}
#endif

#ifdef CONFIG_RGBLED
/* Configure and initialize the RGB LED. */

ret = stm32_rgbled_setup();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: stm32_rgbled_setup() failed: %d\n", ret);
}
#endif

#ifdef CONFIG_STM32F411MINIMUM_GPIO
ret = stm32_gpio_initialize();
if (ret != OK)
Expand Down
Loading

0 comments on commit a6df724

Please sign in to comment.