Skip to content

Allow different port and mode for LED on ch32v boards #3014

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

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

deshipu
Copy link
Contributor

@deshipu deshipu commented Mar 7, 2025

While there is a define for the port, the clock enable is hardcoded for GPIOA, so setting a different port than GPIOA doesn't work. This fixes it by adding a define for enabling the port clock.

It also adds a define for the pin mode, because not all boards have the LED connected in a way that open drain works with it.

@HiFiPhile
Copy link
Collaborator

Thank you for the PR, I think you missed APB1 and APB2.

CI failed with:

In file included from /home/circleci/project/hw/bsp/ch32v20x/family.c:21:
/home/circleci/project/hw/bsp/ch32v20x/family.c: In function 'board_init':
/home/circleci/project/hw/bsp/ch32v20x/boards/nanoch32v203/board.h:16:47: error: 'RCC_APB1Periph_GPIOA' undeclared (first use in this function); did you mean 'RCC_APB2Periph_GPIOA'?
   16 | #define LED_CLOCK_EN() RCC_APB1PeriphClockCmd(RCC_APB1Periph_GPIOA, ENABLE)
      |                                               ^~~~~~~~~~~~~~~~~~~~
/home/circleci/project/hw/bsp/ch32v20x/family.c:99:3: note: in expansion of macro 'LED_CLOCK_EN'
   99 |   LED_CLOCK_EN();
      |   ^~~~~~~~~~~~
compilation terminated due to -Wfatal-errors.

@deshipu
Copy link
Contributor Author

deshipu commented Apr 6, 2025

You are right, I'm sorry I didn't notice it. I only tested it on my own board that has the LED on port C, which is APB2. I'll fix it immediately.

While there is a define for the port, the clock enable is hardcoded for
GPIOA, so setting a different port than GPIOA doesn't work. This fixes
it by adding a define for enabling the port clock.

It also adds a define for the pin mode, because not all boards have the
LED connected in a way that open drain works with it.
@HiFiPhile HiFiPhile merged commit 865e348 into hathach:master Apr 6, 2025
109 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants