Skip to content

Commit c05570d

Browse files
2 parents 2079864 + 461b862 commit c05570d

11 files changed

Lines changed: 182 additions & 13 deletions

File tree

STM32F1/cores/maple/libmaple/i2c.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ int32 i2c_master_xfer(i2c_dev *dev,
235235

236236
i2c_enable_irq(dev, I2C_IRQ_EVENT);
237237
i2c_start_condition(dev);
238-
238+
239239
rc = wait_for_state_change(dev, I2C_STATE_XFER_DONE, timeout);
240240
if (rc < 0) {
241241
goto out;
@@ -347,9 +347,20 @@ void _i2c_irq_handler(i2c_dev *dev) {
347347
* register. We should get another TXE interrupt
348348
* immediately to fill DR again.
349349
*/
350-
if (msg->length != 1) {
350+
if (msg->length > 1) {
351351
i2c_write(dev, msg->data[msg->xferred++]);
352-
}
352+
} else if (msg->length == 0) { /* We're just sending an address */
353+
i2c_stop_condition(dev);
354+
/*
355+
* Turn off event interrupts to keep BTF from firing until
356+
* the end of the stop condition. Why on earth they didn't
357+
* have a start/stop condition request clear BTF is beyond
358+
* me.
359+
*/
360+
i2c_disable_irq(dev, I2C_IRQ_EVENT);
361+
I2C_CRUMB(STOP_SENT, 0, 0);
362+
dev->state = I2C_STATE_XFER_DONE;
363+
} /* else we're just sending one byte */
353364
}
354365
sr1 = sr2 = 0;
355366
}
@@ -456,7 +467,7 @@ void _i2c_irq_handler(i2c_dev *dev) {
456467
void _i2c_irq_error_handler(i2c_dev *dev) {
457468
I2C_CRUMB(ERROR_ENTRY, dev->regs->SR1, dev->regs->SR2);
458469

459-
dev->error_flags = dev->regs->SR2 & (I2C_SR1_BERR |
470+
dev->error_flags = dev->regs->SR1 & (I2C_SR1_BERR |
460471
I2C_SR1_ARLO |
461472
I2C_SR1_AF |
462473
I2C_SR1_OVR);

STM32F1/libraries/Wire/HardWire.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@
4040

4141
uint8 HardWire::process() {
4242
int8 res = i2c_master_xfer(sel_hard, &itc_msg, 1, 0);
43-
if (res != 0) {
43+
if (res == I2C_ERROR_PROTOCOL) {
44+
if (sel_hard->error_flags & I2C_SR1_AF) { /* NACK */
45+
res = (sel_hard->error_flags & I2C_SR1_ADDR ? ENACKADDR :
46+
ENACKTRNS);
47+
} else if (sel_hard->error_flags & I2C_SR1_OVR) { /* Over/Underrun */
48+
res = EDATA;
49+
} else { /* Bus or Arbitration error */
50+
res = EOTHER;
51+
}
4452
i2c_disable(sel_hard);
4553
i2c_master_enable(sel_hard, (I2C_BUS_RESET | dev_flags));
4654
}
47-
return 0;
55+
return res;
4856
}
4957

5058
// TODO: Add in Error Handling if devsel is out of range for other Maples
@@ -56,7 +64,7 @@ HardWire::HardWire(uint8 dev_sel, uint8 flags) {
5664
} else {
5765
ASSERT(1);
5866
}
59-
dev_flags=flags;
67+
dev_flags = flags;
6068
}
6169

6270
HardWire::~HardWire() {

STM32F1/libraries/Wire/HardWire.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ class HardWire : public WireBase {
6767

6868
void begin(uint8 = 0x00);
6969
};
70-
70+
extern HardWire HWire;
7171
#endif // _HARDWIRE_H_

STM32F1/libraries/Wire/WireBase.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ void WireBase::beginTransmission(int slave_address) {
6161

6262
uint8 WireBase::endTransmission(void) {
6363
uint8 retVal;
64-
65-
if (tx_buf_overflow) {
64+
if (tx_buf_overflow) {
6665
return EDATA;
6766
}
68-
retVal=process();// Changed so that the return value from process is returned by this function see also the return line below
67+
retVal = process();// Changed so that the return value from process is returned by this function see also the return line below
6968
tx_buf_idx = 0;
7069
tx_buf_overflow = false;
7170
return retVal;//SUCCESS;
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// --------------------------------------
2+
// i2c_scanner
3+
//
4+
// Version 1
5+
// This program (or code that looks like it)
6+
// can be found in many places.
7+
// For example on the Arduino.cc forum.
8+
// The original author is not know.
9+
// Version 2, Juni 2012, Using Arduino 1.0.1
10+
// Adapted to be as simple as possible by Arduino.cc user Krodal
11+
// Version 3, Feb 26 2013
12+
// V3 by louarnold
13+
// Version 4, March 3, 2013, Using Arduino 1.0.3
14+
// by Arduino.cc user Krodal.
15+
// Changes by louarnold removed.
16+
// Scanning addresses changed from 0...127 to 1...119,
17+
// according to the i2c scanner by Nick Gammon
18+
// http://www.gammon.com.au/forum/?id=10896
19+
// Version 5, March 28, 2013
20+
// As version 4, but address scans now to 127.
21+
// A sensor seems to use address 120.
22+
// Version 6, August 1, 2015
23+
// Modified to support HardWire for STM32duino
24+
//
25+
// This sketch tests the standard 7-bit addresses
26+
// Devices with higher bit address might not be seen properly.
27+
//
28+
29+
#include <HardWire.h>
30+
31+
HardWire HWire(1, I2C_FAST_MODE); // I2c1
32+
33+
void setup() {
34+
Serial.begin(115200);
35+
HWire.begin();
36+
Serial.println("\nI2C Scanner");
37+
}
38+
39+
40+
void loop() {
41+
byte error, address;
42+
int nDevices;
43+
44+
Serial.println("Scanning...");
45+
46+
nDevices = 0;
47+
for(address = 1; address < 127; address++) {
48+
// The i2c_scanner uses the return value of
49+
// the Write.endTransmisstion to see if
50+
// a device did acknowledge to the address.
51+
52+
HWire.beginTransmission(address);
53+
error = HWire.endTransmission();
54+
55+
if (error == 0) {
56+
Serial.print("I2C device found at address 0x");
57+
if (address < 16)
58+
Serial.print("0");
59+
Serial.println(address, HEX);
60+
61+
nDevices++;
62+
}
63+
else if (error == 4) {
64+
Serial.print("Unknown error at address 0x");
65+
if (address < 16)
66+
Serial.print("0");
67+
Serial.println(address, HEX);
68+
}
69+
}
70+
if (nDevices == 0)
71+
Serial.println("No I2C devices found");
72+
else
73+
Serial.println("done");
74+
75+
delay(5000); // wait 5 seconds for next scan
76+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// --------------------------------------
2+
// i2c_scanner
3+
//
4+
// Version 1
5+
// This program (or code that looks like it)
6+
// can be found in many places.
7+
// For example on the Arduino.cc forum.
8+
// The original author is not know.
9+
// Version 2, Juni 2012, Using Arduino 1.0.1
10+
// Adapted to be as simple as possible by Arduino.cc user Krodal
11+
// Version 3, Feb 26 2013
12+
// V3 by louarnold
13+
// Version 4, March 3, 2013, Using Arduino 1.0.3
14+
// by Arduino.cc user Krodal.
15+
// Changes by louarnold removed.
16+
// Scanning addresses changed from 0...127 to 1...119,
17+
// according to the i2c scanner by Nick Gammon
18+
// http://www.gammon.com.au/forum/?id=10896
19+
// Version 5, March 28, 2013
20+
// As version 4, but address scans now to 127.
21+
// A sensor seems to use address 120.
22+
//
23+
// This sketch tests the standard 7-bit addresses
24+
// Devices with higher bit address might not be seen properly.
25+
//
26+
27+
#include <Wire.h>
28+
29+
30+
void setup() {
31+
32+
Serial.begin(115200);
33+
Wire.begin();
34+
Serial.println("\nI2C Scanner");
35+
}
36+
37+
38+
void loop() {
39+
byte error, address;
40+
int nDevices;
41+
42+
Serial.println("Scanning...");
43+
44+
nDevices = 0;
45+
for(address = 1; address < 127; address++) {
46+
// The i2c_scanner uses the return value of
47+
// the Write.endTransmisstion to see if
48+
// a device did acknowledge to the address.
49+
50+
Wire.beginTransmission(address);
51+
error = Wire.endTransmission();
52+
53+
if (error == 0) {
54+
Serial.print("I2C device found at address 0x");
55+
if (address < 16)
56+
Serial.print("0");
57+
Serial.println(address, HEX);
58+
59+
nDevices++;
60+
}
61+
else if (error == 4) {
62+
Serial.print("Unknown error at address 0x");
63+
if (address < 16)
64+
Serial.print("0");
65+
Serial.println(address, HEX);
66+
}
67+
}
68+
if (nDevices == 0)
69+
Serial.println("No I2C devices found");
70+
else
71+
Serial.println("done");
72+
73+
delay(5000); // wait 5 seconds for next scan
74+
}

STM32F4/cores/maple/wirish.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#ifndef _WIRISH_H_
3434
#define _WIRISH_H_
3535

36+
#include <stdlib.h>
3637
#include "libmaple.h"
3738

3839
#include "wirish_types.h"

tools/linux/dfu-util/dfu-prefix

12.6 KB
Binary file not shown.

tools/linux/dfu-util/dfu-suffix

12.5 KB
Binary file not shown.

tools/linux/dfu-util/dfu-util

25.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)