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

Serial1 for genericGD32F130C6 and Arduino not working #44

Open
QGB opened this issue Apr 18, 2023 · 9 comments
Open

Serial1 for genericGD32F130C6 and Arduino not working #44

QGB opened this issue Apr 18, 2023 · 9 comments
Labels
arduino bug Something isn't working

Comments

@QGB
Copy link

QGB commented Apr 18, 2023

even simple gpio

#define LED PB9

void setup(){
    pinMode(LED, OUTPUT);
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    delay(500);
    Serial1.begin(57600);
}

spl code work well

#include "gd32f1x0.h"

#define LEDPORT     GPIOB
#define LEDPIN      GPIO_PIN_9
#define LED_CLOCK   RCU_GPIOB

int main(void){
    systick_config();
    rcu_periph_clock_enable(LED_CLOCK);

    gpio_mode_set(LEDPORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, LEDPIN);
    gpio_output_options_set(LEDPORT, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, LEDPIN);

    while (1){
        gpio_bit_reset(LEDPORT, LEDPIN);//buzzer
        delay_1ms(100);

        gpio_bit_set(LEDPORT, LEDPIN);
        delay_1ms(500);
    }
}
@maxgerhardt
Copy link
Member

Well technically for Arduino blinky to have the same behavior you would have

#define LED PB9

void setup(){
    pinMode(LED, OUTPUT);
}

void loop() {
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    delay(500);
}

To reproduce this, I would also need to know which exact board you're compiling for. Please post the exact platformio.ini.

@QGB
Copy link
Author

QGB commented Apr 18, 2023

arduino

[env]
platform = https://github.com/CommunityGD32Cores/platform-gd32.git
platform_packages = 
    framework-arduinogd32@https://github.com/CommunityGD32Cores/ArduinoCore-GD32.git
monitor_speed = 115200

[env:genericGD32F130C6]
board = genericGD32F130C6
framework = arduino

spl

[env]
platform = https://github.com/CommunityGD32Cores/platform-gd32.git
platform_packages = 
    framework-spl-gd32@https://github.com/CommunityGD32Cores/gd32-pio-spl-package.git

[env:genericGD32F130C6]
board = genericGD32F130C6
framework = spl

@maxgerhardt
Copy link
Member

What exact board are you running on? Custom made? Does it have a quartz crystal for HSE?

@QGB
Copy link
Author

QGB commented Apr 18, 2023

What exact board are you running on? Custom made? Does it have a quartz crystal for HSE?

NO external quartz crystal

@maxgerhardt
Copy link
Member

Hm okay that should still be fine because the Arduino system code configures the clock to be sourced from the internal RC 8MHz oscillator.

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/41f3c2b3524a51e698ef03186a4243bb89e8ad88/system/GD32F1x0_firmware/CMSIS/GD/GD32F1x0/Source/system_gd32f1x0.c#L45-L49

Can you test this exact code? #44 (comment)

If you're uploading via ST-Link, you should also be able to use the Debugging sidebar ("PIO Debug"). Does it get stuck somewhere?

@QGB
Copy link
Author

QGB commented Apr 18, 2023

Your code works, How to config Serial1 pin PA2 as RX, PA3 as TX

@maxgerhardt
Copy link
Member

This should already be the default configuration for Serial1 as set by

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/41f3c2b3524a51e698ef03186a4243bb89e8ad88/variants/GD32F130C6_GENERIC/variant.h#L130-L137

And the pin mapping looks good too

https://github.com/CommunityGD32Cores/ArduinoCore-GD32/blob/41f3c2b3524a51e698ef03186a4243bb89e8ad88/variants/GD32F130C6_GENERIC/PeripheralPins.c#L180-L198

When you go back to your original code and debug it in the debugger, do you see it getting stuck somewhere?

@QGB
Copy link
Author

QGB commented Apr 18, 2023

#include <Arduino.h>

#define LED PB9

void setup(){
    pinMode(LED, OUTPUT);
    Serial1.begin(57600);
    Serial1.println("Start on Serial1!");

}

void loop() {
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    delay(50);
    Serial1.println("Serial1 \r\n");
}

gpio OK,spl framework uart OK,
but this code no output in serial console . I try switch RX TX cable.also not work

@maxgerhardt maxgerhardt changed the title framework = arduino Not work , framework = spl OK Serial1 for genericGD32F130C6 and Arduino not working Apr 18, 2023
@maxgerhardt maxgerhardt added bug Something isn't working arduino labels Apr 18, 2023
@maxgerhardt
Copy link
Member

maxgerhardt commented May 1, 2023

I checked the code again and the macros are named very confusingly indeed.

grafik

So you actually need to use Serial2 for TX=PA2, RX=PA3 (board's perspective), using USART1.

#include <Arduino.h>

#define LED PB9

void setup(){
    pinMode(LED, OUTPUT);
    Serial2.begin(57600);
    Serial2.println("Start on Serial2!");

}

void loop() {
    digitalWrite(LED, LOW);
    delay(500);
    digitalWrite(LED, HIGH);
    delay(50);
    Serial2.println("Serial2");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arduino bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants