Skip to content

[NUCLEO_F302R8] Implement analogout_free function #260

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "pinmap.h"
#include "error.h"

#define RANGE_12BIT (0xFFF)
#define DAC_RANGE (0xFFF) // 12 bits

static const PinMap PinMap_DAC[] = {
{PA_4, DAC_1, STM_PIN_DATA(GPIO_Mode_AN, GPIO_OType_PP, GPIO_PuPd_NOPULL, 0xFF)}, // DAC_OUT1
Expand All @@ -56,7 +56,7 @@ void analogout_init(dac_t *obj, PinName pin) {
// Configure GPIO
pinmap_pinout(pin, PinMap_DAC);

// Save the channel for the write and read functions
// Save the channel for future use
obj->channel = pin;

// Enable DAC clock
Expand All @@ -71,6 +71,12 @@ void analogout_init(dac_t *obj, PinName pin) {
}

void analogout_free(dac_t *obj) {
DAC_TypeDef *dac = (DAC_TypeDef *)(obj->dac);
// Disable DAC
DAC_DeInit(dac);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, DISABLE);
// Configure GPIO
pin_function(obj->channel, STM_PIN_DATA(GPIO_Mode_IN, 0, GPIO_PuPd_NOPULL, 0xFF));
}

static inline void dac_write(dac_t *obj, uint16_t value) {
Expand All @@ -87,23 +93,23 @@ void analogout_write(dac_t *obj, float value) {
if (value < 0.0f) {
dac_write(obj, 0); // Min value
} else if (value > 1.0f) {
dac_write(obj, (uint16_t)RANGE_12BIT); // Max value
dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
dac_write(obj, (uint16_t)(value * (float)RANGE_12BIT));
dac_write(obj, (uint16_t)(value * (float)DAC_RANGE));
}
}

void analogout_write_u16(dac_t *obj, uint16_t value) {
if (value > (uint16_t)RANGE_12BIT) {
dac_write(obj, (uint16_t)RANGE_12BIT); // Max value
if (value > (uint16_t)DAC_RANGE) {
dac_write(obj, (uint16_t)DAC_RANGE); // Max value
} else {
dac_write(obj, value);
}
}

float analogout_read(dac_t *obj) {
uint32_t value = dac_read(obj);
return (float)value * (1.0f / (float)RANGE_12BIT);
return (float)((float)value * (1.0f / (float)DAC_RANGE));
}

uint16_t analogout_read_u16(dac_t *obj) {
Expand Down
17 changes: 7 additions & 10 deletions libraries/tests/mbed/dev_null/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "mbed.h"
#include "test_env.h"

class DevNull : public Stream {

public:
DevNull(const char *name=NULL) : Stream(name) {}
DevNull(const char *name = NULL) : Stream(name) {}

protected:
virtual int _getc() {return 0;}
Expand All @@ -13,14 +14,10 @@ class DevNull : public Stream {
DevNull null("null");

int main() {
printf("re-routing stdout to /null\n");

printf("MBED: re-routing stdout to /null\n");
freopen("/null", "w", stdout);
printf("printf redirected to /null\n");

DigitalOut led(LED1);
while (true) {
led = !led;
wait(1);
}
printf("MBED: printf redirected to /null\n"); // This shouldn't appear
// If failure message can be seen test should fail :)
notify_completion(false); // This is 'false' on purpose
return 0;
}
56 changes: 43 additions & 13 deletions libraries/tests/net/helloworld/tcpclient/main.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,61 @@
#include <algorithm>
#include "mbed.h"
#include "EthernetInterface.h"
#include "test_env.h"

namespace {
const char *HTTP_SERVER_NAME = "mbed.org";
const int HTTP_SERVER_PORT = 80;
const int RECV_BUFFER_SIZE = 512;

// Test related data
const char *HTTP_OK_STR = "200 OK";
const char *HTTP_HELLO_STR = "Hello world!";
}

bool find_substring(const char *first, const char *last, const char *s_first, const char *s_last) {
const char *f = std::search(first, last, s_first, s_last);
return (f != last);
}

int main() {
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();
printf("IP Address is %s\n", eth.getIPAddress());
printf("TCP client IP Address is %s\n", eth.getIPAddress());

TCPSocketConnection sock;
sock.connect("mbed.org", 80);
sock.connect(HTTP_SERVER_NAME, HTTP_SERVER_PORT);

char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
sock.send_all(http_cmd, sizeof(http_cmd));
char buffer[300];
int ret;

char buffer[RECV_BUFFER_SIZE] = {0};
bool result = true;
while (true) {
ret = sock.receive(buffer, sizeof(buffer)-1);
const int ret = sock.receive(buffer, sizeof(buffer) - 1);
if (ret <= 0)
break;
buffer[ret] = '\0';
printf("Received %d chars from server:\n%s\n", ret, buffer);

// Find 200 OK HTTP status in reply
bool found_200_ok = find_substring(buffer, buffer + ret, HTTP_OK_STR, HTTP_OK_STR + strlen(HTTP_OK_STR));
result = result && found_200_ok;

// Find Hello World! in reply
bool found_hello = find_substring(buffer, buffer + ret, HTTP_HELLO_STR, HTTP_HELLO_STR + strlen(HTTP_HELLO_STR));
result = result && found_hello;

// Print results
printf("HTTP: Received %d chars from server\r\n", ret);
printf("HTTP: Received 200 OK status ... %s\r\n", found_200_ok ? "[OK]" : "[FAIL]");
printf("HTTP: Received '%s' status ... %s\r\n", HTTP_HELLO_STR, found_hello ? "[OK]" : "[FAIL]");
printf("HTTP: Received massage:\r\n\r\n");
printf("%s", buffer);
}

sock.close();

eth.disconnect();

while(1) {}
notify_completion(result);
return 0;
}
48 changes: 34 additions & 14 deletions libraries/tests/net/helloworld/udpclient/main.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
#include "mbed.h"
#include "EthernetInterface.h"

#include "test_env.h"

namespace {
const char *HTTP_SERVER_NAME = "utcnist.colorado.edu";
const int HTTP_SERVER_PORT = 37;
}

int main() {
bool result = false;
EthernetInterface eth;
eth.init(); //Use DHCP
eth.connect();

printf("UDP client IP Address is %s\n", eth.getIPAddress());

UDPSocket sock;
sock.init();

Endpoint nist;
nist.set_address("utcnist.colorado.edu", 37);
nist.set_address(HTTP_SERVER_NAME, HTTP_SERVER_PORT);

char out_buffer[] = "plop"; // Does not matter
sock.sendTo(nist, out_buffer, sizeof(out_buffer));

char in_buffer[4];
int n = sock.receiveFrom(nist, in_buffer, sizeof(in_buffer));

unsigned int timeRes = ntohl( *((unsigned int*)in_buffer));
printf("Received %d bytes from server %s on port %d: %u seconds since 1/01/1900 00:00 GMT\n", n, nist.get_address(), nist.get_port(), timeRes);


union {
char in_buffer_tab[4];
unsigned int in_buffer_uint;
};

const int n = sock.receiveFrom(nist, in_buffer_tab, sizeof(in_buffer_tab));
if (n > 0) {
const unsigned int timeRes = ntohl(in_buffer_uint);
const float years = timeRes / 60.0 / 60.0 / 24.0 / 365;
printf("UDP: Received %d bytes from server %s on port %d\r\n", n, nist.get_address(), nist.get_port());
printf("UDP: %u seconds since 01/01/1900 00:00 GMT ... %s\r\n", timeRes, timeRes > 0 ? "[OK]" : "[FAIL]");
printf("UDP: %.2f years since 01/01/1900 00:00 GMT ... %s\r\n", years, timeRes > 114.0 ? "[OK]" : "[FAIL]");
result = true;

if (years < 114.0) {
result = false;
}
}
sock.close();

eth.disconnect();
while(1) {}
notify_completion(result);
return 0;
}
37 changes: 37 additions & 0 deletions workspace_tools/host_tests/dev_null_auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
mbed SDK
Copyright (c) 2011-2013 ARM Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

from host_test import Test, DefaultTest
from sys import stdout

class DevNullTest(DefaultTest):

def print_result(self, result):
print "\n{%s}\n{end}" % result

def run(self):
test_result = True
c = self.mbed.serial.read(512)
print "Received %d bytes" % len(c)
if "{failure}" not in c:
self.print_result('success')
else:
self.print_result('failure')
stdout.flush()

if __name__ == '__main__':
DevNullTest().run()
27 changes: 24 additions & 3 deletions workspace_tools/singletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ def get_result_summary_table():
for unique_id in unique_test_id:
# print "\t\t%s: %d / %d" % (unique_id, counter_dict_test_id_types[unique_id], counter_dict_test_id_types_all[unique_id])
percent_progress = round(100.0 * counter_dict_test_id_types[unique_id] / float(counter_dict_test_id_types_all[unique_id]), 2)
step = int(percent_progress / 2)
str_progress = '#' * step + '.' * int(50 - step)
str_progress = progress_bar(percent_progress, 75)
row = [unique_id,
counter_dict_test_id_types[unique_id],
counter_dict_test_id_types_all[unique_id],
Expand All @@ -435,6 +434,17 @@ def get_result_summary_table():
print pt


def progress_bar(percent_progress, saturation=0):
""" This function creates progress bar with optional simple saturation mark"""
step = int(percent_progress / 2) # Scale by to (scale: 1 - 50)
str_progress = '#' * step + '.' * int(50 - step)
c = '!' if str_progress[38] == '.' else '|'
if (saturation > 0):
saturation = saturation / 2
str_progress = str_progress[:saturation] + c + str_progress[saturation:]
return str_progress


if __name__ == '__main__':
# Command line options
parser = optparse.OptionParser()
Expand Down Expand Up @@ -472,14 +482,20 @@ def get_result_summary_table():
action="store_true",
help='Prints information about all tests and exits')

parser.add_option('-P', '--only-peripheral',
dest='test_only_peripheral',
default=False,
action="store_true",
help='Test only peripheral declared for MUT and skip common tests')

parser.add_option('-v', '--verbose',
dest='verbose',
default=False,
action="store_true",
help='Verbose mode (pronts some extra information)')

parser.description = """This script allows you to run mbed defined test cases for particular MCU(s) and corresponding toolchain(s)."""
parser.epilog = """Example: singletest.py -i test_spec.json [-M muts_all.json]"""
parser.epilog = """Example: singletest.py -i test_spec.json -M muts_all.json"""

(opts, args) = parser.parse_args()

Expand Down Expand Up @@ -527,6 +543,11 @@ def get_result_summary_table():
if test_ids and test_id not in test_ids:
continue

if opts.test_only_peripheral and not test.peripherals:
if opts.verbose:
print "TargetTest::%s::NotPeripheralTestSkipped(%s)" % (target, ",".join(test.peripherals))
continue

if test.automated and test.is_supported(target, toolchain):
if not is_peripherals_available(target, test.peripherals):
if opts.verbose:
Expand Down
Loading