Skip to content

Commit 06434d9

Browse files
committed
Merge branch 'master' of https://github.com/mbedmicro/mbed
2 parents 62c3e14 + 6b044ad commit 06434d9

File tree

9 files changed

+156
-57
lines changed

9 files changed

+156
-57
lines changed

libraries/mbed/api/BusIn.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ class BusIn {
5151
* An integer with each bit corresponding to the value read from the associated DigitalIn pin
5252
*/
5353
int read();
54-
54+
55+
/** Set the input pin mode
56+
*
57+
* @param mode PullUp, PullDown, PullNone
58+
*/
59+
void mode(PinMode pull);
60+
5561
#ifdef MBED_OPERATORS
5662
/** A shorthand for read()
5763
*/

libraries/mbed/common/BusIn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ int BusIn::read() {
4949
return v;
5050
}
5151

52+
void BusIn::mode(PinMode pull) {
53+
for (int i=0; i<16; i++) {
54+
if (_pin[i] != 0) {
55+
_pin[i]->mode(pull);
56+
}
57+
}
58+
}
59+
5260
#ifdef MBED_OPERATORS
5361
BusIn::operator int() {
5462
return read();

libraries/mbed/common/gpio.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
1919
{
2020
gpio_init(gpio, pin);
21-
gpio_dir(gpio, PIN_INPUT);
22-
gpio_mode(gpio, mode);
21+
if (pin != NC) {
22+
gpio_dir(gpio, PIN_INPUT);
23+
gpio_mode(gpio, mode);
24+
}
2325
}
2426

2527
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
2628
{
2729
gpio_init(gpio, pin);
28-
gpio_write(gpio, value);
29-
gpio_dir(gpio, PIN_OUTPUT);
30-
gpio_mode(gpio, mode);
30+
if (pin != NC) {
31+
gpio_write(gpio, value);
32+
gpio_dir(gpio, PIN_OUTPUT);
33+
gpio_mode(gpio, mode);
34+
}
3135
}
3236

3337
void gpio_init_in(gpio_t* gpio, PinName pin) {
@@ -49,7 +53,8 @@ void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
4953
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
5054
if (direction == PIN_INPUT) {
5155
_gpio_init_in(gpio, pin, mode);
52-
gpio_write(gpio, value); // we prepare the value in case it is switched later
56+
if (pin != NC)
57+
gpio_write(gpio, value); // we prepare the value in case it is switched later
5358
} else {
5459
_gpio_init_out(gpio, pin, mode, value);
5560
}

libraries/mbed/targets/hal/TARGET_STM/TARGET_DISCO_F407VG/pwmout_api.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static const PinMap PinMap_PWM[] = {
4343
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
4444
//{PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
4545
//{PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
46-
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
46+
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
4747
//{PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
4848
//{PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
4949
{PA_5, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH1
@@ -77,7 +77,7 @@ static const PinMap PinMap_PWM[] = {
7777
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
7878
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
7979
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
80-
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
80+
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
8181

8282
{NC, NC, 0}
8383
};
@@ -183,13 +183,13 @@ void pwmout_write(pwmout_t* obj, float value) {
183183
break;
184184
// Channels 3
185185
case PA_2:
186-
case PA_3:
186+
//case PA_3:
187187
case PA_10:
188188
//case PB_0:
189189
case PB_8:
190190
case PB_10:
191191
case PC_8:
192-
case PC_9:
192+
//case PC_9:
193193
channel = TIM_CHANNEL_3;
194194
break;
195195
// Channels 3N
@@ -199,10 +199,11 @@ void pwmout_write(pwmout_t* obj, float value) {
199199
complementary_channel = 1;
200200
break;
201201
// Channels 4
202-
//case PA_3:
202+
case PA_3:
203203
case PA_11:
204204
//case PB_1:
205205
case PB_9:
206+
case PC_9:
206207
channel = TIM_CHANNEL_4;
207208
break;
208209
default:
Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
#include "mbed.h"
22
#include "MMA8451Q.h"
3-
4-
#define MMA8451_I2C_ADDRESS (0x1d<<1)
3+
#include "test_env.h"
54

65
#ifdef TARGET_KL05Z
7-
#define SDA PTB4
8-
#define SCL PTB3
6+
#define SDA PTB4
7+
#define SCL PTB3
98
#else
10-
#define SDA PTE25
11-
#define SCL PTE24
9+
#define SDA PTE25
10+
#define SCL PTE24
1211
#endif
1312

13+
namespace {
14+
const int MMA8451_I2C_ADDRESS = 0x1D << 1; // I2C bus address
15+
const float MMA8451_DIGITAL_SENSITIVITY = 4096.0; // Counts/g
16+
}
17+
18+
float calc_3d_vector_len(float x, float y, float z) {
19+
return sqrt(x*x + y*y + z*z);
20+
}
21+
22+
#define TEST_ITERATIONS 25
23+
#define TEST_ITERATIONS_SKIP 5
24+
#define MEASURE_DEVIATION_TOLERANCE 0.025 // 2.5%
25+
1426
int main(void) {
1527
DigitalOut led(LED_GREEN);
1628
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
17-
printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI());
18-
19-
while (true) {
20-
printf("-----------\r\n");
21-
printf("acc_x: %d\r\n", acc.getAccX());
22-
printf("acc_y: %d\r\n", acc.getAccY());
23-
printf("acc_z: %d\r\n", acc.getAccZ());
29+
bool result = true;
30+
printf("WHO AM I: 0x%2X\r\n\n", acc.getWhoAmI());
2431

25-
wait(1);
32+
for (int i = 0; i < TEST_ITERATIONS; i++) {
33+
if (i < TEST_ITERATIONS_SKIP) {
34+
// Skip first 5 measurements
35+
continue;
36+
}
37+
const float g_vect_len = calc_3d_vector_len(acc.getAccX(), acc.getAccY(), acc.getAccZ()) / MMA8451_DIGITAL_SENSITIVITY;
38+
const float deviation = fabs(g_vect_len - 1.0);
39+
const char *succes_str = deviation <= MEASURE_DEVIATION_TOLERANCE ? "[OK]" : "[FAIL]";
40+
result = result && (deviation <= MEASURE_DEVIATION_TOLERANCE);
41+
printf("X:% 6d Y:% 6d Z:% 5d GF:%0.3fg, dev:%0.3f ... %s\r\n", acc.getAccX(), acc.getAccY(), acc.getAccZ(), g_vect_len, deviation, succes_str);
42+
wait(0.5);
2643
led = !led;
2744
}
45+
notify_completion(result);
2846
}
Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,69 @@
11
#include "mbed.h"
22
#include "EthernetInterface.h"
33

4-
const char* ECHO_SERVER_ADDRESS = "10.2.200.57";
5-
const int ECHO_PORT = 7;
4+
struct s_ip_address
5+
{
6+
int ip_1;
7+
int ip_2;
8+
int ip_3;
9+
int ip_4;
10+
};
11+
12+
#define MAX_ECHO_LOOPS 100
613

714
int main() {
15+
char buffer[256] = {0};
16+
char out_buffer[] = "Hello World\n";
17+
char out_success[] = "{{success}}\n{{end}}\n";
18+
char out_failure[] = "{{failure}}\n{{end}}\n";
19+
s_ip_address ip_addr = {0, 0, 0, 0};
20+
int port = 0;
21+
22+
printf("TCPCllient waiting for server IP and port...\r\n");
23+
scanf("%d.%d.%d.%d:%d", &ip_addr.ip_1, &ip_addr.ip_2, &ip_addr.ip_3, &ip_addr.ip_4, &port);
24+
printf("Address received:%d.%d.%d.%d:%d\r\n", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4, port);
25+
826
EthernetInterface eth;
927
eth.init(); //Use DHCP
1028
eth.connect();
11-
printf("IP Address is %s\n", eth.getIPAddress());
12-
29+
30+
printf("TCPClient IP Address is %s\r\n", eth.getIPAddress());
31+
sprintf(buffer, "%d.%d.%d.%d", ip_addr.ip_1, ip_addr.ip_2, ip_addr.ip_3, ip_addr.ip_4);
32+
1333
TCPSocketConnection socket;
14-
15-
while (true) {
16-
while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_PORT) < 0) {
17-
printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_PORT);
18-
wait(1);
19-
}
20-
21-
char hello[] = "Hello World\n";
22-
socket.send_all(hello, sizeof(hello) - 1);
23-
24-
char buf[256];
25-
int n = socket.receive(buf, 256);
26-
buf[n] = '\0';
27-
printf("%s", buf);
28-
29-
socket.close();
34+
while (socket.connect(buffer, port) < 0) {
35+
printf("TCPCllient unable to connect to %s:%d\r\n", buffer, port);
3036
wait(1);
3137
}
32-
38+
39+
// Test loop for multiple client conenctions
40+
bool result = true;
41+
int count_error = 0;
42+
for (int i = 0; i < MAX_ECHO_LOOPS; i++) {
43+
socket.send_all(out_buffer, sizeof(out_buffer) - 1);
44+
45+
int n = socket.receive(buffer, sizeof(buffer));
46+
if (n > 0)
47+
{
48+
buffer[n] = '\0';
49+
printf("%s", buffer);
50+
bool echoed = strncmp(out_buffer, buffer, sizeof(out_buffer) - 1) == 0;
51+
result = result && echoed;
52+
if (echoed == false) {
53+
count_error++; // Count error messages
54+
}
55+
}
56+
}
57+
58+
printf("Loop messages passed: %d/%d\r\n", MAX_ECHO_LOOPS - count_error, MAX_ECHO_LOOPS);
59+
60+
if (result) {
61+
socket.send_all(out_success, sizeof(out_success) - 1);
62+
}
63+
else {
64+
socket.send_all(out_failure, sizeof(out_failure) - 1);
65+
}
66+
socket.close();
3367
eth.disconnect();
68+
return 0;
3469
}

libraries/tests/net/protocols/HTTPClient_HelloWorld/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ int main()
3939
{
4040
bool result = true;
4141
const char *url_httpbin_post = "http://httpbin.org/post";
42-
HTTPMap map;
4342
HTTPText text(http_request_buffer, BUFFER_SIZE);
43+
HTTPMap map;
4444
map.put("Hello", "World");
4545
map.put("test", "1234");
4646
printf("HTTP_POST: Trying to post data to '%s' ...\r\n", url_httpbin_post);
4747
const int ret = http.post(url_httpbin_post, map, &text);
4848
if (ret == 0) {
49-
printf("HTTP_POST: Read %d chars ... [OK]\n", strlen(http_request_buffer));
49+
printf("HTTP_POST: Read %d chars ... [OK]\r\n", strlen(http_request_buffer));
5050
printf("HTTP_POST: %s\r\n", http_request_buffer);
5151
}
5252
else {

workspace_tools/singletest.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,12 @@ def get_result_summary_table():
391391
counter_dict_test_id_types_all = dict((t, 0) for t in unique_test_id)
392392

393393
test_properties = ['id', 'automated', 'description', 'peripherals', 'host_test', 'duration']
394+
395+
# All tests status table print
394396
pt = PrettyTable(test_properties)
395397
for col in test_properties:
396-
pt.align[col] = "l" # Left align
398+
pt.align[col] = "l"
399+
pt.align['duration'] = "r"
397400

398401
counter_all = 0
399402
counter_automated = 0
@@ -414,24 +417,42 @@ def get_result_summary_table():
414417
counter_all += 1
415418
counter_dict_test_id_types_all[test_id_prefix] += 1
416419
print pt
417-
print "Result:"
418-
percent_progress = round(100.0 * counter_automated / float(counter_all), 2)
419-
print "\tAutomated: %d / %d (%s %%)" % (counter_automated, counter_all, percent_progress)
420420
print
421+
422+
# Automation result summary
423+
test_id_cols = ['automated', 'all', 'percent [%]', 'progress']
424+
pt = PrettyTable(test_id_cols)
425+
pt.align['automated'] = "r"
426+
pt.align['all'] = "r"
427+
pt.align['percent [%]'] = "r"
428+
429+
percent_progress = round(100.0 * counter_automated / float(counter_all), 1)
430+
str_progress = progress_bar(percent_progress, 75)
431+
pt.add_row([counter_automated, counter_all, percent_progress, str_progress])
432+
print "Automation coverage:"
433+
print pt
434+
print
435+
436+
# Test automation coverage table print
421437
test_id_cols = ['id', 'automated', 'all', 'percent [%]', 'progress']
422438
pt = PrettyTable(test_id_cols)
423-
pt.align['id'] = "l" # Left align
439+
pt.align['id'] = "l"
440+
pt.align['automated'] = "r"
441+
pt.align['all'] = "r"
442+
pt.align['percent [%]'] = "r"
424443
for unique_id in unique_test_id:
425444
# print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id])
426-
percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2)
445+
percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 1)
427446
str_progress = progress_bar(percent_progress, 75)
428447
row = [unique_id,
429448
counter_dict_test_id_types[unique_id],
430449
counter_dict_test_id_types_all[unique_id],
431450
percent_progress,
432451
"[" + str_progress + "]"]
433452
pt.add_row(row)
453+
print "Test automation coverage:"
434454
print pt
455+
print
435456

436457

437458
def progress_bar(percent_progress, saturation=0):
@@ -545,7 +566,7 @@ def progress_bar(percent_progress, saturation=0):
545566

546567
if opts.test_only_peripheral and not test.peripherals:
547568
if opts.verbose:
548-
print "TargetTest::%s::NotPeripheralTestSkipped(%s)" % (target, ",".join(test.peripherals))
569+
print "TargetTest::%s::NotPeripheralTestSkipped()" % (target)
549570
continue
550571

551572
if test.automated and test.is_supported(target, toolchain):

workspace_tools/tests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,9 @@
660660
"id": "NET_13", "description": "TCP client echo loop",
661661
"source_dir": join(TEST_DIR, "net", "echo", "tcp_client_loop"),
662662
"dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY],
663+
"automated": True,
664+
"duration": 15,
665+
"host_test": "tcpecho_client_auto",
663666
"peripherals": ["ethernet"],
664667
},
665668

@@ -761,7 +764,9 @@
761764
"source_dir": join(TEST_DIR, "mbed", "i2c_MMA8451Q"),
762765
"dependencies": [MBED_LIBRARIES, TEST_MBED_LIB, join(PERIPHERALS, 'MMA8451Q')],
763766
"mcu": ["KL25Z", "KL05Z", "KL46Z"],
764-
},
767+
"automated": True,
768+
"duration": 15,
769+
},
765770

766771
# Examples
767772
{

0 commit comments

Comments
 (0)