Skip to content

Commit 2c4ae25

Browse files
committed
Merge branch 'master' of github.com:arduino/ArduinoCore-mbed
2 parents 4a9d8fe + a588098 commit 2c4ae25

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ git clone [email protected]:arduino/ArduinoCore-API
2020

2121
### Update the `api` symlink
2222

23-
Create a symlink to `ArduinoCore-API/api` in `$sketchbook/hardware/arduino/mbed/cores/arduino`.
23+
Create a symlink to `ArduinoCore-API/api` in `$sketchbook/hardware/arduino-git/mbed/cores/arduino`.
2424

2525
### Test things out
2626

boards.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pico.upload.transport=
414414
pico.upload.use_1200bps_touch=true
415415
pico.upload.wait_for_upload_port=false
416416
pico.upload.native_usb=true
417-
pico.upload.maximum_size=16777216
417+
pico.upload.maximum_size=2097152
418418
pico.upload.maximum_data_size=270336
419419

420420
pico.bootloader.tool=openocd
@@ -530,4 +530,4 @@ nicla_vision.bootloader.tool=openocd
530530
nicla_vision.bootloader.config=-f target/stm32h7x_dual_bank.cfg
531531
nicla_vision.bootloader.programmer=-f interface/stlink.cfg
532532
nicla_vision.bootloader.extra_action.preflash=stm32h7x option_write 0 0x01c 0xb86aaf0
533-
nicla_vision.bootloader.file=NICLA_VISION/bootloader.elf
533+
nicla_vision.bootloader.file=NICLA_VISION/bootloader.elf

libraries/Nicla_System/src/Nicla_System.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ RGBled nicla::leds;
1313
BQ25120A nicla::_pmic;
1414
rtos::Mutex nicla::i2c_mutex;
1515
bool nicla::started = false;
16+
uint8_t nicla::_chg_reg = 0;
1617

1718
void nicla::pingI2CThd() {
1819
while(1) {
1920
// already protected by a mutex on Wire operations
20-
readLDOreg();
21+
checkChgReg();
2122
delay(10000);
2223
}
2324
}
2425

2526
bool nicla::begin()
2627
{
28+
pinMode(p25, OUTPUT);
2729
pinMode(P0_10, OUTPUT);
2830
digitalWrite(P0_10, HIGH);
2931
Wire1.begin();
32+
_chg_reg = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG);
3033
#ifndef NO_NEED_FOR_WATCHDOG_THREAD
3134
static rtos::Thread th(osPriorityHigh, 1024, nullptr, "ping_thread");
3235
th.start(&nicla::pingI2CThd);
@@ -98,8 +101,26 @@ bool nicla::enterShipMode()
98101

99102
uint8_t nicla::readLDOreg()
100103
{
101-
uint8_t ldo_reg = _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_LDO_CTRL);
102-
return ldo_reg;
104+
return _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_LDO_CTRL);
105+
}
106+
107+
bool nicla::enableCharge(uint8_t mA)
108+
{
109+
digitalWrite(p25, LOW);
110+
if (mA < 35) {
111+
_chg_reg = ((mA-5) << 2);
112+
} else {
113+
_chg_reg = (((mA-40)/10) << 2) | 0x80;
114+
}
115+
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _chg_reg);
116+
return _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG) == _chg_reg;
117+
}
118+
119+
void nicla::checkChgReg()
120+
{
121+
if (_chg_reg != _pmic.readByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG)) {
122+
_pmic.writeByte(BQ25120A_ADDRESS, BQ25120A_FAST_CHG, _chg_reg);
123+
}
103124
}
104125

105126
I2CLed LEDR(red);

libraries/Nicla_System/src/Nicla_System.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <mbed.h>
99
#include <I2C.h>
1010

11+
#define USE_FASTCHG_TO_KICK_WATCHDOG 1
12+
1113
class nicla {
1214

1315
public:
@@ -16,6 +18,8 @@ class nicla {
1618
static bool enable1V8LDO();
1719
static bool disableLDO();
1820
static bool enterShipMode();
21+
static uint8_t readLDOreg();
22+
static bool enableCharge(uint8_t mA = 20);
1923

2024
static RGBled leds;
2125
static BQ25120A _pmic;
@@ -28,8 +32,9 @@ class nicla {
2832

2933
private:
3034
static void pingI2CThd();
31-
static uint8_t readLDOreg();
35+
static void checkChgReg();
3236
static rtos::Mutex i2c_mutex;
37+
static uint8_t _chg_reg;
3338
};
3439

3540
#endif

libraries/Nicla_System/src/RGBled.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ uint8_t RGBled::readByte(uint8_t address, uint8_t subAddress)
160160
Wire1.write(subAddress);
161161
Wire1.endTransmission(false);
162162
Wire1.requestFrom(address, 1);
163-
while(!Wire1.available()) {}
163+
uint32_t timeout = 100;
164+
uint32_t start_time = millis();
165+
while(!Wire1.available() && (millis() - start_time) < timeout) {}
164166
uint8_t ret = Wire1.read();
165167
nicla::i2c_mutex.unlock();
166168
return ret;

libraries/Nicla_System/src/pmic_driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ uint8_t BQ25120A::getStatus()
1111

1212
void BQ25120A::writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
1313
{
14+
digitalWrite(p25, HIGH);
1415
nicla::i2c_mutex.lock();
1516
Wire1.beginTransmission(address);
1617
Wire1.write(subAddress);
1718
Wire1.write(data);
1819
Wire1.endTransmission();
1920
nicla::i2c_mutex.unlock();
21+
digitalWrite(p25, LOW);
2022
}
2123

2224
uint8_t BQ25120A::readByte(uint8_t address, uint8_t subAddress)
2325
{
26+
digitalWrite(p25, HIGH);
2427
nicla::i2c_mutex.lock();
2528
char response = 0xFF;
2629
Wire1.beginTransmission(address);
@@ -32,5 +35,6 @@ uint8_t BQ25120A::readByte(uint8_t address, uint8_t subAddress)
3235
while(!Wire1.available() && (millis() - start_time) < timeout) {}
3336
uint8_t ret = Wire1.read();
3437
nicla::i2c_mutex.unlock();
38+
digitalWrite(p25, LOW);
3539
return ret;
3640
}

libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/*
55
* This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB)
6-
* On the board, launch both 'proxy' and 'example' binaries (from https://github.com/bcmi-labs/portentax8-m4-proxy)
6+
* On the board, launch both 'proxy' and 'example' binaries (from https://github.com/arduino/portentax8-m4-proxy)
77
* The M4 provides the 'subtract' API (which will be invoked by 'example'
88
* It also provides a full duplex Serial-like interface that is proxies through the serial monitor
99
* Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered

platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ recipe.hooks.objcopy.postobjcopy.1.pattern={build.postbuild.cmd}
101101
## Compute size
102102
recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf"
103103
recipe.size.regex.data=^(?:\.data|\.bss)\s+([0-9]+).*
104-
recipe.size.regex=^(?:\.data|\.text)\S*?\s+([0-9]+).*
104+
recipe.size.regex=^(?:\.data|\.text|\.rodata)\S*?\s+([0-9]+).*
105105

106106
## Save hex
107107
recipe.output.tmp_file={build.project_name}.bin

0 commit comments

Comments
 (0)