Skip to content

Commit

Permalink
Merge pull request #73 from arcayi/gd32e23x-support
Browse files Browse the repository at this point in the history
Gd32e23x ADC + GD32_ISP_CLI support
  • Loading branch information
maxgerhardt authored Aug 8, 2022
2 parents f7423b5 + 4c4d02a commit 977fef9
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vscode
.dir-locals.el
TAGS
*.bak
package_gd32_arcayi_index.json
14 changes: 7 additions & 7 deletions cores/arduino/analog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ uint16_t get_adc_value(PinName pinname)
{
uint16_t value;
uint32_t adc_periph = pinmap_peripheral(pinname, PinMap_ADC);
uint8_t index = get_dac_index(adc_periph);
uint8_t index = get_adc_index(adc_periph);
uint8_t channel = get_adc_channel(pinname);
if (!ADC_[index].isactive) {
pinmap_pinout(pinname, PinMap_ADC);
Expand All @@ -156,10 +156,10 @@ uint16_t get_adc_value(PinName pinname)
adc_resolution_config(adc_periph, ADC_RESOLUTION_12B);
adc_data_alignment_config(adc_periph, ADC_DATAALIGN_RIGHT);
adc_channel_length_config(adc_periph, ADC_REGULAR_CHANNEL, 1U);
#elif defined(GD32F3x0) || defined(GD32F1x0)
#elif defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32E23x)
rcu_adc_clock_config(RCU_ADCCK_APB2_DIV6);
adc_special_function_config(ADC_CONTINUOUS_MODE, ENABLE);
#if defined(GD32F3x0) || defined(GD32F170_190)
#if defined(GD32F3x0) || defined(GD32F170_190) || defined(GD32E23x)
adc_resolution_config(ADC_RESOLUTION_12B);
#endif
adc_data_alignment_config(ADC_DATAALIGN_RIGHT);
Expand All @@ -169,15 +169,15 @@ uint16_t get_adc_value(PinName pinname)
adc_external_trigger_source_config(adc_periph, ADC_REGULAR_CHANNEL, ADC0_1_2_EXTTRIG_REGULAR_NONE);
#elif defined(GD32VF103) /* what?! Code for a RISC-V MCU here? */
adc_external_trigger_source_config(adc_periph, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_NONE);
#elif defined(GD32F3x0) || defined(GD32F1x0)
#elif defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32E23x)
adc_external_trigger_source_config(ADC_REGULAR_CHANNEL, ADC_EXTTRIG_REGULAR_NONE);
#endif
#if defined(GD32F30x) || defined(GD32E50X)
adc_external_trigger_config(adc_periph, ADC_REGULAR_CHANNEL, ENABLE);
adc_enable(adc_periph);
delay(1U);
adc_calibration_enable(adc_periph);
#elif defined(GD32F3x0) || defined(GD32F1x0)
#elif defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32E23x)
adc_external_trigger_config(ADC_REGULAR_CHANNEL, ENABLE);
adc_enable();
delay(1U);
Expand All @@ -191,7 +191,7 @@ uint16_t get_adc_value(PinName pinname)
while (!adc_flag_get(adc_periph, ADC_FLAG_EOC));
adc_flag_clear(adc_periph, ADC_FLAG_EOC);
value = adc_regular_data_read(adc_periph);
#elif defined(GD32F3x0) || defined(GD32F1x0)
#elif defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32E23x)
adc_regular_channel_config(0U, channel, ADC_SAMPLETIME_7POINT5);
adc_software_trigger_enable(ADC_REGULAR_CHANNEL);
while (!adc_flag_get(ADC_FLAG_EOC));
Expand Down Expand Up @@ -381,7 +381,7 @@ void adc_clock_enable(uint32_t instance)
temp = RCU_ADC2;
break;
#endif
#elif defined(GD32F3x0) || defined(GD32F1x0)
#elif defined(GD32F3x0) || defined(GD32F1x0) || defined(GD32E23x)
case ADC:
temp = RCU_ADC;
break;
Expand Down
36 changes: 18 additions & 18 deletions libraries/Wire/examples/i2c_scanner/i2c_scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
void setup()
{

// Serial.begin(9600);
Serial.begin(115200);
Wire.begin();
// Serial.println("\nI2C Scanner");
Serial.println("\nI2C Scanner");
}


Expand All @@ -68,7 +68,7 @@ void loop()
byte error, address;
int nDevices;

// Serial.println("Scanning...");
Serial.println("Scanning...");

nDevices = 0;
for(address = 1; address < 127; address++) {
Expand All @@ -80,24 +80,24 @@ void loop()
error = Wire.endTransmission();

if(error == 0) {
// Serial.print("I2C device found at address 0x");
//if (address < 16)
// Serial.print("0");
// Serial.println(address, HEX);
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);

nDevices++;
}
//else if (error == 4) {
// Serial.print("Unknown error at address 0x");
//if (address < 16)
// Serial.print("0");
// Serial.println(address, HEX);
//}
else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
//if (nDevices == 0)
// Serial.println("No I2C devices found");
//else
// Serial.println("done");
if (nDevices == 0)
Serial.println("No I2C devices found");
else
Serial.println("done");

delay(5000); // wait 5 seconds for next scan
delay(1000); // wait 5 seconds for next scan
}
8 changes: 4 additions & 4 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
tools.serial_upload.cmd=serial_upload
tools.serial_upload.cmd.windows=serial_upload.bat
tools.serial_upload.cmd.macosx=serial_upload
tools.serial_upload.path={runtime.tools.gd32tools-1.0.0.path}/win
#tools.serial_upload.path.macosx={runtime.tools.gd32tools-1.0.0.path}/macosx
#tools.serial_upload.path.linux={runtime.tools.gd32tools-1.0.0.path}/linux
#tools.serial_upload.path.linux64={runtime.tools.gd32tools-1.0.0.path}/linux
tools.serial_upload.path={runtime.platform.path}/tools/win
tools.serial_upload.path.macosx={runtime.platform.path}/tools/macosx
tools.serial_upload.path.linux={runtime.platform.path}/tools/linux
tools.serial_upload.path.linux64={runtime.platform.path}/tools/linux64
tools.serial_upload.upload.params.verbose=-d
tools.serial_upload.upload.params.quiet=n
tools.serial_upload.upload.pattern="{path}/{cmd}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin"
Expand Down
Binary file added tools/win/GD32 MCU ISP Console User Manual.docx
Binary file not shown.
Binary file added tools/win/GD32_ISP_CLI.exe
Binary file not shown.
Binary file added tools/win/GD_MCU_DLL.dll
Binary file not shown.
20 changes: 20 additions & 0 deletions tools/win/serial_upload.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
rem @echo off
rem: Note %~dp0 get path of this batch file
rem: Need to change drive if My Documents is on a drive other than C:
set scriptPath=%~dp0
set driverLetter=%scriptPath:~0,2%
set scriptPath=%scriptPath:/=\%

rem %driverLetter%
rem cd %~dp0

rem: ------------- use GD's own uploader
rem: ---- Need to remove the COM bit from the comm port as the GD prog just wants the number
set commport=%1
set commportnum=%commport:COM=%

rem: the two line below are needed to fix path issues with incorrect slashes before the bin file name
set strBinFile=%4
set strBinFile=%strBinFile:/=\%

%scriptPath%\GD32_ISP_CLI.exe -c --pn %commportnum% --br 57600 --to 1000 -e --all -d --a 8000000 --fn %strBinFile% --v -r --a 8000000

0 comments on commit 977fef9

Please sign in to comment.