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

PA7 digitalRead always returns 0 after Serial.begin() + Serial.end() #184

Closed
vladkozlov69 opened this issue Jul 5, 2023 · 1 comment
Closed

Comments

@vladkozlov69
Copy link

PA7 digitalRead always returns 0 after Serial.begin() + Serial.end()

Here is the code to reproduce the issue:


void setup()
{
	Serial.begin(115200);
}


void loop()
{
	Serial.println(millis());
	Serial.end();
	pinMode(PA7, INPUT_PULLUP);
	int status = digitalRead(PA7);
	Serial.begin(115200);
	Serial.println(status);
	delay(200);
}

I guess Serial.end() should release the resources and bindings so PA7 should be available to read?

@vladkozlov69
Copy link
Author

I found that *void serial_free(serial_t obj) does not perform a correct cleanup.

So after Serial.end() I just added

Pinmux_Config((PinName)g_APinDescription[LOG_TX].pinname, PINMUX_FUNCTION_GPIO);

Here is the demo code:

#define RESET_PIN PA7

void setup()
{
	Serial.begin(115200);
	pinMode(LED_G, OUTPUT);
	pinMode(LED_R, OUTPUT);
	digitalWrite(LED_G, LOW);
	digitalWrite(LED_R, LOW);
}


unsigned long resetTimerStart;
unsigned long resetTimerEnd;

void loop()
{
	Serial.println(millis());
	Serial.end();
	Pinmux_Config((PinName)g_APinDescription[LOG_TX].pinname, PINMUX_FUNCTION_GPIO);
	pinMode(RESET_PIN, INPUT);
	if (digitalRead(RESET_PIN) == LOW)
	{
		digitalWrite(LED_G, HIGH);
		resetTimerStart = millis();
		while(digitalRead(RESET_PIN) == LOW);
		resetTimerEnd = millis();
	}
	digitalWrite(LED_G, LOW);
	if (resetTimerEnd - resetTimerStart >= 5000)
	{
		digitalWrite(LED_R, HIGH);
	}

	Serial.begin(115200);
	Serial.print("Factory settings button was pressed for ");
	Serial.print(resetTimerEnd - resetTimerStart);
	Serial.println(" milliseconds.");
	delay(200);
}

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

No branches or pull requests

1 participant