Skip to content
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

porting for CH32V203 #33

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

TianpeiLee
Copy link

Hello, I have adapted on the CH32V203, and added the MRS project folder of WCH, and I verified it on the hardware provided by airbot, it works very well, thank you very much for the support of airbot.

I've changed the definition of a couple of variables by adding the keyword "volatile" in front of them to increase their compatibility under gcc, and this will not affect compilation under armcc

@tridge
Copy link
Member

tridge commented Aug 21, 2024

I've been looking at adding support for this MCU in AM32-bootloader:
https://github.com/tridge/AM32-bootloader
are you on the AM32 discord? If so please ping me and we could create a thread under development
I have a couple of CH32V203 dev boards, but need some help with getting openocd working, setup of toolchain etc

@tridge
Copy link
Member

tridge commented Sep 1, 2024

here is a rebase of this PR on top of current main with some fixes:
https://github.com/tridge/AM32/tree/pr-ch32v203-wip

@tridge
Copy link
Member

tridge commented Sep 2, 2024

I've now got the bootloader working. This AM32 tree:
https://github.com/tridge/AM32/tree/pr-ch32v203-wip
now works with this bootloader:
am32-firmware/AM32-bootloader#4

Src/main.c Outdated
@@ -1680,6 +1683,10 @@ void runBrushedLoop()

int main(void)
{
#ifdef DEBUG_SDI
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should remove this extra debug code before merge

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, all debug related code can be deleted

Src/main.c Outdated
@@ -1832,6 +1839,12 @@ int main(void)
}
#endif

#ifdef MCU_CH32V203
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a NEED_INPUT_READY define for F031 and V203, instead of copying the code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, NEED_INPUT_READY would be bettter, it was distinguished by name before.

Src/main.c Outdated
@@ -1852,6 +1865,7 @@ int main(void)
for (int i = 0; i < 64; i++) {
dma_buffer[i] = 0;
}
PRINT("reset1:%d\r\n",signaltimeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug should be removed

Src/main.c Outdated
@@ -1865,6 +1879,7 @@ int main(void)
for (int i = 0; i < 64; i++) {
dma_buffer[i] = 0;
}
PRINT("reset2:%d\r\n",signaltimeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove debug

Src/main.c Outdated
@@ -1952,15 +1967,37 @@ int main(void)
}

#ifndef MCU_F031
#ifdef WCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code should be removed

NVIC_SetPriority(COM_TIMER_IRQ, 0);
NVIC_SetPriority(COMPARATOR_IRQ, 0);
}
NVIC_SetPriority(IC_DMA_IRQ_NAME, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the whitespace changes here should be reverted

Src/main.c Outdated
@@ -1993,6 +2030,11 @@ int main(void)
adc_ordinary_software_trigger_enable(ADC1, TRUE);
// converted_degrees = (4000 - ADC_raw_temp) / 20;
converted_degrees = getConvertedDegrees(ADC_raw_temp);
#endif
#ifdef WCH
// ADC_DMA_Callback( ); //������
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments in english please

Src/signal.c Outdated
@@ -160,7 +160,13 @@ void transfercomplete()
buffersize = 2;
computeServoInput();
}
#ifdef MCU_CH32V203
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not make these changes part of receiveDShotDma() ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can indeed be moved to receiveDShotDma()

Src/sounds.c Outdated
@@ -97,7 +97,12 @@ void playStartupTune()
__disable_irq();

uint8_t value = *(uint8_t*)(EEPROM_START_ADD + 48);
if (value != 0xFF) {
#ifdef WCH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change needed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because after it is erased, its default value is 0xe339e339

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, better to have a define ERASED_FLASH_BYTE, we could default it to 0xff at the top of sounds.c, but use ifndef to allow a Mcu port to override it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah would be better

Copy link
Member

@tridge tridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR is looking pretty good now, but needs a rebase on current main branch

Src/main.c Outdated
@@ -224,7 +224,7 @@ an settings option)
#endif

#define VERSION_MAJOR 2
#define VERSION_MINOR 8
#define VERSION_MINOR 12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PR needs to be rebased on current main branch, these defines no longer exist

#ifdef WCH

void delayMicros(uint32_t micros)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not a fan of the busy loop method, depends too much on the clock selected. Works for current v203 but will fail on other variants. Don't we have a timer we can use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All timers have been used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, this delay should use the core timer, so that it can be used as long as it is a chip with the same core. However, the V203 has a total of 4 peripheral timers.

1 for scheduled task, 2 for commutation tasks, 1 for dshot signal detection task, and 1 for PWM output task,so.....

@tridge
Copy link
Member

tridge commented Sep 12, 2024

@TianpeiLee I have rebased your code and fixed some issues with it in this branch:
https://github.com/tridge/AM32/tree/pr-ch32v203-wip

TianpeiLee and others added 2 commits September 13, 2024 15:28
fix compilation errors
@tridge
Copy link
Member

tridge commented Sep 13, 2024

the commit "v203_pr" removed thousands of files, removing support for other MCUs, and removing the CI tests
please do a hard reset against my branch
https://github.com/tridge/AM32/tree/pr-ch32v203-wip

@tridge
Copy link
Member

tridge commented Sep 20, 2024

@TianpeiLee I also just noticed this PR is missing the handling of the driving_brake_strength in Src/main.c
you need to search for '#ifdef STMICRO' and make sure ch32 is handled in all the same places

@TianpeiLee
Copy link
Author

@tridge Hi,How about resubmitting the pr directly from your branch? Not only is my modification and update very slow every time, but it also fails due to network reasons.

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