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

Fix #126: Add system clock calibration and read analog code from Catena-Arduino-Platform module #127

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

Conversation

chwon64
Copy link

@chwon64 chwon64 commented Sep 12, 2019

No description provided.

@@ -33,17 +33,25 @@ Copyright notice and license information:

#ifdef USBCON

#define ANALOG_CHANNEL_VBUS 2
#if defined(ARDUINO_MCCI_CATENA_4610) || defined(ARDUINO_MCCI_CATENA_4611)

Choose a reason for hiding this comment

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

4611 also non-rechargeable battery variant. I think it required READ_COUNT 6

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will change it.

Copy link
Author

Choose a reason for hiding this comment

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

We also need same change in C-A-P . Catena 4611 use ReadCount==6 for reading VBUS.

@chwon64
Copy link
Author

chwon64 commented Sep 18, 2019

I just realized user have to upgrade Catena-Arduino-Platform change first which is mcci-catena/Catena-Arduino-Platform#217.
If user upgrade BSP only, it will encounter link errors.
I think we need to release Catena-Arduino-Platform code change first.

Copy link
Member

@terrillmoore terrillmoore left a comment

Choose a reason for hiding this comment

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

See comments.

@@ -23,6 +23,9 @@ extern "C"{
#ifdef USBCON
#include "usb_interface.h"
#endif //USBCON
#include "stm32_rtc.h"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these included everywhere? Maybe better to include these in the .c files. Not needed for API definitions as far as I can see.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will remove these files from board.h.

/* the clock we'll use: */
constexpr uint32_t AdcClockMode = AdcClockModeAsync;

#ifdef __cplusplus
Copy link
Member

Choose a reason for hiding this comment

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

Since this is a .cpp file, I don't think we need this -- it's always defined.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will remove it.

extern "C" {
#endif

#ifdef STM32L0xx
Copy link
Member

Choose a reason for hiding this comment

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

Is this the right sentinel variable? I think we should be using an ARDUINO_ARCH_... variable or something like that.

Copy link
Author

Choose a reason for hiding this comment

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

We have STM32L0xx and ARDUINO_STM32L0xx. But other stm32 code use STML0xx, STM32L1xx, … If you want to use ARDUINO_STM32L0xx, I can use it.

*pValue = 2;

// make sure the clock is configured
// ADC1->CFGR2 = (ADC1->CFGR2 & ~ADC_CFGR2_CKMODE) | AdcClockMode;
Copy link
Member

Choose a reason for hiding this comment

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

do we need this commented-out code?

Copy link
Author

Choose a reason for hiding this comment

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

I will remove it.

{
ADC1->CR &= ~ADC_CR_ADEN;

// if (! AdcDisable())
Copy link
Member

Choose a reason for hiding this comment

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

ditto this.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, remove it.

}
}

// uint32_t calData = ADC1->DR;
Copy link
Member

Choose a reason for hiding this comment

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

Needed?


if (CalibNew != Calib)
{
Serial.print(CalibNew < Calib ? '+' : '-');
Copy link
Member

Choose a reason for hiding this comment

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

do we want this print in production?

Copy link
Author

Choose a reason for hiding this comment

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

I will comment out. There is another prints and I will comment out too.

return vBus > 250 ? 1 : 0;
}
vBus = Stm32ReadAnalog(ANALOG_CHANNEL_VBUS, READ_COUNT, MULTIPLIER);
return vBus < 3000 ? 0 : 1;
Copy link
Member

Choose a reason for hiding this comment

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

same question.

USBD_LL_ConnectionState_WEAK uint32_t USBD_LL_ConnectionState(void)
{
uint32_t vBus;
uint32_t USBD_LL_ConnectionState(void)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should have a static variable and only do an analog input for this purpose once every second or two. Spinning up the clock consumes a lot of power and time.

Copy link
Author

Choose a reason for hiding this comment

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

Okay, I will add code as suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants