-
Notifications
You must be signed in to change notification settings - Fork 84
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
base: main
Are you sure you want to change the base?
Conversation
I've been looking at adding support for this MCU in AM32-bootloader: |
here is a rebase of this PR on top of current main with some fixes: |
I've now got the bootloader working. This AM32 tree: |
Src/main.c
Outdated
@@ -1680,6 +1683,10 @@ void runBrushedLoop() | |||
|
|||
int main(void) | |||
{ | |||
#ifdef DEBUG_SDI |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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( ); //������ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() ?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah would be better
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) | ||
{ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.....
@TianpeiLee I have rebased your code and fixed some issues with it in this branch: |
fix compilation errors
the commit "v203_pr" removed thousands of files, removing support for other MCUs, and removing the CI tests |
@TianpeiLee I also just noticed this PR is missing the handling of the driving_brake_strength in Src/main.c |
@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. |
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