mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #3930 from ARMmbed/release-candidate
Release candidate for mbed-os-5.4.1pull/3965/head mbed_lib_rev138
commit
f4864dc642
|
@ -114,7 +114,7 @@ public:
|
||||||
* 0 on success or un-needed,
|
* 0 on success or un-needed,
|
||||||
* -1 on error
|
* -1 on error
|
||||||
*/
|
*/
|
||||||
virtual int stat(const char *name, struct stat *st) = 0;
|
virtual int stat(const char *name, struct stat *st) { return -1; };
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -66,6 +66,6 @@ void hal_sleep(void)
|
||||||
|
|
||||||
void hal_deepsleep(void)
|
void hal_deepsleep(void)
|
||||||
{
|
{
|
||||||
sleep();
|
hal_sleep();
|
||||||
// NRF_POWER->SYSTEMOFF=1;
|
// NRF_POWER->SYSTEMOFF=1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,10 @@ static __INLINE uint32_t pstorage_flash_page_end()
|
||||||
|
|
||||||
#define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
|
#define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
|
||||||
|
|
||||||
|
#ifndef PSTORAGE_NUM_OF_PAGES
|
||||||
#define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
|
#define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
|
#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
|
||||||
|
|
||||||
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
|
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
|
||||||
|
|
|
@ -91,7 +91,7 @@ void test_dns_literal_pref() {
|
||||||
|
|
||||||
// Test setup
|
// Test setup
|
||||||
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
utest::v1::status_t test_setup(const size_t number_of_cases) {
|
||||||
GREENTEA_SETUP(20, "default_auto");
|
GREENTEA_SETUP(60, "default_auto");
|
||||||
net_bringup();
|
net_bringup();
|
||||||
return verbose_test_setup_handler(number_of_cases);
|
return verbose_test_setup_handler(number_of_cases);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "tcp_echo");
|
GREENTEA_SETUP(60, "tcp_echo");
|
||||||
|
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
eth.connect();
|
eth.connect();
|
||||||
|
|
|
@ -88,7 +88,7 @@ Echo echoers[MBED_CFG_TCP_CLIENT_ECHO_THREADS];
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "tcp_echo");
|
GREENTEA_SETUP(60, "tcp_echo");
|
||||||
|
|
||||||
int err = net.connect();
|
int err = net.connect();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
|
@ -36,7 +36,7 @@ bool find_substring(const char *first, const char *last, const char *s_first, co
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "default_auto");
|
GREENTEA_SETUP(60, "default_auto");
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
|
|
|
@ -28,7 +28,7 @@ int udp_dtls_handshake_pattern[] = {MBED_CFG_UDP_DTLS_HANDSHAKE_PATTERN};
|
||||||
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);
|
const int udp_dtls_handshake_count = sizeof(udp_dtls_handshake_pattern) / sizeof(int);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "udp_shotgun");
|
GREENTEA_SETUP(60, "udp_shotgun");
|
||||||
|
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
int err = eth.connect();
|
int err = eth.connect();
|
||||||
|
|
|
@ -34,7 +34,7 @@ void prep_buffer(char *tx_buffer, size_t tx_size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "udp_echo");
|
GREENTEA_SETUP(60, "udp_echo");
|
||||||
|
|
||||||
EthernetInterface eth;
|
EthernetInterface eth;
|
||||||
eth.connect();
|
eth.connect();
|
||||||
|
|
|
@ -99,7 +99,7 @@ Echo echoers[MBED_CFG_UDP_CLIENT_ECHO_THREADS];
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
GREENTEA_SETUP(20, "udp_echo");
|
GREENTEA_SETUP(60, "udp_echo");
|
||||||
|
|
||||||
int err = net.connect();
|
int err = net.connect();
|
||||||
TEST_ASSERT_EQUAL(0, err);
|
TEST_ASSERT_EQUAL(0, err);
|
||||||
|
|
|
@ -117,7 +117,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return Size of the underlying device in bytes
|
* @return Size of the underlying device in bytes
|
||||||
*/
|
*/
|
||||||
virtual bd_size_t size() = 0;
|
virtual bd_size_t size() const = 0;
|
||||||
|
|
||||||
/** Convenience function for checking block read validity
|
/** Convenience function for checking block read validity
|
||||||
*
|
*
|
||||||
|
@ -125,7 +125,7 @@ public:
|
||||||
* @param size Size to read in bytes
|
* @param size Size to read in bytes
|
||||||
* @return True if read is valid for underlying block device
|
* @return True if read is valid for underlying block device
|
||||||
*/
|
*/
|
||||||
bool is_valid_read(bd_addr_t addr, bd_size_t size)
|
bool is_valid_read(bd_addr_t addr, bd_size_t size) const
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
addr % get_read_size() == 0 &&
|
addr % get_read_size() == 0 &&
|
||||||
|
@ -139,7 +139,7 @@ public:
|
||||||
* @param size Size to write in bytes
|
* @param size Size to write in bytes
|
||||||
* @return True if program is valid for underlying block device
|
* @return True if program is valid for underlying block device
|
||||||
*/
|
*/
|
||||||
bool is_valid_program(bd_addr_t addr, bd_size_t size)
|
bool is_valid_program(bd_addr_t addr, bd_size_t size) const
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
addr % get_program_size() == 0 &&
|
addr % get_program_size() == 0 &&
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
* @param size Size to erase in bytes
|
* @param size Size to erase in bytes
|
||||||
* @return True if erase is valid for underlying block device
|
* @return True if erase is valid for underlying block device
|
||||||
*/
|
*/
|
||||||
bool is_valid_erase(bd_addr_t addr, bd_size_t size)
|
bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
addr % get_erase_size() == 0 &&
|
addr % get_erase_size() == 0 &&
|
||||||
|
|
|
@ -190,7 +190,7 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
|
||||||
return _erase_size;
|
return _erase_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bd_size_t ChainingBlockDevice::size()
|
bd_size_t ChainingBlockDevice::size() const
|
||||||
{
|
{
|
||||||
return _size;
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return Size of the underlying device in bytes
|
* @return Size of the underlying device in bytes
|
||||||
*/
|
*/
|
||||||
virtual bd_size_t size();
|
virtual bd_size_t size() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BlockDevice **_bds;
|
BlockDevice **_bds;
|
||||||
|
|
|
@ -77,7 +77,7 @@ bd_size_t HeapBlockDevice::get_erase_size() const
|
||||||
return _erase_size;
|
return _erase_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bd_size_t HeapBlockDevice::size()
|
bd_size_t HeapBlockDevice::size() const
|
||||||
{
|
{
|
||||||
return _count * _erase_size;
|
return _count * _erase_size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return Size of the underlying device in bytes
|
* @return Size of the underlying device in bytes
|
||||||
*/
|
*/
|
||||||
virtual bd_size_t size();
|
virtual bd_size_t size() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bd_size_t _read_size;
|
bd_size_t _read_size;
|
||||||
|
|
|
@ -108,7 +108,7 @@ bd_size_t SlicingBlockDevice::get_erase_size() const
|
||||||
return _bd->get_erase_size();
|
return _bd->get_erase_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bd_size_t SlicingBlockDevice::size()
|
bd_size_t SlicingBlockDevice::size() const
|
||||||
{
|
{
|
||||||
return _stop - _start;
|
return _stop - _start;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ public:
|
||||||
*
|
*
|
||||||
* @return Size of the underlying device in bytes
|
* @return Size of the underlying device in bytes
|
||||||
*/
|
*/
|
||||||
virtual bd_size_t size();
|
virtual bd_size_t size() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BlockDevice *_bd;
|
BlockDevice *_bd;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
mbedtls-2.4.0
|
mbedtls-2.4.2
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
# Set the mbed TLS release to import (this can/should be edited before import)
|
# Set the mbed TLS release to import (this can/should be edited before import)
|
||||||
MBED_TLS_RELEASE ?= mbedtls-2.4.0
|
MBED_TLS_RELEASE ?= mbedtls-2.4.2
|
||||||
|
|
||||||
# Translate between mbed TLS namespace and mbed namespace
|
# Translate between mbed TLS namespace and mbed namespace
|
||||||
TARGET_PREFIX:=../
|
TARGET_PREFIX:=../
|
||||||
|
|
|
@ -58,9 +58,13 @@ struct mbedtls_cmac_context_t
|
||||||
/**
|
/**
|
||||||
* \brief Set the CMAC key and prepare to authenticate the input
|
* \brief Set the CMAC key and prepare to authenticate the input
|
||||||
* data.
|
* data.
|
||||||
* Should be called with an initialised cipher context.
|
* Should be called with an initialized cipher context.
|
||||||
*
|
*
|
||||||
* \param ctx Cipher context
|
* \param ctx Cipher context. This should be a cipher context,
|
||||||
|
* initialized to be one of the following types:
|
||||||
|
* MBEDTLS_CIPHER_AES_128_ECB, MBEDTLS_CIPHER_AES_192_ECB,
|
||||||
|
* MBEDTLS_CIPHER_AES_256_ECB or
|
||||||
|
* MBEDTLS_CIPHER_DES_EDE3_ECB.
|
||||||
* \param key CMAC key
|
* \param key CMAC key
|
||||||
* \param keybits length of the CMAC key in bits
|
* \param keybits length of the CMAC key in bits
|
||||||
* (must be acceptable by the cipher)
|
* (must be acceptable by the cipher)
|
||||||
|
@ -115,7 +119,7 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||||
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Output = Generic_CMAC( hmac key, input buffer )
|
* \brief Output = Generic_CMAC( cmac key, input buffer )
|
||||||
*
|
*
|
||||||
* \param cipher_info message digest info
|
* \param cipher_info message digest info
|
||||||
* \param key CMAC key
|
* \param key CMAC key
|
||||||
|
|
|
@ -2453,7 +2453,6 @@
|
||||||
#define ssl_set_arc4_support mbedtls_ssl_conf_arc4_support
|
#define ssl_set_arc4_support mbedtls_ssl_conf_arc4_support
|
||||||
#define ssl_set_authmode mbedtls_ssl_conf_authmode
|
#define ssl_set_authmode mbedtls_ssl_conf_authmode
|
||||||
#define ssl_set_bio mbedtls_ssl_set_bio
|
#define ssl_set_bio mbedtls_ssl_set_bio
|
||||||
#define ssl_set_bio mbedtls_ssl_set_bio_timeout
|
|
||||||
#define ssl_set_ca_chain mbedtls_ssl_conf_ca_chain
|
#define ssl_set_ca_chain mbedtls_ssl_conf_ca_chain
|
||||||
#define ssl_set_cbc_record_splitting mbedtls_ssl_conf_cbc_record_splitting
|
#define ssl_set_cbc_record_splitting mbedtls_ssl_conf_cbc_record_splitting
|
||||||
#define ssl_set_ciphersuites mbedtls_ssl_conf_ciphersuites
|
#define ssl_set_ciphersuites mbedtls_ssl_conf_ciphersuites
|
||||||
|
|
|
@ -1540,7 +1540,7 @@
|
||||||
* library/pkwrite.c
|
* library/pkwrite.c
|
||||||
* library/x509_create.c
|
* library/x509_create.c
|
||||||
* library/x509write_crt.c
|
* library/x509write_crt.c
|
||||||
* library/mbedtls_x509write_csr.c
|
* library/x509write_csr.c
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_ASN1_WRITE_C
|
#define MBEDTLS_ASN1_WRITE_C
|
||||||
|
|
||||||
|
@ -1901,7 +1901,7 @@
|
||||||
*
|
*
|
||||||
* Enable the generic message digest layer.
|
* Enable the generic message digest layer.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_md.c
|
* Module: library/md.c
|
||||||
* Caller:
|
* Caller:
|
||||||
*
|
*
|
||||||
* Uncomment to enable generic message digest wrappers.
|
* Uncomment to enable generic message digest wrappers.
|
||||||
|
@ -1913,7 +1913,7 @@
|
||||||
*
|
*
|
||||||
* Enable the MD2 hash algorithm.
|
* Enable the MD2 hash algorithm.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_md2.c
|
* Module: library/md2.c
|
||||||
* Caller:
|
* Caller:
|
||||||
*
|
*
|
||||||
* Uncomment to enable support for (rare) MD2-signed X.509 certs.
|
* Uncomment to enable support for (rare) MD2-signed X.509 certs.
|
||||||
|
@ -1925,7 +1925,7 @@
|
||||||
*
|
*
|
||||||
* Enable the MD4 hash algorithm.
|
* Enable the MD4 hash algorithm.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_md4.c
|
* Module: library/md4.c
|
||||||
* Caller:
|
* Caller:
|
||||||
*
|
*
|
||||||
* Uncomment to enable support for (rare) MD4-signed X.509 certs.
|
* Uncomment to enable support for (rare) MD4-signed X.509 certs.
|
||||||
|
@ -1937,8 +1937,8 @@
|
||||||
*
|
*
|
||||||
* Enable the MD5 hash algorithm.
|
* Enable the MD5 hash algorithm.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_md5.c
|
* Module: library/md5.c
|
||||||
* Caller: library/mbedtls_md.c
|
* Caller: library/md.c
|
||||||
* library/pem.c
|
* library/pem.c
|
||||||
* library/ssl_tls.c
|
* library/ssl_tls.c
|
||||||
*
|
*
|
||||||
|
@ -1995,11 +1995,11 @@
|
||||||
* library/rsa.c
|
* library/rsa.c
|
||||||
* library/x509.c
|
* library/x509.c
|
||||||
* library/x509_create.c
|
* library/x509_create.c
|
||||||
* library/mbedtls_x509_crl.c
|
* library/x509_crl.c
|
||||||
* library/mbedtls_x509_crt.c
|
* library/x509_crt.c
|
||||||
* library/mbedtls_x509_csr.c
|
* library/x509_csr.c
|
||||||
* library/x509write_crt.c
|
* library/x509write_crt.c
|
||||||
* library/mbedtls_x509write_csr.c
|
* library/x509write_csr.c
|
||||||
*
|
*
|
||||||
* This modules translates between OIDs and internal values.
|
* This modules translates between OIDs and internal values.
|
||||||
*/
|
*/
|
||||||
|
@ -2027,9 +2027,9 @@
|
||||||
* Module: library/pem.c
|
* Module: library/pem.c
|
||||||
* Caller: library/dhm.c
|
* Caller: library/dhm.c
|
||||||
* library/pkparse.c
|
* library/pkparse.c
|
||||||
* library/mbedtls_x509_crl.c
|
* library/x509_crl.c
|
||||||
* library/mbedtls_x509_crt.c
|
* library/x509_crt.c
|
||||||
* library/mbedtls_x509_csr.c
|
* library/x509_csr.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_BASE64_C
|
* Requires: MBEDTLS_BASE64_C
|
||||||
*
|
*
|
||||||
|
@ -2045,7 +2045,7 @@
|
||||||
* Module: library/pem.c
|
* Module: library/pem.c
|
||||||
* Caller: library/pkwrite.c
|
* Caller: library/pkwrite.c
|
||||||
* library/x509write_crt.c
|
* library/x509write_crt.c
|
||||||
* library/mbedtls_x509write_csr.c
|
* library/x509write_csr.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_BASE64_C
|
* Requires: MBEDTLS_BASE64_C
|
||||||
*
|
*
|
||||||
|
@ -2075,8 +2075,8 @@
|
||||||
* Enable the generic public (asymetric) key parser.
|
* Enable the generic public (asymetric) key parser.
|
||||||
*
|
*
|
||||||
* Module: library/pkparse.c
|
* Module: library/pkparse.c
|
||||||
* Caller: library/mbedtls_x509_crt.c
|
* Caller: library/x509_crt.c
|
||||||
* library/mbedtls_x509_csr.c
|
* library/x509_csr.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_PK_C
|
* Requires: MBEDTLS_PK_C
|
||||||
*
|
*
|
||||||
|
@ -2167,8 +2167,8 @@
|
||||||
*
|
*
|
||||||
* Enable the RIPEMD-160 hash algorithm.
|
* Enable the RIPEMD-160 hash algorithm.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_ripemd160.c
|
* Module: library/ripemd160.c
|
||||||
* Caller: library/mbedtls_md.c
|
* Caller: library/md.c
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
//#define MBEDTLS_RIPEMD160_C
|
//#define MBEDTLS_RIPEMD160_C
|
||||||
|
@ -2196,8 +2196,8 @@
|
||||||
*
|
*
|
||||||
* Enable the SHA1 cryptographic hash algorithm.
|
* Enable the SHA1 cryptographic hash algorithm.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_sha1.c
|
* Module: library/sha1.c
|
||||||
* Caller: library/mbedtls_md.c
|
* Caller: library/md.c
|
||||||
* library/ssl_cli.c
|
* library/ssl_cli.c
|
||||||
* library/ssl_srv.c
|
* library/ssl_srv.c
|
||||||
* library/ssl_tls.c
|
* library/ssl_tls.c
|
||||||
|
@ -2212,9 +2212,9 @@
|
||||||
*
|
*
|
||||||
* Enable the SHA-224 and SHA-256 cryptographic hash algorithms.
|
* Enable the SHA-224 and SHA-256 cryptographic hash algorithms.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_sha256.c
|
* Module: library/sha256.c
|
||||||
* Caller: library/entropy.c
|
* Caller: library/entropy.c
|
||||||
* library/mbedtls_md.c
|
* library/md.c
|
||||||
* library/ssl_cli.c
|
* library/ssl_cli.c
|
||||||
* library/ssl_srv.c
|
* library/ssl_srv.c
|
||||||
* library/ssl_tls.c
|
* library/ssl_tls.c
|
||||||
|
@ -2229,9 +2229,9 @@
|
||||||
*
|
*
|
||||||
* Enable the SHA-384 and SHA-512 cryptographic hash algorithms.
|
* Enable the SHA-384 and SHA-512 cryptographic hash algorithms.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_sha512.c
|
* Module: library/sha512.c
|
||||||
* Caller: library/entropy.c
|
* Caller: library/entropy.c
|
||||||
* library/mbedtls_md.c
|
* library/md.c
|
||||||
* library/ssl_cli.c
|
* library/ssl_cli.c
|
||||||
* library/ssl_srv.c
|
* library/ssl_srv.c
|
||||||
*
|
*
|
||||||
|
@ -2379,9 +2379,9 @@
|
||||||
* Enable X.509 core for using certificates.
|
* Enable X.509 core for using certificates.
|
||||||
*
|
*
|
||||||
* Module: library/x509.c
|
* Module: library/x509.c
|
||||||
* Caller: library/mbedtls_x509_crl.c
|
* Caller: library/x509_crl.c
|
||||||
* library/mbedtls_x509_crt.c
|
* library/x509_crt.c
|
||||||
* library/mbedtls_x509_csr.c
|
* library/x509_csr.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C,
|
* Requires: MBEDTLS_ASN1_PARSE_C, MBEDTLS_BIGNUM_C, MBEDTLS_OID_C,
|
||||||
* MBEDTLS_PK_PARSE_C
|
* MBEDTLS_PK_PARSE_C
|
||||||
|
@ -2395,7 +2395,7 @@
|
||||||
*
|
*
|
||||||
* Enable X.509 certificate parsing.
|
* Enable X.509 certificate parsing.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_x509_crt.c
|
* Module: library/x509_crt.c
|
||||||
* Caller: library/ssl_cli.c
|
* Caller: library/ssl_cli.c
|
||||||
* library/ssl_srv.c
|
* library/ssl_srv.c
|
||||||
* library/ssl_tls.c
|
* library/ssl_tls.c
|
||||||
|
@ -2411,8 +2411,8 @@
|
||||||
*
|
*
|
||||||
* Enable X.509 CRL parsing.
|
* Enable X.509 CRL parsing.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_x509_crl.c
|
* Module: library/x509_crl.c
|
||||||
* Caller: library/mbedtls_x509_crt.c
|
* Caller: library/x509_crt.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_X509_USE_C
|
* Requires: MBEDTLS_X509_USE_C
|
||||||
*
|
*
|
||||||
|
@ -2425,7 +2425,7 @@
|
||||||
*
|
*
|
||||||
* Enable X.509 Certificate Signing Request (CSR) parsing.
|
* Enable X.509 Certificate Signing Request (CSR) parsing.
|
||||||
*
|
*
|
||||||
* Module: library/mbedtls_x509_csr.c
|
* Module: library/x509_csr.c
|
||||||
* Caller: library/x509_crt_write.c
|
* Caller: library/x509_crt_write.c
|
||||||
*
|
*
|
||||||
* Requires: MBEDTLS_X509_USE_C
|
* Requires: MBEDTLS_X509_USE_C
|
||||||
|
|
|
@ -206,7 +206,7 @@ int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, const mbedtls_rs
|
||||||
* \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
|
* \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
|
||||||
*
|
*
|
||||||
* \note This function does NOT take care of message
|
* \note This function does NOT take care of message
|
||||||
* padding. Also, be sure to set input[0] = 0 or assure that
|
* padding. Also, be sure to set input[0] = 0 or ensure that
|
||||||
* input is smaller than N.
|
* input is smaller than N.
|
||||||
*
|
*
|
||||||
* \note The input and output buffers must be large
|
* \note The input and output buffers must be large
|
||||||
|
|
|
@ -1146,7 +1146,7 @@ void mbedtls_ssl_conf_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout )
|
||||||
*
|
*
|
||||||
* \note See the documentation of \c mbedtls_ssl_set_timer_t and
|
* \note See the documentation of \c mbedtls_ssl_set_timer_t and
|
||||||
* \c mbedtls_ssl_get_timer_t for the conventions this pair of
|
* \c mbedtls_ssl_get_timer_t for the conventions this pair of
|
||||||
* callbacks must fallow.
|
* callbacks must follow.
|
||||||
*
|
*
|
||||||
* \note On some platforms, timing.c provides
|
* \note On some platforms, timing.c provides
|
||||||
* \c mbedtls_timing_set_delay() and
|
* \c mbedtls_timing_set_delay() and
|
||||||
|
@ -2183,7 +2183,7 @@ void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Set record counter threshold for periodic renegotiation.
|
* \brief Set record counter threshold for periodic renegotiation.
|
||||||
* (Default: 2^64 - 256.)
|
* (Default: 2^48 - 1)
|
||||||
*
|
*
|
||||||
* Renegotiation is automatically triggered when a record
|
* Renegotiation is automatically triggered when a record
|
||||||
* counter (outgoing or ingoing) crosses the defined
|
* counter (outgoing or ingoing) crosses the defined
|
||||||
|
@ -2194,9 +2194,17 @@ void mbedtls_ssl_conf_renegotiation_enforced( mbedtls_ssl_config *conf, int max_
|
||||||
* Lower values can be used to enforce policies such as "keys
|
* Lower values can be used to enforce policies such as "keys
|
||||||
* must be refreshed every N packets with cipher X".
|
* must be refreshed every N packets with cipher X".
|
||||||
*
|
*
|
||||||
|
* The renegotiation period can be disabled by setting
|
||||||
|
* conf->disable_renegotiation to
|
||||||
|
* MBEDTLS_SSL_RENEGOTIATION_DISABLED.
|
||||||
|
*
|
||||||
|
* \note When the configured transport is
|
||||||
|
* MBEDTLS_SSL_TRANSPORT_DATAGRAM the maximum renegotiation
|
||||||
|
* period is 2^48 - 1, and for MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
|
* the maximum renegotiation period is 2^64 - 1.
|
||||||
|
*
|
||||||
* \param conf SSL configuration
|
* \param conf SSL configuration
|
||||||
* \param period The threshold value: a big-endian 64-bit number.
|
* \param period The threshold value: a big-endian 64-bit number.
|
||||||
* Set to 2^64 - 1 to disable periodic renegotiation
|
|
||||||
*/
|
*/
|
||||||
void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
|
void mbedtls_ssl_conf_renegotiation_period( mbedtls_ssl_config *conf,
|
||||||
const unsigned char period[8] );
|
const unsigned char period[8] );
|
||||||
|
@ -2428,7 +2436,7 @@ int mbedtls_ssl_read( mbedtls_ssl_context *ssl, unsigned char *buf, size_t len )
|
||||||
* \param len how many bytes must be written
|
* \param len how many bytes must be written
|
||||||
*
|
*
|
||||||
* \return the number of bytes actually written (may be less than len),
|
* \return the number of bytes actually written (may be less than len),
|
||||||
* or MBEDTLS_ERR_SSL_WANT_WRITE of MBEDTLS_ERR_SSL_WANT_READ,
|
* or MBEDTLS_ERR_SSL_WANT_WRITE or MBEDTLS_ERR_SSL_WANT_READ,
|
||||||
* or another negative error code.
|
* or another negative error code.
|
||||||
*
|
*
|
||||||
* \note If this function returns something other than a positive
|
* \note If this function returns something other than a positive
|
||||||
|
@ -2513,7 +2521,6 @@ void mbedtls_ssl_config_init( mbedtls_ssl_config *conf );
|
||||||
* \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
|
* \param transport MBEDTLS_SSL_TRANSPORT_STREAM for TLS, or
|
||||||
* MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
|
* MBEDTLS_SSL_TRANSPORT_DATAGRAM for DTLS
|
||||||
* \param preset a MBEDTLS_SSL_PRESET_XXX value
|
* \param preset a MBEDTLS_SSL_PRESET_XXX value
|
||||||
* (currently unused).
|
|
||||||
*
|
*
|
||||||
* \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
|
* \note See \c mbedtls_ssl_conf_transport() for notes on DTLS.
|
||||||
*
|
*
|
||||||
|
|
|
@ -39,16 +39,16 @@
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_VERSION_MAJOR 2
|
#define MBEDTLS_VERSION_MAJOR 2
|
||||||
#define MBEDTLS_VERSION_MINOR 4
|
#define MBEDTLS_VERSION_MINOR 4
|
||||||
#define MBEDTLS_VERSION_PATCH 0
|
#define MBEDTLS_VERSION_PATCH 2
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The single version number has the following structure:
|
* The single version number has the following structure:
|
||||||
* MMNNPP00
|
* MMNNPP00
|
||||||
* Major version | Minor version | Patch version
|
* Major version | Minor version | Patch version
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_VERSION_NUMBER 0x02040000
|
#define MBEDTLS_VERSION_NUMBER 0x02040200
|
||||||
#define MBEDTLS_VERSION_STRING "2.4.0"
|
#define MBEDTLS_VERSION_STRING "2.4.2"
|
||||||
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.4.0"
|
#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 2.4.2"
|
||||||
|
|
||||||
#if defined(MBEDTLS_VERSION_C)
|
#if defined(MBEDTLS_VERSION_C)
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@
|
||||||
#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
|
#define MBEDTLS_X509_EXT_INIHIBIT_ANYPOLICY (1 << 13)
|
||||||
#define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
|
#define MBEDTLS_X509_EXT_FRESHEST_CRL (1 << 14)
|
||||||
|
|
||||||
#define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16) /* Parsed (and then ?) */
|
#define MBEDTLS_X509_EXT_NS_CERT_TYPE (1 << 16)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Storage format identifiers
|
* Storage format identifiers
|
||||||
|
|
|
@ -192,7 +192,11 @@ int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
n = ( ( n * 6 ) + 7 ) >> 3;
|
/* The following expression is to calculate the following formula without
|
||||||
|
* risk of integer overflow in n:
|
||||||
|
* n = ( ( n * 6 ) + 7 ) >> 3;
|
||||||
|
*/
|
||||||
|
n = ( 6 * ( n >> 3 ) ) + ( ( 6 * ( n & 0x7 ) + 7 ) >> 3 );
|
||||||
n -= j;
|
n -= j;
|
||||||
|
|
||||||
if( dst == NULL || dlen < n )
|
if( dst == NULL || dlen < n )
|
||||||
|
|
|
@ -534,7 +534,12 @@ int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
|
||||||
n = mbedtls_mpi_bitlen( X );
|
n = mbedtls_mpi_bitlen( X );
|
||||||
if( radix >= 4 ) n >>= 1;
|
if( radix >= 4 ) n >>= 1;
|
||||||
if( radix >= 16 ) n >>= 1;
|
if( radix >= 16 ) n >>= 1;
|
||||||
n += 3;
|
/*
|
||||||
|
* Round up the buffer length to an even value to ensure that there is
|
||||||
|
* enough room for hexadecimal values that can be represented in an odd
|
||||||
|
* number of digits.
|
||||||
|
*/
|
||||||
|
n += 3 + ( ( n + 1 ) & 1 );
|
||||||
|
|
||||||
if( buflen < n )
|
if( buflen < n )
|
||||||
{
|
{
|
||||||
|
|
|
@ -326,9 +326,9 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i
|
||||||
* If there is not enough data for a full block, cache it.
|
* If there is not enough data for a full block, cache it.
|
||||||
*/
|
*/
|
||||||
if( ( ctx->operation == MBEDTLS_DECRYPT &&
|
if( ( ctx->operation == MBEDTLS_DECRYPT &&
|
||||||
ilen + ctx->unprocessed_len <= block_size ) ||
|
ilen <= block_size - ctx->unprocessed_len ) ||
|
||||||
( ctx->operation == MBEDTLS_ENCRYPT &&
|
( ctx->operation == MBEDTLS_ENCRYPT &&
|
||||||
ilen + ctx->unprocessed_len < block_size ) )
|
ilen < block_size - ctx->unprocessed_len ) )
|
||||||
{
|
{
|
||||||
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
memcpy( &( ctx->unprocessed_data[ctx->unprocessed_len] ), input,
|
||||||
ilen );
|
ilen );
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
*
|
*
|
||||||
* - NIST SP 800-38B Recommendation for Block Cipher Modes of Operation: The
|
* - NIST SP 800-38B Recommendation for Block Cipher Modes of Operation: The
|
||||||
* CMAC Mode for Authentication
|
* CMAC Mode for Authentication
|
||||||
* http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38b.pdf
|
* http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-38b.pdf
|
||||||
*
|
*
|
||||||
* - RFC 4493 - The AES-CMAC Algorithm
|
* - RFC 4493 - The AES-CMAC Algorithm
|
||||||
* https://tools.ietf.org/html/rfc4493
|
* https://tools.ietf.org/html/rfc4493
|
||||||
|
@ -62,7 +62,7 @@
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define mbedtls_printf printf
|
#define mbedtls_printf printf
|
||||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C || MBEDTLS_DES_C */
|
#endif /* MBEDTLS_SELF_TEST */
|
||||||
#endif /* MBEDTLS_PLATFORM_C */
|
#endif /* MBEDTLS_PLATFORM_C */
|
||||||
|
|
||||||
/* Implementation that should never be optimized out by the compiler */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
|
@ -80,7 +80,7 @@ static void mbedtls_zeroize( void *v, size_t n ) {
|
||||||
* with R_64 = 0x1B and R_128 = 0x87
|
* with R_64 = 0x1B and R_128 = 0x87
|
||||||
*
|
*
|
||||||
* Input and output MUST NOT point to the same buffer
|
* Input and output MUST NOT point to the same buffer
|
||||||
* Block size must be 8 byes or 16 bytes - the block sizes for DES and AES.
|
* Block size must be 8 bytes or 16 bytes - the block sizes for DES and AES.
|
||||||
*/
|
*/
|
||||||
static int cmac_multiply_by_u( unsigned char *output,
|
static int cmac_multiply_by_u( unsigned char *output,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
|
@ -105,7 +105,7 @@ static int cmac_multiply_by_u( unsigned char *output,
|
||||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i = blocksize - 1; i >= 0; i-- )
|
for( i = (int)blocksize - 1; i >= 0; i-- )
|
||||||
{
|
{
|
||||||
output[i] = input[i] << 1 | overflow;
|
output[i] = input[i] << 1 | overflow;
|
||||||
overflow = input[i] >> 7;
|
overflow = input[i] >> 7;
|
||||||
|
@ -209,7 +209,7 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||||
if( ctx == NULL || ctx->cipher_info == NULL || key == NULL )
|
if( ctx == NULL || ctx->cipher_info == NULL || key == NULL )
|
||||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||||
|
|
||||||
if( ( retval = mbedtls_cipher_setkey( ctx, key, keybits,
|
if( ( retval = mbedtls_cipher_setkey( ctx, key, (int)keybits,
|
||||||
MBEDTLS_ENCRYPT ) ) != 0 )
|
MBEDTLS_ENCRYPT ) ) != 0 )
|
||||||
return( retval );
|
return( retval );
|
||||||
|
|
||||||
|
@ -244,8 +244,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||||
{
|
{
|
||||||
mbedtls_cmac_context_t* cmac_ctx;
|
mbedtls_cmac_context_t* cmac_ctx;
|
||||||
unsigned char *state;
|
unsigned char *state;
|
||||||
int n, j, ret = 0;
|
int ret = 0;
|
||||||
size_t olen, block_size;
|
size_t n, j, olen, block_size;
|
||||||
|
|
||||||
if( ctx == NULL || ctx->cipher_info == NULL || input == NULL ||
|
if( ctx == NULL || ctx->cipher_info == NULL || input == NULL ||
|
||||||
ctx->cmac_ctx == NULL )
|
ctx->cmac_ctx == NULL )
|
||||||
|
@ -280,8 +280,9 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||||
/* n is the number of blocks including any final partial block */
|
/* n is the number of blocks including any final partial block */
|
||||||
n = ( ilen + block_size - 1 ) / block_size;
|
n = ( ilen + block_size - 1 ) / block_size;
|
||||||
|
|
||||||
/* Iterate across the input data in block sized chunks */
|
/* Iterate across the input data in block sized chunks, excluding any
|
||||||
for( j = 0; j < n - 1; j++ )
|
* final partial or complete block */
|
||||||
|
for( j = 1; j < n; j++ )
|
||||||
{
|
{
|
||||||
cmac_xor_block( state, input, state, block_size );
|
cmac_xor_block( state, input, state, block_size );
|
||||||
|
|
||||||
|
@ -469,8 +470,9 @@ exit:
|
||||||
|
|
||||||
#if defined(MBEDTLS_SELF_TEST)
|
#if defined(MBEDTLS_SELF_TEST)
|
||||||
/*
|
/*
|
||||||
* CMAC test data from SP800-38B Appendix D.1 (corrected)
|
* CMAC test data for SP800-38B
|
||||||
* http://csrc.nist.gov/publications/nistpubs/800-38B/Updated_CMAC_Examples.pdf
|
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CMAC.pdf
|
||||||
|
* http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/TDES_CMAC.pdf
|
||||||
*
|
*
|
||||||
* AES-CMAC-PRF-128 test data from RFC 4615
|
* AES-CMAC-PRF-128 test data from RFC 4615
|
||||||
* https://tools.ietf.org/html/rfc4615#page-4
|
* https://tools.ietf.org/html/rfc4615#page-4
|
||||||
|
@ -482,128 +484,148 @@ exit:
|
||||||
#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C)
|
#if defined(MBEDTLS_AES_C) || defined(MBEDTLS_DES_C)
|
||||||
/* All CMAC test inputs are truncated from the same 64 byte buffer. */
|
/* All CMAC test inputs are truncated from the same 64 byte buffer. */
|
||||||
static const unsigned char test_message[] = {
|
static const unsigned char test_message[] = {
|
||||||
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
/* PT */
|
||||||
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
|
||||||
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
|
||||||
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
|
||||||
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
|
||||||
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
|
||||||
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
|
||||||
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
|
0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
|
||||||
|
0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10
|
||||||
};
|
};
|
||||||
#endif /* MBEDTLS_AES_C || MBEDTLS_DES_C */
|
#endif /* MBEDTLS_AES_C || MBEDTLS_DES_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_AES_C)
|
#if defined(MBEDTLS_AES_C)
|
||||||
/* Truncation point of message for AES CMAC tests */
|
/* Truncation point of message for AES CMAC tests */
|
||||||
static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
static const unsigned int aes_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
||||||
|
/* Mlen */
|
||||||
0,
|
0,
|
||||||
16,
|
16,
|
||||||
40,
|
20,
|
||||||
64
|
64
|
||||||
};
|
};
|
||||||
|
|
||||||
/* AES 128 CMAC Test Data */
|
/* CMAC-AES128 Test Data */
|
||||||
static const unsigned char aes_128_key[16] = {
|
static const unsigned char aes_128_key[16] = {
|
||||||
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
|
||||||
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
|
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
|
||||||
};
|
};
|
||||||
static const unsigned char aes_128_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_128_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66,
|
/* K1 */
|
||||||
0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde
|
0xfb, 0xee, 0xd6, 0x18, 0x35, 0x71, 0x33, 0x66,
|
||||||
|
0x7c, 0x85, 0xe0, 0x8f, 0x72, 0x36, 0xa8, 0xde
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc,
|
/* K2 */
|
||||||
0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b
|
0xf7, 0xdd, 0xac, 0x30, 0x6a, 0xe2, 0x66, 0xcc,
|
||||||
|
0xf9, 0x0b, 0xc1, 0x1e, 0xe4, 0x6d, 0x51, 0x3b
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static const unsigned char aes_128_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_128_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
/* Example #1 */
|
||||||
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
|
0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
|
||||||
|
0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
/* Example #2 */
|
||||||
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
|
0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
|
||||||
|
0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
|
/* Example #3 */
|
||||||
0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27
|
0x7d, 0x85, 0x44, 0x9e, 0xa6, 0xea, 0x19, 0xc8,
|
||||||
|
0x23, 0xa7, 0xbf, 0x78, 0x83, 0x7d, 0xfa, 0xde
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
/* Example #4 */
|
||||||
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
|
0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
|
||||||
|
0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* AES 192 CMAC Test Data */
|
/* CMAC-AES192 Test Data */
|
||||||
static const unsigned char aes_192_key[24] = {
|
static const unsigned char aes_192_key[24] = {
|
||||||
0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
|
0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
|
||||||
0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
|
0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
|
||||||
0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
|
0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b
|
||||||
};
|
};
|
||||||
static const unsigned char aes_192_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_192_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0x44, 0x8a, 0x5b, 0x1c, 0x93, 0x51, 0x4b, 0x27,
|
/* K1 */
|
||||||
0x3e, 0xe6, 0x43, 0x9d, 0xd4, 0xda, 0xa2, 0x96
|
0x44, 0x8a, 0x5b, 0x1c, 0x93, 0x51, 0x4b, 0x27,
|
||||||
|
0x3e, 0xe6, 0x43, 0x9d, 0xd4, 0xda, 0xa2, 0x96
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x89, 0x14, 0xb6, 0x39, 0x26, 0xa2, 0x96, 0x4e,
|
/* K2 */
|
||||||
0x7d, 0xcc, 0x87, 0x3b, 0xa9, 0xb5, 0x45, 0x2c
|
0x89, 0x14, 0xb6, 0x39, 0x26, 0xa2, 0x96, 0x4e,
|
||||||
|
0x7d, 0xcc, 0x87, 0x3b, 0xa9, 0xb5, 0x45, 0x2c
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_192_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
|
/* Example #1 */
|
||||||
0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
|
0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
|
||||||
|
0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
|
/* Example #2 */
|
||||||
0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
|
0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
|
||||||
|
0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
|
/* Example #3 */
|
||||||
0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e
|
0x3d, 0x75, 0xc1, 0x94, 0xed, 0x96, 0x07, 0x04,
|
||||||
|
0x44, 0xa9, 0xfa, 0x7e, 0xc7, 0x40, 0xec, 0xf8
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
|
/* Example #4 */
|
||||||
0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
|
0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
|
||||||
|
0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* AES 256 CMAC Test Data */
|
/* CMAC-AES256 Test Data */
|
||||||
static const unsigned char aes_256_key[32] = {
|
static const unsigned char aes_256_key[32] = {
|
||||||
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
|
0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
|
||||||
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
|
0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
|
||||||
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
|
0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
|
||||||
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
|
0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4
|
||||||
};
|
};
|
||||||
static const unsigned char aes_256_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_256_subkeys[2][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac,
|
/* K1 */
|
||||||
0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f
|
0xca, 0xd1, 0xed, 0x03, 0x29, 0x9e, 0xed, 0xac,
|
||||||
|
0x2e, 0x9a, 0x99, 0x80, 0x86, 0x21, 0x50, 0x2f
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x95, 0xa3, 0xda, 0x06, 0x53, 0x3d, 0xdb, 0x58,
|
/* K2 */
|
||||||
0x5d, 0x35, 0x33, 0x01, 0x0c, 0x42, 0xa0, 0xd9
|
0x95, 0xa3, 0xda, 0x06, 0x53, 0x3d, 0xdb, 0x58,
|
||||||
|
0x5d, 0x35, 0x33, 0x01, 0x0c, 0x42, 0xa0, 0xd9
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_AES_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
|
/* Example #1 */
|
||||||
0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
|
0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
|
||||||
|
0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
|
/* Example #2 */
|
||||||
0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
|
0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
|
||||||
|
0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
|
/* Example #3 */
|
||||||
0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6
|
0x15, 0x67, 0x27, 0xdc, 0x08, 0x78, 0x94, 0x4a,
|
||||||
|
0x02, 0x3c, 0x1f, 0xe0, 0x3b, 0xad, 0x6d, 0x93
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
|
/* Example #4 */
|
||||||
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
|
0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
|
||||||
|
0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif /* MBEDTLS_AES_C */
|
#endif /* MBEDTLS_AES_C */
|
||||||
|
@ -612,66 +634,84 @@ static const unsigned char aes_256_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTL
|
||||||
/* Truncation point of message for 3DES CMAC tests */
|
/* Truncation point of message for 3DES CMAC tests */
|
||||||
static const unsigned int des3_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
static const unsigned int des3_message_lengths[NB_CMAC_TESTS_PER_KEY] = {
|
||||||
0,
|
0,
|
||||||
8,
|
16,
|
||||||
20,
|
20,
|
||||||
32
|
32
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 3DES 2 Key CMAC Test Data */
|
/* CMAC-TDES (Generation) - 2 Key Test Data */
|
||||||
static const unsigned char des3_2key_key[24] = {
|
static const unsigned char des3_2key_key[24] = {
|
||||||
0x4c, 0xf1, 0x51, 0x34, 0xa2, 0x85, 0x0d, 0xd5,
|
/* Key1 */
|
||||||
0x8a, 0x3d, 0x10, 0xba, 0x80, 0x57, 0x0d, 0x38,
|
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
||||||
0x4c, 0xf1, 0x51, 0x34, 0xa2, 0x85, 0x0d, 0xd5
|
/* Key2 */
|
||||||
|
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xEF, 0x01,
|
||||||
|
/* Key3 */
|
||||||
|
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
|
||||||
};
|
};
|
||||||
static const unsigned char des3_2key_subkeys[2][8] = {
|
static const unsigned char des3_2key_subkeys[2][8] = {
|
||||||
{
|
{
|
||||||
0x8e, 0xcf, 0x37, 0x3e, 0xd7, 0x1a, 0xfa, 0xef
|
/* K1 */
|
||||||
|
0x0d, 0xd2, 0xcb, 0x7a, 0x3d, 0x88, 0x88, 0xd9
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x1d, 0x9e, 0x6e, 0x7d, 0xae, 0x35, 0xf5, 0xc5
|
/* K2 */
|
||||||
|
0x1b, 0xa5, 0x96, 0xf4, 0x7b, 0x11, 0x11, 0xb2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static const unsigned char des3_2key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
static const unsigned char des3_2key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xbd, 0x2e, 0xbf, 0x9a, 0x3b, 0xa0, 0x03, 0x61
|
/* Sample #1 */
|
||||||
|
0x79, 0xce, 0x52, 0xa7, 0xf7, 0x86, 0xa9, 0x60
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x4f, 0xf2, 0xab, 0x81, 0x3c, 0x53, 0xce, 0x83
|
/* Sample #2 */
|
||||||
|
0xcc, 0x18, 0xa0, 0xb7, 0x9a, 0xf2, 0x41, 0x3b
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x62, 0xdd, 0x1b, 0x47, 0x19, 0x02, 0xbd, 0x4e
|
/* Sample #3 */
|
||||||
|
0xc0, 0x6d, 0x37, 0x7e, 0xcd, 0x10, 0x19, 0x69
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x31, 0xb1, 0xe4, 0x31, 0xda, 0xbc, 0x4e, 0xb8
|
/* Sample #4 */
|
||||||
|
0x9c, 0xd3, 0x35, 0x80, 0xf9, 0xb6, 0x4d, 0xfb
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* 3DES 3 Key CMAC Test Data */
|
/* CMAC-TDES (Generation) - 3 Key Test Data */
|
||||||
static const unsigned char des3_3key_key[24] = {
|
static const unsigned char des3_3key_key[24] = {
|
||||||
0x8a, 0xa8, 0x3b, 0xf8, 0xcb, 0xda, 0x10, 0x62,
|
/* Key1 */
|
||||||
0x0b, 0xc1, 0xbf, 0x19, 0xfb, 0xb6, 0xcd, 0x58,
|
0x01, 0x23, 0x45, 0x67, 0x89, 0xaa, 0xcd, 0xef,
|
||||||
0xbc, 0x31, 0x3d, 0x4a, 0x37, 0x1c, 0xa8, 0xb5
|
/* Key2 */
|
||||||
|
0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01,
|
||||||
|
/* Key3 */
|
||||||
|
0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0x01, 0x23
|
||||||
};
|
};
|
||||||
static const unsigned char des3_3key_subkeys[2][8] = {
|
static const unsigned char des3_3key_subkeys[2][8] = {
|
||||||
{
|
{
|
||||||
0x91, 0x98, 0xe9, 0xd3, 0x14, 0xe6, 0x53, 0x5f
|
/* K1 */
|
||||||
|
0x9d, 0x74, 0xe7, 0x39, 0x33, 0x17, 0x96, 0xc0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x23, 0x31, 0xd3, 0xa6, 0x29, 0xcc, 0xa6, 0xa5
|
/* K2 */
|
||||||
|
0x3a, 0xe9, 0xce, 0x72, 0x66, 0x2f, 0x2d, 0x9b
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][MBEDTLS_DES3_BLOCK_SIZE] = {
|
||||||
{
|
{
|
||||||
0xb7, 0xa6, 0x88, 0xe1, 0x22, 0xff, 0xaf, 0x95
|
/* Sample #1 */
|
||||||
|
0x7d, 0xb0, 0xd3, 0x7d, 0xf9, 0x36, 0xc5, 0x50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x8e, 0x8f, 0x29, 0x31, 0x36, 0x28, 0x37, 0x97
|
/* Sample #2 */
|
||||||
|
0x30, 0x23, 0x9c, 0xf1, 0xf5, 0x2e, 0x66, 0x09
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x74, 0x3d, 0xdb, 0xe0, 0xce, 0x2d, 0xc2, 0xed
|
/* Sample #3 */
|
||||||
|
0x6c, 0x9f, 0x3e, 0xe4, 0x92, 0x3f, 0x6b, 0xe2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x33, 0xe6, 0xb1, 0x09, 0x24, 0x00, 0xea, 0xe5
|
/* Sample #4 */
|
||||||
|
0x99, 0x42, 0x9b, 0xd0, 0xbF, 0x79, 0x04, 0xe5
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -680,8 +720,9 @@ static const unsigned char des3_3key_expected_result[NB_CMAC_TESTS_PER_KEY][MBED
|
||||||
#if defined(MBEDTLS_AES_C)
|
#if defined(MBEDTLS_AES_C)
|
||||||
/* AES AES-CMAC-PRF-128 Test Data */
|
/* AES AES-CMAC-PRF-128 Test Data */
|
||||||
static const unsigned char PRFK[] = {
|
static const unsigned char PRFK[] = {
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
/* Key */
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||||
0xed, 0xcb
|
0xed, 0xcb
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -692,25 +733,25 @@ static const size_t PRFKlen[NB_PRF_TESTS] = {
|
||||||
10
|
10
|
||||||
};
|
};
|
||||||
|
|
||||||
/* PRF M */
|
/* Message */
|
||||||
static const unsigned char PRFM[] = {
|
static const unsigned char PRFM[] = {
|
||||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||||
0x10, 0x11, 0x12, 0x13
|
0x10, 0x11, 0x12, 0x13
|
||||||
};
|
};
|
||||||
|
|
||||||
static const unsigned char PRFT[NB_PRF_TESTS][16] = {
|
static const unsigned char PRFT[NB_PRF_TESTS][16] = {
|
||||||
{
|
{
|
||||||
0x84, 0xa3, 0x48, 0xa4, 0xa4, 0x5d, 0x23, 0x5b,
|
0x84, 0xa3, 0x48, 0xa4, 0xa4, 0x5d, 0x23, 0x5b,
|
||||||
0xab, 0xff, 0xfc, 0x0d, 0x2b, 0x4d, 0xa0, 0x9a
|
0xab, 0xff, 0xfc, 0x0d, 0x2b, 0x4d, 0xa0, 0x9a
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x98, 0x0a, 0xe8, 0x7b, 0x5f, 0x4c, 0x9c, 0x52,
|
0x98, 0x0a, 0xe8, 0x7b, 0x5f, 0x4c, 0x9c, 0x52,
|
||||||
0x14, 0xf5, 0xb6, 0xa8, 0x45, 0x5e, 0x4c, 0x2d
|
0x14, 0xf5, 0xb6, 0xa8, 0x45, 0x5e, 0x4c, 0x2d
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x29, 0x0d, 0x9e, 0x11, 0x2e, 0xdb, 0x09, 0xee,
|
0x29, 0x0d, 0x9e, 0x11, 0x2e, 0xdb, 0x09, 0xee,
|
||||||
0x14, 0x1f, 0xcf, 0x64, 0xc0, 0xb7, 0x2f, 0x3d
|
0x14, 0x1f, 0xcf, 0x64, 0xc0, 0xb7, 0x2f, 0x3d
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif /* MBEDTLS_AES_C */
|
#endif /* MBEDTLS_AES_C */
|
||||||
|
|
|
@ -290,7 +290,8 @@ int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx,
|
||||||
unsigned char seed[MBEDTLS_CTR_DRBG_MAX_SEED_INPUT];
|
unsigned char seed[MBEDTLS_CTR_DRBG_MAX_SEED_INPUT];
|
||||||
size_t seedlen = 0;
|
size_t seedlen = 0;
|
||||||
|
|
||||||
if( ctx->entropy_len + len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT )
|
if( ctx->entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ||
|
||||||
|
len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len )
|
||||||
return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
|
return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG );
|
||||||
|
|
||||||
memset( seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT );
|
memset( seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT );
|
||||||
|
|
|
@ -71,7 +71,7 @@ static inline void debug_send_line( const mbedtls_ssl_context *ssl, int level,
|
||||||
*/
|
*/
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
|
char idstr[20 + DEBUG_BUF_SIZE]; /* 0x + 16 nibbles + ': ' */
|
||||||
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", ssl, str );
|
mbedtls_snprintf( idstr, sizeof( idstr ), "%p: %s", (void*)ssl, str );
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
|
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, idstr );
|
||||||
#else
|
#else
|
||||||
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
ssl->conf->f_dbg( ssl->conf->p_dbg, level, file, line, str );
|
||||||
|
|
|
@ -1213,7 +1213,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t
|
||||||
int ret;
|
int ret;
|
||||||
size_t i;
|
size_t i;
|
||||||
mbedtls_mpi M, R;
|
mbedtls_mpi M, R;
|
||||||
mbedtls_mpi_uint Mp[P_KOBLITZ_MAX + P_KOBLITZ_R];
|
mbedtls_mpi_uint Mp[P_KOBLITZ_MAX + P_KOBLITZ_R + 1];
|
||||||
|
|
||||||
if( N->n < p_limbs )
|
if( N->n < p_limbs )
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -1235,7 +1235,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t
|
||||||
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
|
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
|
||||||
if( shift != 0 )
|
if( shift != 0 )
|
||||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
|
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
|
||||||
M.n += R.n - adjust; /* Make room for multiplication by R */
|
M.n += R.n; /* Make room for multiplication by R */
|
||||||
|
|
||||||
/* N = A0 */
|
/* N = A0 */
|
||||||
if( mask != 0 )
|
if( mask != 0 )
|
||||||
|
@ -1257,7 +1257,7 @@ static inline int ecp_mod_koblitz( mbedtls_mpi *N, mbedtls_mpi_uint *Rp, size_t
|
||||||
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
|
memcpy( Mp, N->p + p_limbs - adjust, M.n * sizeof( mbedtls_mpi_uint ) );
|
||||||
if( shift != 0 )
|
if( shift != 0 )
|
||||||
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
|
MBEDTLS_MPI_CHK( mbedtls_mpi_shift_r( &M, shift ) );
|
||||||
M.n += R.n - adjust; /* Make room for multiplication by R */
|
M.n += R.n; /* Make room for multiplication by R */
|
||||||
|
|
||||||
/* N = A0 */
|
/* N = A0 */
|
||||||
if( mask != 0 )
|
if( mask != 0 )
|
||||||
|
|
|
@ -158,7 +158,7 @@ void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, s
|
||||||
|
|
||||||
while( ilen > 0 )
|
while( ilen > 0 )
|
||||||
{
|
{
|
||||||
if( ctx->left + ilen > 16 )
|
if( ilen > 16 - ctx->left )
|
||||||
fill = 16 - ctx->left;
|
fill = 16 - ctx->left;
|
||||||
else
|
else
|
||||||
fill = ilen;
|
fill = ilen;
|
||||||
|
|
|
@ -133,7 +133,8 @@ void mbedtls_net_init( mbedtls_net_context *ctx )
|
||||||
/*
|
/*
|
||||||
* Initiate a TCP connection with host:port and the given protocol
|
* Initiate a TCP connection with host:port and the given protocol
|
||||||
*/
|
*/
|
||||||
int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host, const char *port, int proto )
|
int mbedtls_net_connect( mbedtls_net_context *ctx, const char *host,
|
||||||
|
const char *port, int proto )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct addrinfo hints, *addr_list, *cur;
|
struct addrinfo hints, *addr_list, *cur;
|
||||||
|
@ -238,7 +239,7 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* I we ever get there, it's a success */
|
/* Bind was successful */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -322,7 +323,7 @@ int mbedtls_net_accept( mbedtls_net_context *bind_ctx,
|
||||||
{
|
{
|
||||||
/* TCP: actual accept() */
|
/* TCP: actual accept() */
|
||||||
ret = client_ctx->fd = (int) accept( bind_ctx->fd,
|
ret = client_ctx->fd = (int) accept( bind_ctx->fd,
|
||||||
(struct sockaddr *) &client_addr, &n );
|
(struct sockaddr *) &client_addr, &n );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,12 +44,12 @@
|
||||||
#define mbedtls_free free
|
#define mbedtls_free free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||||
/* Implementation that should never be optimized out by the compiler */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
|
||||||
void mbedtls_pem_init( mbedtls_pem_context *ctx )
|
void mbedtls_pem_init( mbedtls_pem_context *ctx )
|
||||||
{
|
{
|
||||||
memset( ctx, 0, sizeof( mbedtls_pem_context ) );
|
memset( ctx, 0, sizeof( mbedtls_pem_context ) );
|
||||||
|
@ -249,7 +249,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||||
|
|
||||||
enc = 0;
|
enc = 0;
|
||||||
|
|
||||||
if( memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 )
|
if( s2 - s1 >= 22 && memcmp( s1, "Proc-Type: 4,ENCRYPTED", 22 ) == 0 )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
#if defined(MBEDTLS_MD5_C) && defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
||||||
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
( defined(MBEDTLS_DES_C) || defined(MBEDTLS_AES_C) )
|
||||||
|
@ -262,22 +262,22 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_DES_C)
|
#if defined(MBEDTLS_DES_C)
|
||||||
if( memcmp( s1, "DEK-Info: DES-EDE3-CBC,", 23 ) == 0 )
|
if( s2 - s1 >= 23 && memcmp( s1, "DEK-Info: DES-EDE3-CBC,", 23 ) == 0 )
|
||||||
{
|
{
|
||||||
enc_alg = MBEDTLS_CIPHER_DES_EDE3_CBC;
|
enc_alg = MBEDTLS_CIPHER_DES_EDE3_CBC;
|
||||||
|
|
||||||
s1 += 23;
|
s1 += 23;
|
||||||
if( pem_get_iv( s1, pem_iv, 8 ) != 0 )
|
if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8 ) != 0 )
|
||||||
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
||||||
|
|
||||||
s1 += 16;
|
s1 += 16;
|
||||||
}
|
}
|
||||||
else if( memcmp( s1, "DEK-Info: DES-CBC,", 18 ) == 0 )
|
else if( s2 - s1 >= 18 && memcmp( s1, "DEK-Info: DES-CBC,", 18 ) == 0 )
|
||||||
{
|
{
|
||||||
enc_alg = MBEDTLS_CIPHER_DES_CBC;
|
enc_alg = MBEDTLS_CIPHER_DES_CBC;
|
||||||
|
|
||||||
s1 += 18;
|
s1 += 18;
|
||||||
if( pem_get_iv( s1, pem_iv, 8) != 0 )
|
if( s2 - s1 < 16 || pem_get_iv( s1, pem_iv, 8) != 0 )
|
||||||
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
||||||
|
|
||||||
s1 += 16;
|
s1 += 16;
|
||||||
|
@ -285,9 +285,11 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||||
#endif /* MBEDTLS_DES_C */
|
#endif /* MBEDTLS_DES_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_AES_C)
|
#if defined(MBEDTLS_AES_C)
|
||||||
if( memcmp( s1, "DEK-Info: AES-", 14 ) == 0 )
|
if( s2 - s1 >= 14 && memcmp( s1, "DEK-Info: AES-", 14 ) == 0 )
|
||||||
{
|
{
|
||||||
if( memcmp( s1, "DEK-Info: AES-128-CBC,", 22 ) == 0 )
|
if( s2 - s1 < 22 )
|
||||||
|
return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG );
|
||||||
|
else if( memcmp( s1, "DEK-Info: AES-128-CBC,", 22 ) == 0 )
|
||||||
enc_alg = MBEDTLS_CIPHER_AES_128_CBC;
|
enc_alg = MBEDTLS_CIPHER_AES_128_CBC;
|
||||||
else if( memcmp( s1, "DEK-Info: AES-192-CBC,", 22 ) == 0 )
|
else if( memcmp( s1, "DEK-Info: AES-192-CBC,", 22 ) == 0 )
|
||||||
enc_alg = MBEDTLS_CIPHER_AES_192_CBC;
|
enc_alg = MBEDTLS_CIPHER_AES_192_CBC;
|
||||||
|
@ -297,7 +299,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||||
return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG );
|
return( MBEDTLS_ERR_PEM_UNKNOWN_ENC_ALG );
|
||||||
|
|
||||||
s1 += 22;
|
s1 += 22;
|
||||||
if( pem_get_iv( s1, pem_iv, 16 ) != 0 )
|
if( s2 - s1 < 32 || pem_get_iv( s1, pem_iv, 16 ) != 0 )
|
||||||
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
return( MBEDTLS_ERR_PEM_INVALID_ENC_IV );
|
||||||
|
|
||||||
s1 += 32;
|
s1 += 32;
|
||||||
|
@ -316,7 +318,7 @@ int mbedtls_pem_read_buffer( mbedtls_pem_context *ctx, const char *header, const
|
||||||
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
( MBEDTLS_AES_C || MBEDTLS_DES_C ) */
|
||||||
}
|
}
|
||||||
|
|
||||||
if( s1 == s2 )
|
if( s1 >= s2 )
|
||||||
return( MBEDTLS_ERR_PEM_INVALID_DATA );
|
return( MBEDTLS_ERR_PEM_INVALID_DATA );
|
||||||
|
|
||||||
ret = mbedtls_base64_decode( NULL, 0, &len, s1, s2 - s1 );
|
ret = mbedtls_base64_decode( NULL, 0, &len, s1, s2 - s1 );
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include "mbedtls/pk.h"
|
#include "mbedtls/pk.h"
|
||||||
#include "mbedtls/pk_internal.h"
|
#include "mbedtls/pk_internal.h"
|
||||||
|
|
||||||
|
#include "mbedtls/bignum.h"
|
||||||
|
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
#include "mbedtls/rsa.h"
|
#include "mbedtls/rsa.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,6 +41,8 @@
|
||||||
#include "mbedtls/ecdsa.h"
|
#include "mbedtls/ecdsa.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
/* Implementation that should never be optimized out by the compiler */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||||
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
volatile unsigned char *p = v; while( n-- ) *p++ = 0;
|
||||||
|
@ -209,6 +213,11 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
|
||||||
int ret;
|
int ret;
|
||||||
const mbedtls_pk_rsassa_pss_options *pss_opts;
|
const mbedtls_pk_rsassa_pss_options *pss_opts;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVE_INT64)
|
||||||
|
if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len )
|
||||||
|
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||||
|
#endif /* MBEDTLS_HAVE_INT64 */
|
||||||
|
|
||||||
if( options == NULL )
|
if( options == NULL )
|
||||||
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
@ -232,7 +241,7 @@ int mbedtls_pk_verify_ext( mbedtls_pk_type_t type, const void *options,
|
||||||
return( 0 );
|
return( 0 );
|
||||||
#else
|
#else
|
||||||
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE );
|
||||||
#endif
|
#endif /* MBEDTLS_RSA_C && MBEDTLS_PKCS1_V21 */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* General case: no options */
|
/* General case: no options */
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
/* Even if RSA not activated, for the sake of RSA-alt */
|
/* Even if RSA not activated, for the sake of RSA-alt */
|
||||||
#include "mbedtls/rsa.h"
|
#include "mbedtls/rsa.h"
|
||||||
|
#include "mbedtls/bignum.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -49,6 +50,8 @@
|
||||||
#define mbedtls_free free
|
#define mbedtls_free free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
||||||
/* Implementation that should never be optimized out by the compiler */
|
/* Implementation that should never be optimized out by the compiler */
|
||||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||||
|
@ -74,6 +77,11 @@ static int rsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVE_INT64)
|
||||||
|
if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len )
|
||||||
|
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||||
|
#endif /* MBEDTLS_HAVE_INT64 */
|
||||||
|
|
||||||
if( sig_len < ((mbedtls_rsa_context *) ctx)->len )
|
if( sig_len < ((mbedtls_rsa_context *) ctx)->len )
|
||||||
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
|
return( MBEDTLS_ERR_RSA_VERIFY_FAILED );
|
||||||
|
|
||||||
|
@ -93,6 +101,11 @@ static int rsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||||
unsigned char *sig, size_t *sig_len,
|
unsigned char *sig, size_t *sig_len,
|
||||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
|
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
|
||||||
{
|
{
|
||||||
|
#if defined(MBEDTLS_HAVE_INT64)
|
||||||
|
if( md_alg == MBEDTLS_MD_NONE && UINT_MAX < hash_len )
|
||||||
|
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||||
|
#endif /* MBEDTLS_HAVE_INT64 */
|
||||||
|
|
||||||
*sig_len = ((mbedtls_rsa_context *) ctx)->len;
|
*sig_len = ((mbedtls_rsa_context *) ctx)->len;
|
||||||
|
|
||||||
return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
|
return( mbedtls_rsa_pkcs1_sign( (mbedtls_rsa_context *) ctx, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
|
||||||
|
@ -402,6 +415,11 @@ static int rsa_alt_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||||
{
|
{
|
||||||
mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx;
|
mbedtls_rsa_alt_context *rsa_alt = (mbedtls_rsa_alt_context *) ctx;
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_HAVE_INT64)
|
||||||
|
if( UINT_MAX < hash_len )
|
||||||
|
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||||
|
#endif /* MBEDTLS_HAVE_INT64 */
|
||||||
|
|
||||||
*sig_len = rsa_alt->key_len_func( rsa_alt->key );
|
*sig_len = rsa_alt->key_len_func( rsa_alt->key );
|
||||||
|
|
||||||
return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
|
return( rsa_alt->sign_func( rsa_alt->key, f_rng, p_rng, MBEDTLS_RSA_PRIVATE,
|
||||||
|
|
|
@ -1187,12 +1187,12 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
|
||||||
#endif /* MBEDTLS_PEM_PARSE_C */
|
#endif /* MBEDTLS_PEM_PARSE_C */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At this point we only know it's not a PEM formatted key. Could be any
|
* At this point we only know it's not a PEM formatted key. Could be any
|
||||||
* of the known DER encoded private key formats
|
* of the known DER encoded private key formats
|
||||||
*
|
*
|
||||||
* We try the different DER format parsers to see if one passes without
|
* We try the different DER format parsers to see if one passes without
|
||||||
* error
|
* error
|
||||||
*/
|
*/
|
||||||
#if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
|
#if defined(MBEDTLS_PKCS12_C) || defined(MBEDTLS_PKCS5_C)
|
||||||
if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, key, keylen,
|
if( ( ret = pk_parse_key_pkcs8_encrypted_der( pk, key, keylen,
|
||||||
pwd, pwdlen ) ) == 0 )
|
pwd, pwdlen ) ) == 0 )
|
||||||
|
|
|
@ -237,7 +237,7 @@ int mbedtls_platform_std_nv_seed_read( unsigned char *buf, size_t buf_len )
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( file );
|
fclose( file );
|
||||||
return( n );
|
return( (int)n );
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
|
int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
|
||||||
|
@ -255,7 +255,7 @@ int mbedtls_platform_std_nv_seed_write( unsigned char *buf, size_t buf_len )
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose( file );
|
fclose( file );
|
||||||
return( n );
|
return( (int)n );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
#endif /* MBEDTLS_PLATFORM_NO_STD_FUNCTIONS */
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ void mbedtls_ssl_cookie_free( mbedtls_ssl_cookie_ctx *ctx )
|
||||||
mbedtls_md_free( &ctx->hmac_ctx );
|
mbedtls_md_free( &ctx->hmac_ctx );
|
||||||
|
|
||||||
#if defined(MBEDTLS_THREADING_C)
|
#if defined(MBEDTLS_THREADING_C)
|
||||||
mbedtls_mutex_init( &ctx->mutex );
|
mbedtls_mutex_free( &ctx->mutex );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mbedtls_zeroize( ctx, sizeof( mbedtls_ssl_cookie_ctx ) );
|
mbedtls_zeroize( ctx, sizeof( mbedtls_ssl_cookie_ctx ) );
|
||||||
|
|
|
@ -3428,7 +3428,7 @@ static int ssl_handle_possible_reconnect( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED )
|
if( ret == MBEDTLS_ERR_SSL_HELLO_VERIFY_REQUIRED )
|
||||||
{
|
{
|
||||||
/* Dont check write errors as we can't do anything here.
|
/* Don't check write errors as we can't do anything here.
|
||||||
* If the error is permanent we'll catch it later,
|
* If the error is permanent we'll catch it later,
|
||||||
* if it's not, then hopefully it'll work next time. */
|
* if it's not, then hopefully it'll work next time. */
|
||||||
(void) ssl->f_send( ssl->p_bio, ssl->out_buf, len );
|
(void) ssl->f_send( ssl->p_bio, ssl->out_buf, len );
|
||||||
|
@ -6006,8 +6006,9 @@ int mbedtls_ssl_conf_alpn_protocols( mbedtls_ssl_config *conf, const char **prot
|
||||||
const char **p;
|
const char **p;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "Empty strings MUST NOT be included and byte strings MUST NOT be
|
* RFC 7301 3.1: "Empty strings MUST NOT be included and byte strings
|
||||||
* truncated". Check lengths now rather than later.
|
* MUST NOT be truncated."
|
||||||
|
* We check lengths now rather than later.
|
||||||
*/
|
*/
|
||||||
tot_len = 0;
|
tot_len = 0;
|
||||||
for( p = protos; *p != NULL; p++ )
|
for( p = protos; *p != NULL; p++ )
|
||||||
|
@ -6481,6 +6482,10 @@ int mbedtls_ssl_renegotiate( mbedtls_ssl_context *ssl )
|
||||||
*/
|
*/
|
||||||
static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl )
|
static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
|
size_t ep_len = ssl_ep_len( ssl );
|
||||||
|
int in_ctr_cmp;
|
||||||
|
int out_ctr_cmp;
|
||||||
|
|
||||||
if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ||
|
if( ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER ||
|
||||||
ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING ||
|
ssl->renego_status == MBEDTLS_SSL_RENEGOTIATION_PENDING ||
|
||||||
ssl->conf->disable_renegotiation == MBEDTLS_SSL_RENEGOTIATION_DISABLED )
|
ssl->conf->disable_renegotiation == MBEDTLS_SSL_RENEGOTIATION_DISABLED )
|
||||||
|
@ -6488,8 +6493,12 @@ static int ssl_check_ctr_renegotiate( mbedtls_ssl_context *ssl )
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( memcmp( ssl->in_ctr, ssl->conf->renego_period, 8 ) <= 0 &&
|
in_ctr_cmp = memcmp( ssl->in_ctr + ep_len,
|
||||||
memcmp( ssl->out_ctr, ssl->conf->renego_period, 8 ) <= 0 )
|
ssl->conf->renego_period + ep_len, 8 - ep_len );
|
||||||
|
out_ctr_cmp = memcmp( ssl->out_ctr + ep_len,
|
||||||
|
ssl->conf->renego_period + ep_len, 8 - ep_len );
|
||||||
|
|
||||||
|
if( in_ctr_cmp <= 0 && out_ctr_cmp <= 0 )
|
||||||
{
|
{
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
@ -7230,8 +7239,8 @@ int mbedtls_ssl_config_defaults( mbedtls_ssl_config *conf,
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
||||||
conf->renego_max_records = MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT;
|
conf->renego_max_records = MBEDTLS_SSL_RENEGO_MAX_RECORDS_DEFAULT;
|
||||||
memset( conf->renego_period, 0xFF, 7 );
|
memset( conf->renego_period, 0x00, 2 );
|
||||||
conf->renego_period[7] = 0x00;
|
memset( conf->renego_period + 2, 0xFF, 6 );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
|
#if defined(MBEDTLS_DHM_C) && defined(MBEDTLS_SSL_SRV_C)
|
||||||
|
@ -7585,7 +7594,7 @@ int mbedtls_ssl_check_cert_usage( const mbedtls_x509_crt *cert,
|
||||||
* and, for DTLS, to/from TLS equivalent.
|
* and, for DTLS, to/from TLS equivalent.
|
||||||
*
|
*
|
||||||
* For TLS this is the identity.
|
* For TLS this is the identity.
|
||||||
* For DTLS, use one complement (v -> 255 - v, and then map as follows:
|
* For DTLS, use 1's complement (v -> 255 - v, and then map as follows:
|
||||||
* 1.0 <-> 3.2 (DTLS 1.0 is based on TLS 1.1)
|
* 1.0 <-> 3.2 (DTLS 1.0 is based on TLS 1.1)
|
||||||
* 1.x <-> 3.x+1 for x != 0 (DTLS 1.2 based on TLS 1.2)
|
* 1.x <-> 3.x+1 for x != 0 (DTLS 1.2 based on TLS 1.2)
|
||||||
*/
|
*/
|
||||||
|
@ -7644,8 +7653,7 @@ int mbedtls_ssl_set_calc_verify_md( mbedtls_ssl_context *ssl, int md )
|
||||||
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
#if defined(MBEDTLS_SSL_PROTO_TLS1) || defined(MBEDTLS_SSL_PROTO_TLS1_1)
|
||||||
#if defined(MBEDTLS_MD5_C)
|
#if defined(MBEDTLS_MD5_C)
|
||||||
case MBEDTLS_SSL_HASH_MD5:
|
case MBEDTLS_SSL_HASH_MD5:
|
||||||
ssl->handshake->calc_verify = ssl_calc_verify_tls;
|
return MBEDTLS_ERR_SSL_INVALID_VERIFY_HASH;
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#if defined(MBEDTLS_SHA1_C)
|
#if defined(MBEDTLS_SHA1_C)
|
||||||
case MBEDTLS_SSL_HASH_SHA1:
|
case MBEDTLS_SSL_HASH_SHA1:
|
||||||
|
|
|
@ -480,14 +480,20 @@ int mbedtls_x509_get_name( unsigned char **p, const unsigned char *end,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x509_parse_int(unsigned char **p, unsigned n, int *res){
|
static int x509_parse_int( unsigned char **p, size_t n, int *res )
|
||||||
|
{
|
||||||
*res = 0;
|
*res = 0;
|
||||||
for( ; n > 0; --n ){
|
|
||||||
if( ( **p < '0') || ( **p > '9' ) ) return MBEDTLS_ERR_X509_INVALID_DATE;
|
for( ; n > 0; --n )
|
||||||
|
{
|
||||||
|
if( ( **p < '0') || ( **p > '9' ) )
|
||||||
|
return ( MBEDTLS_ERR_X509_INVALID_DATE );
|
||||||
|
|
||||||
*res *= 10;
|
*res *= 10;
|
||||||
*res += (*(*p)++ - '0');
|
*res += ( *(*p)++ - '0' );
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x509_date_is_valid(const mbedtls_x509_time *time)
|
static int x509_date_is_valid(const mbedtls_x509_time *time)
|
||||||
|
@ -517,6 +523,70 @@ static int x509_date_is_valid(const mbedtls_x509_time *time)
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse an ASN1_UTC_TIME (yearlen=2) or ASN1_GENERALIZED_TIME (yearlen=4)
|
||||||
|
* field.
|
||||||
|
*/
|
||||||
|
static int x509_parse_time( unsigned char **p, size_t len, size_t yearlen,
|
||||||
|
mbedtls_x509_time *time )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Minimum length is 10 or 12 depending on yearlen
|
||||||
|
*/
|
||||||
|
if ( len < yearlen + 8 )
|
||||||
|
return ( MBEDTLS_ERR_X509_INVALID_DATE );
|
||||||
|
len -= yearlen + 8;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse year, month, day, hour, minute
|
||||||
|
*/
|
||||||
|
CHECK( x509_parse_int( p, yearlen, &time->year ) );
|
||||||
|
if ( 2 == yearlen )
|
||||||
|
{
|
||||||
|
if ( time->year < 50 )
|
||||||
|
time->year += 100;
|
||||||
|
|
||||||
|
time->year += 1900;
|
||||||
|
}
|
||||||
|
|
||||||
|
CHECK( x509_parse_int( p, 2, &time->mon ) );
|
||||||
|
CHECK( x509_parse_int( p, 2, &time->day ) );
|
||||||
|
CHECK( x509_parse_int( p, 2, &time->hour ) );
|
||||||
|
CHECK( x509_parse_int( p, 2, &time->min ) );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse seconds if present
|
||||||
|
*/
|
||||||
|
if ( len >= 2 )
|
||||||
|
{
|
||||||
|
CHECK( x509_parse_int( p, 2, &time->sec ) );
|
||||||
|
len -= 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return ( MBEDTLS_ERR_X509_INVALID_DATE );
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse trailing 'Z' if present
|
||||||
|
*/
|
||||||
|
if ( 1 == len && 'Z' == **p )
|
||||||
|
{
|
||||||
|
(*p)++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We should have parsed all characters at this point
|
||||||
|
*/
|
||||||
|
if ( 0 != len )
|
||||||
|
return ( MBEDTLS_ERR_X509_INVALID_DATE );
|
||||||
|
|
||||||
|
CHECK( x509_date_is_valid( time ) );
|
||||||
|
|
||||||
|
return ( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Time ::= CHOICE {
|
* Time ::= CHOICE {
|
||||||
* utcTime UTCTime,
|
* utcTime UTCTime,
|
||||||
|
@ -526,7 +596,7 @@ int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
|
||||||
mbedtls_x509_time *time )
|
mbedtls_x509_time *time )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
size_t len;
|
size_t len, year_len;
|
||||||
unsigned char tag;
|
unsigned char tag;
|
||||||
|
|
||||||
if( ( end - *p ) < 1 )
|
if( ( end - *p ) < 1 )
|
||||||
|
@ -536,55 +606,20 @@ int mbedtls_x509_get_time( unsigned char **p, const unsigned char *end,
|
||||||
tag = **p;
|
tag = **p;
|
||||||
|
|
||||||
if( tag == MBEDTLS_ASN1_UTC_TIME )
|
if( tag == MBEDTLS_ASN1_UTC_TIME )
|
||||||
{
|
year_len = 2;
|
||||||
(*p)++;
|
|
||||||
ret = mbedtls_asn1_get_len( p, end, &len );
|
|
||||||
|
|
||||||
if( ret != 0 )
|
|
||||||
return( MBEDTLS_ERR_X509_INVALID_DATE + ret );
|
|
||||||
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->year ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->mon ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->day ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->hour ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->min ) );
|
|
||||||
if( len > 10 )
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->sec ) );
|
|
||||||
if( len > 12 && *(*p)++ != 'Z' )
|
|
||||||
return( MBEDTLS_ERR_X509_INVALID_DATE );
|
|
||||||
|
|
||||||
time->year += 100 * ( time->year < 50 );
|
|
||||||
time->year += 1900;
|
|
||||||
|
|
||||||
CHECK( x509_date_is_valid( time ) );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
else if( tag == MBEDTLS_ASN1_GENERALIZED_TIME )
|
else if( tag == MBEDTLS_ASN1_GENERALIZED_TIME )
|
||||||
{
|
year_len = 4;
|
||||||
(*p)++;
|
|
||||||
ret = mbedtls_asn1_get_len( p, end, &len );
|
|
||||||
|
|
||||||
if( ret != 0 )
|
|
||||||
return( MBEDTLS_ERR_X509_INVALID_DATE + ret );
|
|
||||||
|
|
||||||
CHECK( x509_parse_int( p, 4, &time->year ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->mon ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->day ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->hour ) );
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->min ) );
|
|
||||||
if( len > 12 )
|
|
||||||
CHECK( x509_parse_int( p, 2, &time->sec ) );
|
|
||||||
if( len > 14 && *(*p)++ != 'Z' )
|
|
||||||
return( MBEDTLS_ERR_X509_INVALID_DATE );
|
|
||||||
|
|
||||||
CHECK( x509_date_is_valid( time ) );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return( MBEDTLS_ERR_X509_INVALID_DATE +
|
return( MBEDTLS_ERR_X509_INVALID_DATE +
|
||||||
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||||
|
|
||||||
|
(*p)++;
|
||||||
|
ret = mbedtls_asn1_get_len( p, end, &len );
|
||||||
|
|
||||||
|
if( ret != 0 )
|
||||||
|
return( MBEDTLS_ERR_X509_INVALID_DATE + ret );
|
||||||
|
|
||||||
|
return x509_parse_time( p, len, year_len, time );
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig )
|
int mbedtls_x509_get_sig( unsigned char **p, const unsigned char *end, mbedtls_x509_buf *sig )
|
||||||
|
@ -661,7 +696,7 @@ int mbedtls_x509_get_sig_alg( const mbedtls_x509_buf *sig_oid, const mbedtls_x50
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* X.509 Extensions (No parsing of extensions, pointer should
|
* X.509 Extensions (No parsing of extensions, pointer should
|
||||||
* be either manually updated or extensions should be parsed!
|
* be either manually updated or extensions should be parsed!)
|
||||||
*/
|
*/
|
||||||
int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
|
int mbedtls_x509_get_ext( unsigned char **p, const unsigned char *end,
|
||||||
mbedtls_x509_buf *ext, int tag )
|
mbedtls_x509_buf *ext, int tag )
|
||||||
|
|
|
@ -525,16 +525,17 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s
|
||||||
if( ( ret = mbedtls_x509_crl_parse_der( chain,
|
if( ( ret = mbedtls_x509_crl_parse_der( chain,
|
||||||
pem.buf, pem.buflen ) ) != 0 )
|
pem.buf, pem.buflen ) ) != 0 )
|
||||||
{
|
{
|
||||||
|
mbedtls_pem_free( &pem );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_pem_free( &pem );
|
|
||||||
}
|
}
|
||||||
else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
|
else if( is_pem )
|
||||||
{
|
{
|
||||||
mbedtls_pem_free( &pem );
|
mbedtls_pem_free( &pem );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mbedtls_pem_free( &pem );
|
||||||
}
|
}
|
||||||
/* In the PEM case, buflen is 1 at the end, for the terminated NULL byte.
|
/* In the PEM case, buflen is 1 at the end, for the terminated NULL byte.
|
||||||
* And a valid CRL cannot be less than 1 byte anyway. */
|
* And a valid CRL cannot be less than 1 byte anyway. */
|
||||||
|
|
|
@ -969,8 +969,8 @@ int mbedtls_x509_crt_parse_der( mbedtls_x509_crt *chain, const unsigned char *bu
|
||||||
*/
|
*/
|
||||||
int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen )
|
int mbedtls_x509_crt_parse( mbedtls_x509_crt *chain, const unsigned char *buf, size_t buflen )
|
||||||
{
|
{
|
||||||
int success = 0, first_error = 0, total_failed = 0;
|
|
||||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||||
|
int success = 0, first_error = 0, total_failed = 0;
|
||||||
int buf_format = MBEDTLS_X509_FORMAT_DER;
|
int buf_format = MBEDTLS_X509_FORMAT_DER;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ int mbedtls_x509_crt_parse_path( mbedtls_x509_crt *chain, const char *path )
|
||||||
p = filename + len;
|
p = filename + len;
|
||||||
filename[len++] = '*';
|
filename[len++] = '*';
|
||||||
|
|
||||||
w_ret = MultiByteToWideChar( CP_ACP, 0, filename, len, szDir,
|
w_ret = MultiByteToWideChar( CP_ACP, 0, filename, (int)len, szDir,
|
||||||
MAX_PATH - 3 );
|
MAX_PATH - 3 );
|
||||||
if( w_ret == 0 )
|
if( w_ret == 0 )
|
||||||
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_X509_BAD_INPUT_DATA );
|
||||||
|
@ -1904,6 +1904,7 @@ static int x509_crt_verify_top(
|
||||||
int check_path_cnt;
|
int check_path_cnt;
|
||||||
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
unsigned char hash[MBEDTLS_MD_MAX_SIZE];
|
||||||
const mbedtls_md_info_t *md_info;
|
const mbedtls_md_info_t *md_info;
|
||||||
|
mbedtls_x509_crt *future_past_ca = NULL;
|
||||||
|
|
||||||
if( mbedtls_x509_time_is_past( &child->valid_to ) )
|
if( mbedtls_x509_time_is_past( &child->valid_to ) )
|
||||||
*flags |= MBEDTLS_X509_BADCERT_EXPIRED;
|
*flags |= MBEDTLS_X509_BADCERT_EXPIRED;
|
||||||
|
@ -1958,16 +1959,6 @@ static int x509_crt_verify_top(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( mbedtls_x509_time_is_past( &trust_ca->valid_to ) )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( mbedtls_x509_time_is_future( &trust_ca->valid_from ) )
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( mbedtls_pk_verify_ext( child->sig_pk, child->sig_opts, &trust_ca->pk,
|
if( mbedtls_pk_verify_ext( child->sig_pk, child->sig_opts, &trust_ca->pk,
|
||||||
child->sig_md, hash, mbedtls_md_get_size( md_info ),
|
child->sig_md, hash, mbedtls_md_get_size( md_info ),
|
||||||
child->sig.p, child->sig.len ) != 0 )
|
child->sig.p, child->sig.len ) != 0 )
|
||||||
|
@ -1975,6 +1966,20 @@ static int x509_crt_verify_top(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( mbedtls_x509_time_is_past( &trust_ca->valid_to ) ||
|
||||||
|
mbedtls_x509_time_is_future( &trust_ca->valid_from ) )
|
||||||
|
{
|
||||||
|
if ( future_past_ca == NULL )
|
||||||
|
future_past_ca = trust_ca;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( trust_ca != NULL || ( trust_ca = future_past_ca ) != NULL )
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* Top of chain is signed by a trusted CA
|
* Top of chain is signed by a trusted CA
|
||||||
*/
|
*/
|
||||||
|
@ -1982,8 +1987,6 @@ static int x509_crt_verify_top(
|
||||||
|
|
||||||
if( x509_profile_check_key( profile, child->sig_pk, &trust_ca->pk ) != 0 )
|
if( x509_profile_check_key( profile, child->sig_pk, &trust_ca->pk ) != 0 )
|
||||||
*flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
|
*flags |= MBEDTLS_X509_BADCERT_BAD_KEY;
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2003,6 +2006,12 @@ static int x509_crt_verify_top(
|
||||||
((void) ca_crl);
|
((void) ca_crl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if( mbedtls_x509_time_is_past( &trust_ca->valid_to ) )
|
||||||
|
ca_flags |= MBEDTLS_X509_BADCERT_EXPIRED;
|
||||||
|
|
||||||
|
if( mbedtls_x509_time_is_future( &trust_ca->valid_from ) )
|
||||||
|
ca_flags |= MBEDTLS_X509_BADCERT_FUTURE;
|
||||||
|
|
||||||
if( NULL != f_vrfy )
|
if( NULL != f_vrfy )
|
||||||
{
|
{
|
||||||
if( ( ret = f_vrfy( p_vrfy, trust_ca, path_cnt + 1,
|
if( ( ret = f_vrfy( p_vrfy, trust_ca, path_cnt + 1,
|
||||||
|
|
|
@ -265,8 +265,8 @@ int mbedtls_x509_csr_parse_der( mbedtls_x509_csr *csr,
|
||||||
*/
|
*/
|
||||||
int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen )
|
int mbedtls_x509_csr_parse( mbedtls_x509_csr *csr, const unsigned char *buf, size_t buflen )
|
||||||
{
|
{
|
||||||
int ret;
|
|
||||||
#if defined(MBEDTLS_PEM_PARSE_C)
|
#if defined(MBEDTLS_PEM_PARSE_C)
|
||||||
|
int ret;
|
||||||
size_t use_len;
|
size_t use_len;
|
||||||
mbedtls_pem_context pem;
|
mbedtls_pem_context pem;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,124 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
|
|
||||||
void led_blink(PinName led)
|
|
||||||
{
|
|
||||||
DigitalOut myled(led);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
myled = !myled;
|
|
||||||
wait(1.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify_completion(bool success)
|
|
||||||
{
|
|
||||||
if (success)
|
|
||||||
printf("{success}\n");
|
|
||||||
else
|
|
||||||
printf("{failure}\n");
|
|
||||||
|
|
||||||
printf("{end}\n");
|
|
||||||
led_blink(success ? LED1 : LED4);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TEST_STRING "Hello World!"
|
|
||||||
|
|
||||||
FILE *test_open(char *path, const char *mode)
|
|
||||||
{
|
|
||||||
FILE *f;
|
|
||||||
|
|
||||||
f = fopen(path, mode);
|
|
||||||
if (f == NULL) {
|
|
||||||
printf("Error opening file\n");
|
|
||||||
notify_completion(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_write(FILE *f, const char *str)
|
|
||||||
{
|
|
||||||
int n = fprintf(f, str);
|
|
||||||
|
|
||||||
if (n != strlen(str)) {
|
|
||||||
printf("Error writing file\n");
|
|
||||||
notify_completion(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_close(FILE *f)
|
|
||||||
{
|
|
||||||
int rc = fclose(f);
|
|
||||||
|
|
||||||
if (rc != 0) {
|
|
||||||
printf("Error closing file\n");
|
|
||||||
notify_completion(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DigitalOut led2(LED2);
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
#if defined(TARGET_KL25Z)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
|
||||||
#elif defined(TARGET_nRF51822)
|
|
||||||
//SDFileSystem sd(p20, p22, p25, p24, "sd");
|
|
||||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
|
||||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F070RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F091RC) || \
|
|
||||||
defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F303RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F410RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L073RZ) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
#elif defined(TARGET_LPC11U37H_401)
|
|
||||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_NUC472)
|
|
||||||
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_M453)
|
|
||||||
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
|
|
||||||
#else
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
#endif
|
|
||||||
led2 = 1;
|
|
||||||
wait(0.5);
|
|
||||||
FILE *f;
|
|
||||||
char *str = TEST_STRING;
|
|
||||||
char *buffer = (char *)malloc(sizeof(unsigned char) * strlen(TEST_STRING));
|
|
||||||
int str_len = strlen(TEST_STRING);
|
|
||||||
|
|
||||||
printf("Write files\n");
|
|
||||||
char filename[32];
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
sprintf(filename, "/sd/test_%d.txt", i);
|
|
||||||
printf("Creating file: %s\n", filename);
|
|
||||||
f = test_open(filename, "w");
|
|
||||||
led2 = 0;
|
|
||||||
test_write(f, str);
|
|
||||||
test_close(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("List files:\n");
|
|
||||||
DIR *d = opendir("/sd");
|
|
||||||
if (d == NULL) {
|
|
||||||
printf("Error opening directory\n");
|
|
||||||
notify_completion(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct dirent *p;
|
|
||||||
while ((p = readdir(d)) != NULL)
|
|
||||||
printf("%s\n", p->d_name);
|
|
||||||
closedir(d);
|
|
||||||
|
|
||||||
notify_completion(true);
|
|
||||||
}
|
|
|
@ -1,32 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "rtos.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
|
|
||||||
#define FILE_LOC "/sd/test.txt"
|
|
||||||
|
|
||||||
Serial pc(USBTX, USBRX);
|
|
||||||
Serial gps(p28, p27);
|
|
||||||
Serial test(p9,p10);
|
|
||||||
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
|
|
||||||
DigitalOut myled(LED1);
|
|
||||||
DigitalOut sdled(LED2);
|
|
||||||
|
|
||||||
void sd_thread(void const *argument) {
|
|
||||||
while (true) {
|
|
||||||
sdled = !sdled;
|
|
||||||
FILE *fp = NULL;
|
|
||||||
fp = fopen(FILE_LOC, "w");
|
|
||||||
if( fp != NULL ) fclose(fp);
|
|
||||||
Thread::wait(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
Thread sdTask(sd_thread, NULL, osPriorityNormal, DEFAULT_STACK_SIZE * 2.25);
|
|
||||||
while (true) {
|
|
||||||
myled = !myled;
|
|
||||||
Thread::wait(1000);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
#include "test_env.h"
|
|
||||||
|
|
||||||
#if defined(TARGET_KL25Z)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
|
|
||||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K22F)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K20D50M)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_nRF51822)
|
|
||||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F070RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F091RC) || \
|
|
||||||
defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F303RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F410RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L073RZ) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_DISCO_F051R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L031K6)
|
|
||||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC2368)
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U68)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC1549)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_RZ_A1H)
|
|
||||||
SDFileSystem sd(P8_5, P8_6, P8_3, P8_4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U37H_401)
|
|
||||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_NUC472)
|
|
||||||
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_M453)
|
|
||||||
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
|
|
||||||
|
|
||||||
#else
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
const char *sd_file_path = "/sd/out.txt";
|
|
||||||
const int DATA_SIZE = 256;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
MBED_HOSTTEST_TIMEOUT(15);
|
|
||||||
MBED_HOSTTEST_SELECT(default_auto);
|
|
||||||
MBED_HOSTTEST_DESCRIPTION(SD File System);
|
|
||||||
MBED_HOSTTEST_START("MBED_A12");
|
|
||||||
|
|
||||||
uint8_t data_written[DATA_SIZE] = { 0 };
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
// Fill data_written buffer with random data
|
|
||||||
// Write these data into the file
|
|
||||||
bool write_result = false;
|
|
||||||
{
|
|
||||||
printf("SD: Writing ... ");
|
|
||||||
FILE *f = fopen(sd_file_path, "w");
|
|
||||||
if (f) {
|
|
||||||
for (int i = 0; i < DATA_SIZE; i++) {
|
|
||||||
data_written[i] = rand() % 0XFF;
|
|
||||||
fprintf(f, "%c", data_written[i]);
|
|
||||||
}
|
|
||||||
write_result = true;
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
printf("[%s]\r\n", write_result ? "OK" : "FAIL");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read back the data from the file and store them in data_read
|
|
||||||
bool read_result = false;
|
|
||||||
{
|
|
||||||
printf("SD: Reading data ... ");
|
|
||||||
FILE *f = fopen(sd_file_path, "r");
|
|
||||||
if (f) {
|
|
||||||
read_result = true;
|
|
||||||
for (int i = 0; i < DATA_SIZE; i++) {
|
|
||||||
uint8_t data = fgetc(f);
|
|
||||||
if (data != data_written[i]) {
|
|
||||||
read_result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
}
|
|
||||||
printf("[%s]\r\n", read_result ? "OK" : "FAIL");
|
|
||||||
}
|
|
||||||
|
|
||||||
result = write_result && read_result;
|
|
||||||
MBED_HOSTTEST_RESULT(result);
|
|
||||||
}
|
|
|
@ -1,168 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
#include "test_env.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if defined(TARGET_KL25Z)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
|
|
||||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K22F)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K20D50M)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_nRF51822)
|
|
||||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F070RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F091RC) || \
|
|
||||||
defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F303RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F410RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L073RZ) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_DISCO_F051R8)
|
|
||||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC2368)
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U68)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC1549)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U37H_401)
|
|
||||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_NUC472)
|
|
||||||
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_M453)
|
|
||||||
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
|
|
||||||
|
|
||||||
#else
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
char buffer[1024];
|
|
||||||
const int KIB_RW = 128;
|
|
||||||
Timer timer;
|
|
||||||
const char *bin_filename = "0:testfile.bin";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_write_fatfs(const char *filename, const int kib_rw) {
|
|
||||||
FIL file;
|
|
||||||
bool result = true;
|
|
||||||
FRESULT res = f_open(&file, filename, FA_WRITE | FA_CREATE_ALWAYS);
|
|
||||||
if (res == FR_OK) {
|
|
||||||
int byte_write = 0;
|
|
||||||
unsigned int bytes = 0;
|
|
||||||
timer.start();
|
|
||||||
for (int i = 0; i < kib_rw; i++) {
|
|
||||||
if (f_write(&file, buffer, sizeof(buffer), &bytes) != FR_OK) {
|
|
||||||
result = false;
|
|
||||||
f_close(&file);
|
|
||||||
printf("Write error!\r\n");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
byte_write++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timer.stop();
|
|
||||||
f_close(&file);
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("write_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_read_fatfs(const char *filename, const int kib_rw) {
|
|
||||||
FIL file;
|
|
||||||
bool result = true;
|
|
||||||
FRESULT res = f_open(&file, filename, FA_READ | FA_OPEN_EXISTING);
|
|
||||||
if (res == FR_OK) {
|
|
||||||
timer.start();
|
|
||||||
int byte_read = 0;
|
|
||||||
unsigned int bytes = 0;
|
|
||||||
do {
|
|
||||||
res = f_read(&file, buffer, sizeof(buffer), &bytes);
|
|
||||||
byte_read++;
|
|
||||||
} while (res == FR_OK && bytes == sizeof(buffer));
|
|
||||||
timer.stop();
|
|
||||||
f_close(&file);
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("fs_read_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char RandomChar() {
|
|
||||||
return rand() % 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
MBED_HOSTTEST_TIMEOUT(15);
|
|
||||||
MBED_HOSTTEST_SELECT(default_auto);
|
|
||||||
MBED_HOSTTEST_DESCRIPTION(SD FatFS RW Speed);
|
|
||||||
MBED_HOSTTEST_START("PERF_3");
|
|
||||||
|
|
||||||
// Test header
|
|
||||||
printf("\r\n");
|
|
||||||
printf("SD Card FatFS Performance Test\r\n");
|
|
||||||
printf("File name: %s\r\n", bin_filename);
|
|
||||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
|
||||||
|
|
||||||
// Initialize buffer
|
|
||||||
srand(testenv_randseed());
|
|
||||||
char *buffer_end = buffer + sizeof(buffer);
|
|
||||||
std::generate (buffer, buffer_end, RandomChar);
|
|
||||||
|
|
||||||
bool result = true;
|
|
||||||
for (;;) {
|
|
||||||
printf("Write test...\r\n");
|
|
||||||
if (test_sf_file_write_fatfs(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Read test...\r\n");
|
|
||||||
if (test_sf_file_read_fatfs(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MBED_HOSTTEST_RESULT(result);
|
|
||||||
}
|
|
|
@ -1,163 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
#include "test_env.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if defined(TARGET_KL25Z)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
|
|
||||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K22F)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K20D50M)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_nRF51822)
|
|
||||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F070RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F091RC) || \
|
|
||||||
defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F303RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F410RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L073RZ) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_DISCO_F051R8)
|
|
||||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC2368)
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U68)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC1549)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U37H_401)
|
|
||||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_NUC472)
|
|
||||||
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_M453)
|
|
||||||
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
|
|
||||||
|
|
||||||
#else
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
char buffer[1024];
|
|
||||||
const int KIB_RW = 128;
|
|
||||||
Timer timer;
|
|
||||||
const char *bin_filename = "testfile.bin";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_write_fhandle(const char *filename, const int kib_rw) {
|
|
||||||
bool result = true;
|
|
||||||
FileHandle* file = sd.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
|
|
||||||
if (file != NULL) {
|
|
||||||
int byte_write = 0;
|
|
||||||
timer.start();
|
|
||||||
for (int i = 0; i < kib_rw; i++) {
|
|
||||||
if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
|
|
||||||
result = false;
|
|
||||||
file->close();
|
|
||||||
printf("Write error!\r\n");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
byte_write++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timer.stop();
|
|
||||||
file->close();
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("write_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_read_fhandle(const char *filename, const int kib_rw) {
|
|
||||||
bool result = true;
|
|
||||||
FileHandle* file = sd.open(filename, O_RDONLY);
|
|
||||||
if (file) {
|
|
||||||
timer.start();
|
|
||||||
int byte_read = 0;
|
|
||||||
while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)) {
|
|
||||||
byte_read++;
|
|
||||||
}
|
|
||||||
timer.stop();
|
|
||||||
file->close();
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("fs_read_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char RandomChar() {
|
|
||||||
return rand() % 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
MBED_HOSTTEST_TIMEOUT(15);
|
|
||||||
MBED_HOSTTEST_SELECT(default_auto);
|
|
||||||
MBED_HOSTTEST_DESCRIPTION(SD FileHandle RW Speed);
|
|
||||||
MBED_HOSTTEST_START("PERF_2");
|
|
||||||
|
|
||||||
// Test header
|
|
||||||
printf("\r\n");
|
|
||||||
printf("SD Card FileHandle Performance Test\r\n");
|
|
||||||
printf("File name: %s\r\n", bin_filename);
|
|
||||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
|
||||||
|
|
||||||
// Initialize buffer
|
|
||||||
srand(testenv_randseed());
|
|
||||||
char *buffer_end = buffer + sizeof(buffer);
|
|
||||||
std::generate (buffer, buffer_end, RandomChar);
|
|
||||||
|
|
||||||
bool result = true;
|
|
||||||
for (;;) {
|
|
||||||
printf("Write test...\r\n");
|
|
||||||
if (test_sf_file_write_fhandle(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Read test...\r\n");
|
|
||||||
if (test_sf_file_read_fhandle(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MBED_HOSTTEST_RESULT(result);
|
|
||||||
}
|
|
|
@ -1,163 +0,0 @@
|
||||||
#include "mbed.h"
|
|
||||||
#include "SDFileSystem.h"
|
|
||||||
#include "test_env.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#if defined(TARGET_KL25Z)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTD0, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_KL46Z) || defined(TARGET_KL43Z)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K64F) || defined(TARGET_K66F)
|
|
||||||
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K22F)
|
|
||||||
SDFileSystem sd(PTD6, PTD7, PTD5, PTD4, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_K20D50M)
|
|
||||||
SDFileSystem sd(PTD2, PTD3, PTD1, PTC2, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_nRF51822)
|
|
||||||
SDFileSystem sd(p12, p13, p15, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUCLEO_F030R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F070RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F072RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F091RC) || \
|
|
||||||
defined(TARGET_NUCLEO_F103RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F302R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F303RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F334R8) || \
|
|
||||||
defined(TARGET_NUCLEO_F401RE) || \
|
|
||||||
defined(TARGET_NUCLEO_F410RB) || \
|
|
||||||
defined(TARGET_NUCLEO_F411RE) || \
|
|
||||||
defined(TARGET_NUCLEO_L053R8) || \
|
|
||||||
defined(TARGET_NUCLEO_L073RZ) || \
|
|
||||||
defined(TARGET_NUCLEO_L152RE)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_DISCO_F051R8)
|
|
||||||
SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC2368)
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U68)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC1549)
|
|
||||||
SDFileSystem sd(D11, D12, D13, D10, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_LPC11U37H_401)
|
|
||||||
SDFileSystem sd(SDMOSI, SDMISO, SDSCLK, SDSSEL, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_NUC472)
|
|
||||||
SDFileSystem sd(PF_0, PD_15, PD_14, PD_13, "sd");
|
|
||||||
|
|
||||||
#elif defined(TARGET_NUMAKER_PFM_M453)
|
|
||||||
SDFileSystem sd(PD_13, PD_14, PD_15, PD_12, "sd");
|
|
||||||
|
|
||||||
#else
|
|
||||||
SDFileSystem sd(p11, p12, p13, p14, "sd");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
char buffer[1024];
|
|
||||||
const int KIB_RW = 128;
|
|
||||||
Timer timer;
|
|
||||||
const char *bin_filename = "/sd/testfile.bin";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_write_stdio(const char *filename, const int kib_rw) {
|
|
||||||
bool result = true;
|
|
||||||
FILE* file = fopen(filename, "w");
|
|
||||||
if (file != NULL) {
|
|
||||||
int byte_write = 0;
|
|
||||||
timer.start();
|
|
||||||
for (int i = 0; i < kib_rw; i++) {
|
|
||||||
if (fwrite(buffer, sizeof(char), sizeof(buffer), file) != sizeof(buffer)) {
|
|
||||||
result = false;
|
|
||||||
fclose(file);
|
|
||||||
printf("Write error!\r\n");
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
byte_write++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
timer.stop();
|
|
||||||
fclose(file);
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB write in %.3f sec with speed of %.4f KiB/s\r\n", byte_write, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("write_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool test_sf_file_read_stdio(const char *filename, const int kib_rw) {
|
|
||||||
bool result = true;
|
|
||||||
FILE* file = fopen(filename, "r");
|
|
||||||
if (file) {
|
|
||||||
timer.start();
|
|
||||||
int byte_read = 0;
|
|
||||||
while (fread(buffer, sizeof(char), sizeof(buffer), file) == sizeof(buffer)) {
|
|
||||||
byte_read++;
|
|
||||||
}
|
|
||||||
timer.stop();
|
|
||||||
fclose(file);
|
|
||||||
double test_time_sec = timer.read_us() / 1000000.0;
|
|
||||||
double speed = kib_rw / test_time_sec;
|
|
||||||
printf("%d KiB read in %.3f sec with speed of %.4f KiB/s\r\n", byte_read, test_time_sec, speed);
|
|
||||||
notify_performance_coefficient("fs_read_kibps", speed);
|
|
||||||
} else {
|
|
||||||
printf("File '%s' not opened\r\n", filename);
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
timer.reset();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
char RandomChar() {
|
|
||||||
return rand() % 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
MBED_HOSTTEST_TIMEOUT(15);
|
|
||||||
MBED_HOSTTEST_SELECT(default_auto);
|
|
||||||
MBED_HOSTTEST_DESCRIPTION(SD stdio RW Speed);
|
|
||||||
MBED_HOSTTEST_START("PERF_1");
|
|
||||||
|
|
||||||
// Test header
|
|
||||||
printf("\r\n");
|
|
||||||
printf("SD Card Stdio Performance Test\r\n");
|
|
||||||
printf("File name: %s\r\n", bin_filename);
|
|
||||||
printf("Buffer size: %d KiB\r\n", (KIB_RW * sizeof(buffer)) / 1024);
|
|
||||||
|
|
||||||
// Initialize buffer
|
|
||||||
srand(testenv_randseed());
|
|
||||||
char *buffer_end = buffer + sizeof(buffer);
|
|
||||||
std::generate (buffer, buffer_end, RandomChar);
|
|
||||||
|
|
||||||
bool result = true;
|
|
||||||
for (;;) {
|
|
||||||
printf("Write test...\r\n");
|
|
||||||
if (test_sf_file_write_stdio(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("Read test...\r\n");
|
|
||||||
if (test_sf_file_read_stdio(bin_filename, KIB_RW) == false) {
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MBED_HOSTTEST_RESULT(result);
|
|
||||||
}
|
|
2
mbed.h
2
mbed.h
|
@ -22,7 +22,7 @@
|
||||||
// RTOS present, this is valid only for mbed OS 5
|
// RTOS present, this is valid only for mbed OS 5
|
||||||
#define MBED_MAJOR_VERSION 5
|
#define MBED_MAJOR_VERSION 5
|
||||||
#define MBED_MINOR_VERSION 4
|
#define MBED_MINOR_VERSION 4
|
||||||
#define MBED_PATCH_VERSION 0
|
#define MBED_PATCH_VERSION 1
|
||||||
|
|
||||||
#else
|
#else
|
||||||
// mbed 2
|
// mbed 2
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#define RETARGET_H
|
#define RETARGET_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
/* We can get the following standard types from sys/types for gcc, but we
|
/* We can get the following standard types from sys/types for gcc, but we
|
||||||
* need to define the types ourselves for the other compilers that normally
|
* need to define the types ourselves for the other compilers that normally
|
||||||
|
|
|
@ -478,7 +478,7 @@ void set_stack_heap(void) {
|
||||||
mbed_stack_isr_start = ISR_STACK_START;
|
mbed_stack_isr_start = ISR_STACK_START;
|
||||||
#else
|
#else
|
||||||
/* Interrupt stack - reserve space at the end of the free block */
|
/* Interrupt stack - reserve space at the end of the free block */
|
||||||
mbed_stack_isr_size = ISR_STACK_SIZE;
|
mbed_stack_isr_size = ISR_STACK_SIZE < free_size ? ISR_STACK_SIZE : free_size;
|
||||||
mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size;
|
mbed_stack_isr_start = free_start + free_size - mbed_stack_isr_size;
|
||||||
free_size -= mbed_stack_isr_size;
|
free_size -= mbed_stack_isr_size;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -67,7 +67,10 @@ static __INLINE uint32_t pstorage_flash_page_end()
|
||||||
|
|
||||||
#define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
|
#define PSTORAGE_FLASH_PAGE_END pstorage_flash_page_end()
|
||||||
|
|
||||||
|
#ifndef PSTORAGE_NUM_OF_PAGES
|
||||||
#define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
|
#define PSTORAGE_NUM_OF_PAGES 1 /**< Number of flash pages allocated for the pstorage module excluding the swap page, configurable based on system requirements. */
|
||||||
|
#endif
|
||||||
|
|
||||||
#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
|
#define PSTORAGE_MIN_BLOCK_SIZE 0x0010 /**< Minimum size of block that can be registered with the module. Should be configured based on system requirements, recommendation is not have this value to be at least size of word. */
|
||||||
|
|
||||||
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
|
#define PSTORAGE_DATA_START_ADDR ((PSTORAGE_FLASH_PAGE_END - PSTORAGE_NUM_OF_PAGES - 1) \
|
||||||
|
|
|
@ -90,22 +90,22 @@ void SPI0_TWI0_IRQHandler(void);
|
||||||
void SPI1_TWI1_IRQHandler(void);
|
void SPI1_TWI1_IRQHandler(void);
|
||||||
void SPIM2_SPIS2_SPI2_IRQHandler(void);
|
void SPIM2_SPIS2_SPI2_IRQHandler(void);
|
||||||
|
|
||||||
static const peripheral_handler_desc_t spi_hanlder_desc[SPI_COUNT] = {
|
static const peripheral_handler_desc_t spi_handler_desc[SPI_COUNT] = {
|
||||||
#if SPI0_ENABLED
|
#if SPI0_ENABLED
|
||||||
{
|
{
|
||||||
SPIS0_IRQ,
|
SPI0_IRQ,
|
||||||
(uint32_t) SPI0_TWI0_IRQHandler
|
(uint32_t) SPI0_TWI0_IRQHandler
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if SPI1_ENABLED
|
#if SPI1_ENABLED
|
||||||
{
|
{
|
||||||
SPIS1_IRQ,
|
SPI1_IRQ,
|
||||||
(uint32_t) SPI1_TWI1_IRQHandler
|
(uint32_t) SPI1_TWI1_IRQHandler
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
#if SPI2_ENABLED
|
#if SPI2_ENABLED
|
||||||
{
|
{
|
||||||
SPIS2_IRQ,
|
SPI2_IRQ,
|
||||||
(uint32_t) SPIM2_SPIS2_SPI2_IRQHandler
|
(uint32_t) SPIM2_SPIS2_SPI2_IRQHandler
|
||||||
},
|
},
|
||||||
#endif
|
#endif
|
||||||
|
@ -254,12 +254,29 @@ void spi_init(spi_t *obj,
|
||||||
PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
PinName mosi, PinName miso, PinName sclk, PinName ssel)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
// This block is only a workaround that allows to create SPI object several
|
||||||
|
// times, what would be otherwise impossible in the current implementation
|
||||||
|
// of mbed driver that does not call spi_free() from SPI destructor.
|
||||||
|
// Once this mbed's imperfection is corrected, this block should be removed.
|
||||||
|
for (i = 0; i < SPI_COUNT; ++i) {
|
||||||
|
spi_info_t *p_spi_info = &m_spi_info[i];
|
||||||
|
if (p_spi_info->initialized &&
|
||||||
|
p_spi_info->mosi_pin == (uint8_t)mosi &&
|
||||||
|
p_spi_info->miso_pin == (uint8_t)miso &&
|
||||||
|
p_spi_info->sck_pin == (uint8_t)sclk &&
|
||||||
|
p_spi_info->ss_pin == (uint8_t)ssel) {
|
||||||
|
// Reuse the already allocated SPI instance (instead of allocating
|
||||||
|
// a new one), if it appears to be initialized with exactly the same
|
||||||
|
// pin assignments.
|
||||||
|
SPI_IDX(obj) = i;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < SPI_COUNT; ++i) {
|
for (i = 0; i < SPI_COUNT; ++i) {
|
||||||
spi_info_t *p_spi_info = &m_spi_info[i];
|
spi_info_t *p_spi_info = &m_spi_info[i];
|
||||||
if (!p_spi_info->initialized) {
|
if (!p_spi_info->initialized) {
|
||||||
|
|
||||||
NVIC_SetVector(spi_hanlder_desc[i].IRQn, spi_hanlder_desc[i].vector);
|
|
||||||
|
|
||||||
p_spi_info->sck_pin = (uint8_t)sclk;
|
p_spi_info->sck_pin = (uint8_t)sclk;
|
||||||
p_spi_info->mosi_pin = (mosi != NC) ?
|
p_spi_info->mosi_pin = (mosi != NC) ?
|
||||||
(uint8_t)mosi : NRF_DRV_SPI_PIN_NOT_USED;
|
(uint8_t)mosi : NRF_DRV_SPI_PIN_NOT_USED;
|
||||||
|
@ -270,6 +287,8 @@ void spi_init(spi_t *obj,
|
||||||
p_spi_info->spi_mode = (uint8_t)NRF_DRV_SPI_MODE_0;
|
p_spi_info->spi_mode = (uint8_t)NRF_DRV_SPI_MODE_0;
|
||||||
p_spi_info->frequency = NRF_DRV_SPI_FREQ_1M;
|
p_spi_info->frequency = NRF_DRV_SPI_FREQ_1M;
|
||||||
|
|
||||||
|
NVIC_SetVector(spi_handler_desc[i].IRQn, spi_handler_desc[i].vector);
|
||||||
|
|
||||||
// By default each SPI instance is initialized to work as a master.
|
// By default each SPI instance is initialized to work as a master.
|
||||||
// Should the slave mode be used, the instance will be reconfigured
|
// Should the slave mode be used, the instance will be reconfigured
|
||||||
// appropriately in 'spi_format'.
|
// appropriately in 'spi_format'.
|
||||||
|
|
|
@ -1,214 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2014, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin) {
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the functions (timer channel, (non)inverted) from the pin and assign it to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
#if defined(TIM1_BASE)
|
|
||||||
if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM2_BASE)
|
|
||||||
if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM14_BASE)
|
|
||||||
if (obj->pwm == PWM_14) __TIM14_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM15_BASE)
|
|
||||||
if (obj->pwm == PWM_15) __TIM15_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM16_BASE)
|
|
||||||
if (obj->pwm == PWM_16) __TIM16_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM17_BASE)
|
|
||||||
if (obj->pwm == PWM_17) __TIM17_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj) {
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value) {
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj) {
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds) {
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms) {
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us) {
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM14_BASE)
|
||||||
|
{PWM_14, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM15_BASE)
|
||||||
|
{PWM_15, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM16_BASE)
|
||||||
|
{PWM_16, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM17_BASE)
|
||||||
|
{PWM_17, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_UNKNOWN = 1
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
/* there is only 1 APB clock in F0 family */
|
||||||
|
#define PWMOUT_APB2_NOT_SUPPORTED
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,205 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2014, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the functions (timer channel, (non)inverted) from the pin and assign it to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
if (obj->pwm == PWM_1) __TIM1_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
int complementary_channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
HAL_TIM_PWM_Init(&TimHandle);
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -128,6 +128,7 @@ struct i2c_s {
|
||||||
struct pwmout_s {
|
struct pwmout_s {
|
||||||
PWMName pwm;
|
PWMName pwm;
|
||||||
PinName pin;
|
PinName pin;
|
||||||
|
uint32_t prescaler;
|
||||||
uint32_t period;
|
uint32_t period;
|
||||||
uint32_t pulse;
|
uint32_t pulse;
|
||||||
uint8_t channel;
|
uint8_t channel;
|
||||||
|
|
|
@ -1,282 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2016, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the functions (timer channel, (non)inverted) from the pin and assign it to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
#if defined(TIM1_BASE)
|
|
||||||
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM2_BASE)
|
|
||||||
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM4_BASE)
|
|
||||||
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM5_BASE)
|
|
||||||
if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM8_BASE)
|
|
||||||
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM9_BASE)
|
|
||||||
if (obj->pwm == PWM_9) __HAL_RCC_TIM9_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM10_BASE)
|
|
||||||
if (obj->pwm == PWM_10) __HAL_RCC_TIM10_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM11_BASE)
|
|
||||||
if (obj->pwm == PWM_11) __HAL_RCC_TIM11_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM12_BASE)
|
|
||||||
if (obj->pwm == PWM_12) __HAL_RCC_TIM12_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM13_BASE)
|
|
||||||
if (obj->pwm == PWM_13) __HAL_RCC_TIM13_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM14_BASE)
|
|
||||||
if (obj->pwm == PWM_14) __HAL_RCC_TIM14_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
||||||
uint32_t PclkFreq;
|
|
||||||
uint32_t APBxCLKDivider;
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
// Get clock configuration
|
|
||||||
// Note: PclkFreq contains here the Latency (not used after)
|
|
||||||
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq);
|
|
||||||
|
|
||||||
// Get the PCLK and APBCLK divider related to the timer
|
|
||||||
switch (obj->pwm) {
|
|
||||||
|
|
||||||
// APB1 clock
|
|
||||||
#if defined(TIM2_BASE)
|
|
||||||
case PWM_2:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
case PWM_3:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM4_BASE)
|
|
||||||
case PWM_4:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM5_BASE)
|
|
||||||
case PWM_5:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM12_BASE)
|
|
||||||
case PWM_12:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM13_BASE)
|
|
||||||
case PWM_13:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM14_BASE)
|
|
||||||
case PWM_14:
|
|
||||||
#endif
|
|
||||||
PclkFreq = HAL_RCC_GetPCLK1Freq();
|
|
||||||
APBxCLKDivider = RCC_ClkInitStruct.APB1CLKDivider;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// APB2 clock
|
|
||||||
#if defined(TIM1_BASE)
|
|
||||||
case PWM_1:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM8_BASE)
|
|
||||||
case PWM_8:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM9_BASE)
|
|
||||||
case PWM_9:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM10_BASE)
|
|
||||||
case PWM_10:
|
|
||||||
#endif
|
|
||||||
#if defined(TIM11_BASE)
|
|
||||||
case PWM_11:
|
|
||||||
#endif
|
|
||||||
PclkFreq = HAL_RCC_GetPCLK2Freq();
|
|
||||||
APBxCLKDivider = RCC_ClkInitStruct.APB2CLKDivider;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
TimHandle.Init.Period = us - 1;
|
|
||||||
// TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx
|
|
||||||
if (APBxCLKDivider == RCC_HCLK_DIV1)
|
|
||||||
TimHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 us tick
|
|
||||||
else
|
|
||||||
TimHandle.Init.Prescaler = (uint16_t)((PclkFreq * 2) / 1000000) - 1; // 1 us tick
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM5_BASE)
|
||||||
|
{PWM_5, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM12_BASE)
|
||||||
|
{PWM_12, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM13_BASE)
|
||||||
|
{PWM_13, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM14_BASE)
|
||||||
|
{PWM_14, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM8_BASE)
|
||||||
|
{PWM_8, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM9_BASE)
|
||||||
|
{PWM_9, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM10_BASE)
|
||||||
|
{PWM_10, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM11_BASE)
|
||||||
|
{PWM_11, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,259 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2015, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the pin function and assign the used channel to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
#if defined(TIM1_BASE)
|
|
||||||
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM2_BASE)
|
|
||||||
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM4_BASE)
|
|
||||||
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM5_BASE)
|
|
||||||
if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM8_BASE)
|
|
||||||
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM9_BASE)
|
|
||||||
if (obj->pwm == PWM_9) __HAL_RCC_TIM9_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM10_BASE)
|
|
||||||
if (obj->pwm == PWM_10) __HAL_RCC_TIM10_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM11_BASE)
|
|
||||||
if (obj->pwm == PWM_11) __HAL_RCC_TIM11_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM12_BASE)
|
|
||||||
if (obj->pwm == PWM_12) __HAL_RCC_TIM12_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM13_BASE)
|
|
||||||
if (obj->pwm == PWM_13) __HAL_RCC_TIM13_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM14_BASE)
|
|
||||||
if (obj->pwm == PWM_14) __HAL_RCC_TIM14_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM15_BASE)
|
|
||||||
if (obj->pwm == PWM_15) __HAL_RCC_TIM15_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM16_BASE)
|
|
||||||
if (obj->pwm == PWM_16) __HAL_RCC_TIM16_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM17_BASE)
|
|
||||||
if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM18_BASE)
|
|
||||||
if (obj->pwm == PWM_18) __HAL_RCC_TIM18_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM19_BASE)
|
|
||||||
if (obj->pwm == PWM_19) __HAL_RCC_TIM19_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM20_BASE)
|
|
||||||
if (obj->pwm == PWM_20) __HAL_RCC_TIM20_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
// Update the SystemCoreClock variable
|
|
||||||
SystemCoreClockUpdate();
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM8_BASE)
|
||||||
|
{PWM_8, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM15_BASE)
|
||||||
|
{PWM_15, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM16_BASE)
|
||||||
|
{PWM_16, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM17_BASE)
|
||||||
|
{PWM_17, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM20_BASE)
|
||||||
|
{PWM_20, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -38,7 +38,7 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2>
|
* <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
|
@ -739,7 +739,9 @@ void SystemInit_ExtMemCtl(void)
|
||||||
/* Enable the FMC/FSMC interface clock */
|
/* Enable the FMC/FSMC interface clock */
|
||||||
RCC->AHB3ENR |= 0x00000001;
|
RCC->AHB3ENR |= 0x00000001;
|
||||||
|
|
||||||
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx)|| defined(STM32F439xx)
|
#if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx)
|
||||||
|
/* Delay after an RCC peripheral clock enabling */
|
||||||
|
tmp = READ_BIT(RCC->AHB3ENR, RCC_AHB3ENR_FMCEN);
|
||||||
/* Configure and enable Bank1_SRAM2 */
|
/* Configure and enable Bank1_SRAM2 */
|
||||||
FMC_Bank1->BTCR[2] = 0x00001011;
|
FMC_Bank1->BTCR[2] = 0x00001011;
|
||||||
FMC_Bank1->BTCR[3] = 0x00000201;
|
FMC_Bank1->BTCR[3] = 0x00000201;
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
|
* <h2><center>© COPYRIGHT 2017 STMicroelectronics</center></h2>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
* are permitted provided that the following conditions are met:
|
* are permitted provided that the following conditions are met:
|
||||||
|
@ -188,10 +188,6 @@ void SetSysClock(void);
|
||||||
*/
|
*/
|
||||||
void SystemInit(void)
|
void SystemInit(void)
|
||||||
{
|
{
|
||||||
/* FPU settings ------------------------------------------------------------*/
|
|
||||||
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
|
|
||||||
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
|
|
||||||
#endif
|
|
||||||
/* Reset the RCC clock configuration to the default reset state ------------*/
|
/* Reset the RCC clock configuration to the default reset state ------------*/
|
||||||
/* Set HSION bit */
|
/* Set HSION bit */
|
||||||
RCC->CR |= (uint32_t)0x00000001;
|
RCC->CR |= (uint32_t)0x00000001;
|
||||||
|
@ -215,13 +211,6 @@ void SystemInit(void)
|
||||||
SystemInit_ExtMemCtl();
|
SystemInit_ExtMemCtl();
|
||||||
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
|
#endif /* DATA_IN_ExtSRAM || DATA_IN_ExtSDRAM */
|
||||||
|
|
||||||
/* Configure the Vector Table location add offset address ------------------*/
|
|
||||||
#ifdef VECT_TAB_SRAM
|
|
||||||
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */
|
|
||||||
#else
|
|
||||||
SCB->VTOR = NVIC_FLASH_VECTOR_ADDRESS; /* Vector Table Relocation in Internal FLASH */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Configure the Cube driver */
|
/* Configure the Cube driver */
|
||||||
SystemCoreClock = 16000000; // At this stage the HSI is used as system clock
|
SystemCoreClock = 16000000; // At this stage the HSI is used as system clock
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
|
|
|
@ -197,9 +197,15 @@ __Vectors_Size EQU __Vectors_End - __Vectors
|
||||||
; Reset handler
|
; Reset handler
|
||||||
Reset_Handler PROC
|
Reset_Handler PROC
|
||||||
EXPORT Reset_Handler [WEAK]
|
EXPORT Reset_Handler [WEAK]
|
||||||
|
IMPORT SystemInitPre
|
||||||
|
IMPORT HAL_InitPre
|
||||||
IMPORT SystemInit
|
IMPORT SystemInit
|
||||||
IMPORT __main
|
IMPORT __main
|
||||||
|
|
||||||
|
LDR R0, =SystemInitPre
|
||||||
|
BLX R0
|
||||||
|
LDR R0, =HAL_InitPre
|
||||||
|
BLX R0
|
||||||
LDR R0, =SystemInit
|
LDR R0, =SystemInit
|
||||||
BLX R0
|
BLX R0
|
||||||
LDR R0, =__main
|
LDR R0, =__main
|
||||||
|
|
|
@ -170,9 +170,15 @@ __Vectors_Size EQU __Vectors_End - __Vectors
|
||||||
; Reset handler
|
; Reset handler
|
||||||
Reset_Handler PROC
|
Reset_Handler PROC
|
||||||
EXPORT Reset_Handler [WEAK]
|
EXPORT Reset_Handler [WEAK]
|
||||||
|
IMPORT SystemInitPre
|
||||||
|
IMPORT HAL_InitPre
|
||||||
IMPORT SystemInit
|
IMPORT SystemInit
|
||||||
IMPORT __main
|
IMPORT __main
|
||||||
|
|
||||||
|
LDR R0, =SystemInitPre
|
||||||
|
BLX R0
|
||||||
|
LDR R0, =HAL_InitPre
|
||||||
|
BLX R0
|
||||||
LDR R0, =SystemInit
|
LDR R0, =SystemInit
|
||||||
BLX R0
|
BLX R0
|
||||||
LDR R0, =__main
|
LDR R0, =__main
|
||||||
|
|
|
@ -63,6 +63,8 @@
|
||||||
SECTION .intvec:CODE:NOROOT(2)
|
SECTION .intvec:CODE:NOROOT(2)
|
||||||
|
|
||||||
EXTERN __iar_program_start
|
EXTERN __iar_program_start
|
||||||
|
EXTERN SystemInitPre
|
||||||
|
EXTERN HAL_InitPre
|
||||||
EXTERN SystemInit
|
EXTERN SystemInit
|
||||||
PUBLIC __vector_table
|
PUBLIC __vector_table
|
||||||
|
|
||||||
|
@ -188,6 +190,10 @@ __vector_table
|
||||||
SECTION .text:CODE:REORDER:NOROOT(2)
|
SECTION .text:CODE:REORDER:NOROOT(2)
|
||||||
Reset_Handler
|
Reset_Handler
|
||||||
|
|
||||||
|
LDR R0, =SystemInitPre
|
||||||
|
BLX R0
|
||||||
|
LDR R0, =HAL_InitPre
|
||||||
|
BLX R0
|
||||||
LDR R0, =SystemInit
|
LDR R0, =SystemInit
|
||||||
BLX R0
|
BLX R0
|
||||||
LDR R0, =__iar_program_start
|
LDR R0, =__iar_program_start
|
||||||
|
|
|
@ -81,14 +81,14 @@ const PinMap PinMap_ADC[] = {
|
||||||
//{PC_4, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14
|
//{PC_4, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_IN14
|
||||||
{PC_5, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15
|
{PC_5, ADC_2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_IN15
|
||||||
//{PC_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15
|
//{PC_5, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_IN15
|
||||||
//{PF_3, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 - ARDUINO A3
|
{PF_3, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_IN9 - ARDUINO A3
|
||||||
{PF_4, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14
|
{PF_4, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_IN14
|
||||||
//{PF_5, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 - ARDUINO A4
|
{PF_5, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_IN15 - ARDUINO A4
|
||||||
{PF_6, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4
|
{PF_6, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_IN4
|
||||||
{PF_7, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5
|
{PF_7, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_IN5
|
||||||
{PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6
|
{PF_8, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_IN6
|
||||||
{PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7
|
{PF_9, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_IN7
|
||||||
//{PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 - ARDUINO A5
|
{PF_10, ADC_3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_IN8 - ARDUINO A5
|
||||||
{ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // See in analogin_api.c the correct ADC channel used
|
{ADC_TEMP, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // See in analogin_api.c the correct ADC channel used
|
||||||
{ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, // See in analogin_api.c the correct ADC channel used
|
{ADC_VREF, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, // See in analogin_api.c the correct ADC channel used
|
||||||
{ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // See in analogin_api.c the correct ADC channel used
|
{ADC_VBAT, ADC_1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // See in analogin_api.c the correct ADC channel used
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM5_BASE)
|
||||||
|
{PWM_5, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM12_BASE)
|
||||||
|
{PWM_12, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM13_BASE)
|
||||||
|
{PWM_13, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM14_BASE)
|
||||||
|
{PWM_14, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM8_BASE)
|
||||||
|
{PWM_8, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM9_BASE)
|
||||||
|
{PWM_9, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM10_BASE)
|
||||||
|
{PWM_10, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM11_BASE)
|
||||||
|
{PWM_11, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -19,9 +19,9 @@ define region RAM_region = mem:[from __region_RAM_start__ to __region_RAM_end__]
|
||||||
define region ITCMRAM_region = mem:[from __region_ITCMRAM_start__ to __region_ITCMRAM_end__];
|
define region ITCMRAM_region = mem:[from __region_ITCMRAM_start__ to __region_ITCMRAM_end__];
|
||||||
|
|
||||||
/* Stack and Heap */
|
/* Stack and Heap */
|
||||||
/*Heap 1/4 of ram and stack 1/8*/
|
/*Heap 1/4 of ram and stack 1/12 */
|
||||||
define symbol __size_cstack__ = 0x4000;
|
define symbol __size_cstack__ = 0x4000;
|
||||||
define symbol __size_heap__ = 0x8000;
|
define symbol __size_heap__ = 0x13000;
|
||||||
define block CSTACK with alignment = 8, size = __size_cstack__ { };
|
define block CSTACK with alignment = 8, size = __size_cstack__ { };
|
||||||
define block HEAP with alignment = 8, size = __size_heap__ { };
|
define block HEAP with alignment = 8, size = __size_heap__ { };
|
||||||
define block STACKHEAP with fixed order { block HEAP, block CSTACK };
|
define block STACKHEAP with fixed order { block HEAP, block CSTACK };
|
||||||
|
|
|
@ -1,253 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2015, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the functions (timer channel, (non)inverted) from the pin and assign it to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_9) __HAL_RCC_TIM9_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_10) __HAL_RCC_TIM10_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_11) __HAL_RCC_TIM11_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_12) __HAL_RCC_TIM12_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_13) __HAL_RCC_TIM13_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_14) __HAL_RCC_TIM14_CLK_ENABLE();
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_DISABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot configure PWM channel\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
||||||
uint32_t PclkFreq;
|
|
||||||
uint32_t APBxCLKDivider;
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
// Get clock configuration
|
|
||||||
// Note: PclkFreq contains here the Latency (not used after)
|
|
||||||
HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &PclkFreq);
|
|
||||||
|
|
||||||
// Get the PCLK and APBCLK divider related to the timer
|
|
||||||
switch (obj->pwm) {
|
|
||||||
|
|
||||||
// APB1 clock
|
|
||||||
case PWM_2:
|
|
||||||
case PWM_3:
|
|
||||||
case PWM_4:
|
|
||||||
case PWM_5:
|
|
||||||
case PWM_12:
|
|
||||||
case PWM_13:
|
|
||||||
case PWM_14:
|
|
||||||
PclkFreq = HAL_RCC_GetPCLK1Freq();
|
|
||||||
APBxCLKDivider = RCC_ClkInitStruct.APB1CLKDivider;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// APB2 clock
|
|
||||||
case PWM_1:
|
|
||||||
case PWM_8:
|
|
||||||
case PWM_9:
|
|
||||||
case PWM_10:
|
|
||||||
case PWM_11:
|
|
||||||
PclkFreq = HAL_RCC_GetPCLK2Freq();
|
|
||||||
APBxCLKDivider = RCC_ClkInitStruct.APB2CLKDivider;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TIMxCLK = PCLKx when the APB prescaler = 1 else TIMxCLK = 2 * PCLKx
|
|
||||||
if (APBxCLKDivider == RCC_HCLK_DIV1)
|
|
||||||
TimHandle.Init.Prescaler = (uint16_t)(((PclkFreq) / 1000000) * obj->prescaler) - 1; // 1 us tick
|
|
||||||
else
|
|
||||||
TimHandle.Init.Prescaler = (uint16_t)(((PclkFreq * 2) / 1000000) * obj->prescaler) - 1; // 1 us tick
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM5_BASE)
|
||||||
|
{PWM_5, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM12_BASE)
|
||||||
|
{PWM_12, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM13_BASE)
|
||||||
|
{PWM_13, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM14_BASE)
|
||||||
|
{PWM_14, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM8_BASE)
|
||||||
|
{PWM_8, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM9_BASE)
|
||||||
|
{PWM_9, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM10_BASE)
|
||||||
|
{PWM_10, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM11_BASE)
|
||||||
|
{PWM_11, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,204 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2015, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the pin function and assign the used channel to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
if (obj->pwm == PWM_21) __TIM21_CLK_ENABLE();
|
|
||||||
#if defined(TIM22_BASE)
|
|
||||||
if (obj->pwm == PWM_22) __TIM22_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_ENABLE;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM21_BASE)
|
||||||
|
{PWM_21, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM22_BASE)
|
||||||
|
{PWM_22, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#define PWMOUT_INVERTED_NOT_SUPPORTED
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -92,40 +92,40 @@ const PinMap PinMap_I2C_SCL[] = {
|
||||||
|
|
||||||
// TIM5 cannot be used because already used by the us_ticker.
|
// TIM5 cannot be used because already used by the us_ticker.
|
||||||
const PinMap PinMap_PWM[] = {
|
const PinMap PinMap_PWM[] = {
|
||||||
// {PA_0, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_0, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_1, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PA_1, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
// {PA_1, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_1, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PA_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
// {PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
|
// {PA_2, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3
|
||||||
// {PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
// {PA_2, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
// {PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
|
// {PA_3, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4
|
||||||
// {PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
// {PA_3, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PA_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
// {PA_6, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PA_6, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PA_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PA_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
// {PA_7, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PA_7, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_0, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PB_0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PB_1, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PB_1, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{PB_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
{PB_4, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PB_5, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PB_6, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH1
|
{PB_6, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1
|
||||||
{PB_7, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH2
|
{PB_7, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2
|
||||||
{PB_8, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH3
|
{PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
|
||||||
// {PB_8, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PB_8, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_9, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH4
|
{PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
|
||||||
// {PB_9, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PB_9, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_10, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PB_10, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
{PB_11, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PB_11, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
{PB_12, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
{PB_12, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_13, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
{PB_13, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PB_14, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
{PB_14, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PB_15, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
{PB_15, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PC_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PC_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PC_8, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PC_9, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{NC, NC, 0}
|
{NC, NC, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -92,40 +92,40 @@ const PinMap PinMap_I2C_SCL[] = {
|
||||||
|
|
||||||
// TIM5 cannot be used because already used by the us_ticker.
|
// TIM5 cannot be used because already used by the us_ticker.
|
||||||
const PinMap PinMap_PWM[] = {
|
const PinMap PinMap_PWM[] = {
|
||||||
// {PA_0, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_0, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_1, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PA_1, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
// {PA_1, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_1, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PA_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
// {PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
|
// {PA_2, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3
|
||||||
// {PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
// {PA_2, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
// {PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
|
// {PA_3, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4
|
||||||
// {PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
// {PA_3, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PA_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
// {PA_6, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PA_6, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PA_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PA_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
// {PA_7, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PA_7, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_0, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PB_0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PB_1, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PB_1, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{PB_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
{PB_4, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PB_5, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PB_6, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH1
|
{PB_6, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1
|
||||||
{PB_7, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH2
|
{PB_7, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2
|
||||||
{PB_8, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH3
|
{PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
|
||||||
// {PB_8, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PB_8, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_9, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH4
|
{PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
|
||||||
// {PB_9, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PB_9, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_10, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PB_10, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
{PB_11, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PB_11, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
{PB_12, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
{PB_12, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_13, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
{PB_13, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PB_14, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
{PB_14, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PB_15, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
{PB_15, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PC_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PC_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PC_8, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PC_9, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{NC, NC, 0}
|
{NC, NC, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -92,40 +92,40 @@ const PinMap PinMap_I2C_SCL[] = {
|
||||||
|
|
||||||
// TIM5 cannot be used because already used by the us_ticker.
|
// TIM5 cannot be used because already used by the us_ticker.
|
||||||
const PinMap PinMap_PWM[] = {
|
const PinMap PinMap_PWM[] = {
|
||||||
// {PA_0, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_0, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_1, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PA_1, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
// {PA_1, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH1
|
// {PA_1, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
|
||||||
{PA_2, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PA_2, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
// {PA_2, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH3
|
// {PA_2, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3
|
||||||
// {PA_2, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
// {PA_2, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PA_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PA_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
// {PA_3, PWM_5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5)}, // TIM5_CH4
|
// {PA_3, PWM_5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4
|
||||||
// {PA_3, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
// {PA_3, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PA_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PA_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
// {PA_6, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PA_6, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PA_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PA_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
// {PA_7, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PA_7, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_0, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PB_0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PB_1, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PB_1, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{PB_3, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH2
|
{PB_3, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
|
||||||
{PB_4, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PB_4, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PB_5, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PB_5, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PB_6, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH1
|
{PB_6, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1
|
||||||
{PB_7, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH2
|
{PB_7, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2
|
||||||
{PB_8, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH3
|
{PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
|
||||||
// {PB_8, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
// {PB_8, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_9, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH4
|
{PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
|
||||||
// {PB_9, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
// {PB_9, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PB_10, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH3
|
{PB_10, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
|
||||||
{PB_11, PWM_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2)}, // TIM2_CH4
|
{PB_11, PWM_2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
|
||||||
{PB_12, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
{PB_12, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_13, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
{PB_13, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PB_14, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
{PB_14, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PB_15, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
{PB_15, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{PC_6, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH1
|
{PC_6, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
|
||||||
{PC_7, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH2
|
{PC_7, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
|
||||||
{PC_8, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PC_8, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PC_9, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH4
|
{PC_9, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
|
||||||
{NC, NC, 0}
|
{NC, NC, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,13 @@ const PinMap PinMap_I2C_SCL[] = {
|
||||||
// TIM2 cannot be used because it is used to clock the SE
|
// TIM2 cannot be used because it is used to clock the SE
|
||||||
// TIM5 cannot be used because already used by the us_ticker.
|
// TIM5 cannot be used because already used by the us_ticker.
|
||||||
const PinMap PinMap_PWM[] = {
|
const PinMap PinMap_PWM[] = {
|
||||||
{PB_0, PWM_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3)}, // TIM3_CH3
|
{PB_0, PWM_3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
|
||||||
{PB_8, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH3
|
{PB_8, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
|
||||||
{PB_9, PWM_4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4)}, // TIM4_CH4
|
{PB_9, PWM_4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
|
||||||
{PB_12, PWM_10, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10)}, // TIM10_CH1
|
{PB_12, PWM_10, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM10, 1, 0)}, // TIM10_CH1
|
||||||
{PB_13, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH1
|
{PB_13, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 1, 0)}, // TIM9_CH1
|
||||||
{PB_14, PWM_9, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9)}, // TIM9_CH2
|
{PB_14, PWM_9, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM9, 2, 0)}, // TIM9_CH2
|
||||||
{PB_15, PWM_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11)}, // TIM11_CH1
|
{PB_15, PWM_11, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM11, 1, 0)}, // TIM11_CH1
|
||||||
{NC, NC, 0}
|
{NC, NC, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ struct dac_s {
|
||||||
PinName pin;
|
PinName pin;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define GPIO_IP_WITHOUT_BRR
|
||||||
#include "common_objects.h"
|
#include "common_objects.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -45,6 +45,8 @@ struct pwmout_s {
|
||||||
uint32_t prescaler;
|
uint32_t prescaler;
|
||||||
uint32_t period;
|
uint32_t period;
|
||||||
uint32_t pulse;
|
uint32_t pulse;
|
||||||
|
uint8_t channel;
|
||||||
|
uint8_t inverted;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct serial_s {
|
struct serial_s {
|
||||||
|
|
|
@ -1,221 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2014, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
if (obj->pwm == (PWMName)NC) {
|
|
||||||
error("PWM error: pinout mapping failed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
if (obj->pwm == PWM_2) __TIM2_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_3) __TIM3_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_4) __TIM4_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_5) __TIM5_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_9) __TIM9_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_10) __TIM10_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_11) __TIM11_CLK_ENABLE();
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_ENABLE;
|
|
||||||
|
|
||||||
switch (obj->pin) {
|
|
||||||
// Channels 1
|
|
||||||
case PA_6:
|
|
||||||
case PB_4:
|
|
||||||
case PB_6:
|
|
||||||
case PB_12:
|
|
||||||
case PB_13:
|
|
||||||
case PB_15:
|
|
||||||
case PC_6:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
// Channels 2
|
|
||||||
case PA_1:
|
|
||||||
case PA_7:
|
|
||||||
case PB_3:
|
|
||||||
case PB_5:
|
|
||||||
case PB_7:
|
|
||||||
case PB_14:
|
|
||||||
case PC_7:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
// Channels 3
|
|
||||||
case PA_2:
|
|
||||||
case PB_0:
|
|
||||||
case PB_8:
|
|
||||||
case PB_10:
|
|
||||||
case PC_8:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
// Channels 4
|
|
||||||
case PA_3:
|
|
||||||
case PB_1:
|
|
||||||
case PB_9:
|
|
||||||
case PB_11:
|
|
||||||
case PC_9:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel);
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM5_BASE)
|
||||||
|
{PWM_5, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM9_BASE)
|
||||||
|
{PWM_9, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM10_BASE)
|
||||||
|
{PWM_10, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM11_BASE)
|
||||||
|
{PWM_11, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
/* L1 HAL do not offer Output Compare idle nor inverted mode*/
|
||||||
|
#define PWMOUT_INVERTED_NOT_SUPPORTED
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -569,7 +569,7 @@ uint8_t SetSysClock_PLL_MSI(void)
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; /* 80 MHz */
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* 80 MHz */
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; /* 40 MHz */
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||||
{
|
{
|
||||||
return 0; // FAIL
|
return 0; // FAIL
|
||||||
|
|
|
@ -569,7 +569,7 @@ uint8_t SetSysClock_PLL_MSI(void)
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; /* 80 MHz */
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* 80 MHz */
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; /* 40 MHz */
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; /* 80 MHz */
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||||
{
|
{
|
||||||
return 0; // FAIL
|
return 0; // FAIL
|
||||||
|
|
|
@ -1,222 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
*******************************************************************************
|
|
||||||
* Copyright (c) 2015, STMicroelectronics
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
|
||||||
* modification, are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* 1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer.
|
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
* this list of conditions and the following disclaimer in the documentation
|
|
||||||
* and/or other materials provided with the distribution.
|
|
||||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
||||||
* may be used to endorse or promote products derived from this software
|
|
||||||
* without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*******************************************************************************
|
|
||||||
*/
|
|
||||||
#include "pwmout_api.h"
|
|
||||||
|
|
||||||
#if DEVICE_PWMOUT
|
|
||||||
|
|
||||||
#include "cmsis.h"
|
|
||||||
#include "pinmap.h"
|
|
||||||
#include "mbed_error.h"
|
|
||||||
#include "PeripheralPins.h"
|
|
||||||
|
|
||||||
static TIM_HandleTypeDef TimHandle;
|
|
||||||
|
|
||||||
void pwmout_init(pwmout_t* obj, PinName pin)
|
|
||||||
{
|
|
||||||
// Get the peripheral name from the pin and assign it to the object
|
|
||||||
obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(obj->pwm != (PWMName)NC);
|
|
||||||
|
|
||||||
// Get the pin function and assign the used channel to the object
|
|
||||||
uint32_t function = pinmap_function(pin, PinMap_PWM);
|
|
||||||
MBED_ASSERT(function != (uint32_t)NC);
|
|
||||||
obj->channel = STM_PIN_CHANNEL(function);
|
|
||||||
obj->inverted = STM_PIN_INVERTED(function);
|
|
||||||
|
|
||||||
// Enable TIM clock
|
|
||||||
if (obj->pwm == PWM_1) __HAL_RCC_TIM1_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_2) __HAL_RCC_TIM2_CLK_ENABLE();
|
|
||||||
#if defined(TIM3_BASE)
|
|
||||||
if (obj->pwm == PWM_3) __HAL_RCC_TIM3_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM4_BASE)
|
|
||||||
if (obj->pwm == PWM_4) __HAL_RCC_TIM4_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM5_BASE)
|
|
||||||
if (obj->pwm == PWM_5) __HAL_RCC_TIM5_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
#if defined(TIM8_BASE)
|
|
||||||
if (obj->pwm == PWM_8) __HAL_RCC_TIM8_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
if (obj->pwm == PWM_15) __HAL_RCC_TIM15_CLK_ENABLE();
|
|
||||||
if (obj->pwm == PWM_16) __HAL_RCC_TIM16_CLK_ENABLE();
|
|
||||||
#if defined(TIM17_BASE)
|
|
||||||
if (obj->pwm == PWM_17) __HAL_RCC_TIM17_CLK_ENABLE();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Configure GPIO
|
|
||||||
pinmap_pinout(pin, PinMap_PWM);
|
|
||||||
|
|
||||||
obj->pin = pin;
|
|
||||||
obj->period = 0;
|
|
||||||
obj->pulse = 0;
|
|
||||||
obj->prescaler = 1;
|
|
||||||
|
|
||||||
pwmout_period_us(obj, 20000); // 20 ms per default
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_free(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
// Configure GPIO
|
|
||||||
pin_function(obj->pin, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_write(pwmout_t* obj, float value)
|
|
||||||
{
|
|
||||||
TIM_OC_InitTypeDef sConfig;
|
|
||||||
int channel = 0;
|
|
||||||
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
if (value < (float)0.0) {
|
|
||||||
value = 0.0;
|
|
||||||
} else if (value > (float)1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
obj->pulse = (uint32_t)((float)obj->period * value);
|
|
||||||
|
|
||||||
// Configure channels
|
|
||||||
sConfig.OCMode = TIM_OCMODE_PWM1;
|
|
||||||
sConfig.Pulse = obj->pulse / obj->prescaler;
|
|
||||||
sConfig.OCPolarity = TIM_OCPOLARITY_HIGH;
|
|
||||||
sConfig.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
|
||||||
sConfig.OCFastMode = TIM_OCFAST_ENABLE;
|
|
||||||
sConfig.OCIdleState = TIM_OCIDLESTATE_RESET;
|
|
||||||
sConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
|
||||||
|
|
||||||
switch (obj->channel) {
|
|
||||||
case 1:
|
|
||||||
channel = TIM_CHANNEL_1;
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
channel = TIM_CHANNEL_2;
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
channel = TIM_CHANNEL_3;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
channel = TIM_CHANNEL_4;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_ConfigChannel(&TimHandle, &sConfig, channel) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (obj->inverted) {
|
|
||||||
HAL_TIMEx_PWMN_Start(&TimHandle, channel);
|
|
||||||
} else {
|
|
||||||
HAL_TIM_PWM_Start(&TimHandle, channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float pwmout_read(pwmout_t* obj)
|
|
||||||
{
|
|
||||||
float value = 0;
|
|
||||||
if (obj->period > 0) {
|
|
||||||
value = (float)(obj->pulse) / (float)(obj->period);
|
|
||||||
}
|
|
||||||
return ((value > (float)1.0) ? (float)(1.0) : (value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_period_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_period_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
TimHandle.Instance = (TIM_TypeDef *)(obj->pwm);
|
|
||||||
|
|
||||||
float dc = pwmout_read(obj);
|
|
||||||
|
|
||||||
__HAL_TIM_DISABLE(&TimHandle);
|
|
||||||
|
|
||||||
/* To make it simple, we use to possible prescaler values which lead to:
|
|
||||||
* pwm unit = 1us, period/pulse can be from 1us to 65535us
|
|
||||||
* or
|
|
||||||
* pwm unit = 500us, period/pulse can be from 500us to ~32.76sec
|
|
||||||
* Be careful that all the channels of a PWM shares the same prescaler
|
|
||||||
*/
|
|
||||||
if (us > 0xFFFF) {
|
|
||||||
obj->prescaler = 500;
|
|
||||||
} else {
|
|
||||||
obj->prescaler = 1;
|
|
||||||
}
|
|
||||||
TimHandle.Init.Prescaler = ((SystemCoreClock / 1000000) * obj->prescaler) - 1;
|
|
||||||
|
|
||||||
if (TimHandle.Init.Prescaler > 0xFFFF)
|
|
||||||
error("PWM: out of range prescaler");
|
|
||||||
|
|
||||||
TimHandle.Init.Period = (us - 1) / obj->prescaler;
|
|
||||||
if (TimHandle.Init.Period > 0xFFFF)
|
|
||||||
error("PWM: out of range period");
|
|
||||||
|
|
||||||
TimHandle.Init.ClockDivision = 0;
|
|
||||||
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
|
|
||||||
|
|
||||||
if (HAL_TIM_PWM_Init(&TimHandle) != HAL_OK) {
|
|
||||||
error("Cannot initialize PWM\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save for future use
|
|
||||||
obj->period = us;
|
|
||||||
|
|
||||||
// Set duty cycle again
|
|
||||||
pwmout_write(obj, dc);
|
|
||||||
|
|
||||||
__HAL_TIM_ENABLE(&TimHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth(pwmout_t* obj, float seconds)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_ms(pwmout_t* obj, int ms)
|
|
||||||
{
|
|
||||||
pwmout_pulsewidth_us(obj, ms * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
|
||||||
{
|
|
||||||
float value = (float)us / (float)obj->period;
|
|
||||||
pwmout_write(obj, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#include "cmsis.h"
|
||||||
|
#include "pwmout_api.h"
|
||||||
|
#include "pwmout_device.h"
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
const pwm_apb_map_t pwm_apb_map_table[] =
|
||||||
|
{
|
||||||
|
#if defined(TIM2_BASE)
|
||||||
|
{PWM_2, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM3_BASE)
|
||||||
|
{PWM_3, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM4_BASE)
|
||||||
|
{PWM_4, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM5_BASE)
|
||||||
|
{PWM_5, PWMOUT_ON_APB1},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM1_BASE)
|
||||||
|
{PWM_1, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM8_BASE)
|
||||||
|
{PWM_8, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM15_BASE)
|
||||||
|
{PWM_15, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM16_BASE)
|
||||||
|
{PWM_16, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
#if defined(TIM17_BASE)
|
||||||
|
{PWM_17, PWMOUT_ON_APB2},
|
||||||
|
#endif
|
||||||
|
{(PWMName) 0, PWMOUT_UNKNOWN}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
|
@ -0,0 +1,57 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
*******************************************************************************
|
||||||
|
* Copyright (c) 2017, STMicroelectronics
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
#ifndef MBED_PWMOUT_DEVICE_H
|
||||||
|
#define MBED_PWMOUT_DEVICE_H
|
||||||
|
|
||||||
|
#include "cmsis.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEVICE_PWMOUT
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PWMOUT_ON_APB1 = 0,
|
||||||
|
PWMOUT_ON_APB2 = 1,
|
||||||
|
PWMOUT_UNKNOWN = 2
|
||||||
|
} PwmoutApb;
|
||||||
|
|
||||||
|
/* Structure to describe Timers to APB */
|
||||||
|
typedef struct pwm_apb_map {
|
||||||
|
PWMName pwm; // an index entry for each EXIT line
|
||||||
|
PwmoutApb pwmoutApb;
|
||||||
|
} pwm_apb_map_t;
|
||||||
|
|
||||||
|
extern const pwm_apb_map_t pwm_apb_map_table[];
|
||||||
|
|
||||||
|
#endif // DEVICE_PWMOUT
|
||||||
|
|
||||||
|
#endif
|
|
@ -43,6 +43,7 @@ void can_init(can_t *obj, PinName rd, PinName td)
|
||||||
}
|
}
|
||||||
#if defined(CAN2_BASE) && (CAN_NUM == 2)
|
#if defined(CAN2_BASE) && (CAN_NUM == 2)
|
||||||
else if (obj->can == CAN_2) {
|
else if (obj->can == CAN_2) {
|
||||||
|
__HAL_RCC_CAN1_CLK_ENABLE(); // needed to set filters
|
||||||
__HAL_RCC_CAN2_CLK_ENABLE();
|
__HAL_RCC_CAN2_CLK_ENABLE();
|
||||||
obj->index = 1;
|
obj->index = 1;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ int can_frequency(can_t *obj, int f)
|
||||||
|
|
||||||
int can_write(can_t *obj, CAN_Message msg, int cc)
|
int can_write(can_t *obj, CAN_Message msg, int cc)
|
||||||
{
|
{
|
||||||
uint32_t transmitmailbox = 5;
|
uint32_t transmitmailbox = CAN_TXSTATUS_NOMAILBOX;
|
||||||
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
|
CAN_TypeDef *can = (CAN_TypeDef *)(obj->can);
|
||||||
|
|
||||||
/* Select one empty transmit mailbox */
|
/* Select one empty transmit mailbox */
|
||||||
|
@ -217,33 +218,31 @@ int can_write(can_t *obj, CAN_Message msg, int cc)
|
||||||
} else if ((can->TSR & CAN_TSR_TME2) == CAN_TSR_TME2) {
|
} else if ((can->TSR & CAN_TSR_TME2) == CAN_TSR_TME2) {
|
||||||
transmitmailbox = 2;
|
transmitmailbox = 2;
|
||||||
} else {
|
} else {
|
||||||
transmitmailbox = CAN_TXSTATUS_NOMAILBOX;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transmitmailbox != CAN_TXSTATUS_NOMAILBOX) {
|
can->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ;
|
||||||
can->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ;
|
if (!(msg.format)) {
|
||||||
if (!(msg.format)) {
|
can->sTxMailBox[transmitmailbox].TIR |= ((msg.id << 21) | msg.type);
|
||||||
can->sTxMailBox[transmitmailbox].TIR |= ((msg.id << 21) | msg.type);
|
} else {
|
||||||
} else {
|
can->sTxMailBox[transmitmailbox].TIR |= ((msg.id << 3) | CAN_ID_EXT | msg.type);
|
||||||
can->sTxMailBox[transmitmailbox].TIR |= ((msg.id << 3) | CAN_ID_EXT | msg.type);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Set up the DLC */
|
/* Set up the DLC */
|
||||||
can->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0;
|
can->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0;
|
||||||
can->sTxMailBox[transmitmailbox].TDTR |= (msg.len & (uint8_t)0x0000000F);
|
can->sTxMailBox[transmitmailbox].TDTR |= (msg.len & (uint8_t)0x0000000F);
|
||||||
|
|
||||||
/* Set up the data field */
|
/* Set up the data field */
|
||||||
can->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)msg.data[3] << 24) |
|
can->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)msg.data[3] << 24) |
|
||||||
((uint32_t)msg.data[2] << 16) |
|
((uint32_t)msg.data[2] << 16) |
|
||||||
((uint32_t)msg.data[1] << 8) |
|
((uint32_t)msg.data[1] << 8) |
|
||||||
((uint32_t)msg.data[0]));
|
((uint32_t)msg.data[0]));
|
||||||
can->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)msg.data[7] << 24) |
|
can->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)msg.data[7] << 24) |
|
||||||
((uint32_t)msg.data[6] << 16) |
|
((uint32_t)msg.data[6] << 16) |
|
||||||
((uint32_t)msg.data[5] << 8) |
|
((uint32_t)msg.data[5] << 8) |
|
||||||
((uint32_t)msg.data[4]));
|
((uint32_t)msg.data[4]));
|
||||||
/* Request transmission */
|
/* Request transmission */
|
||||||
can->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ;
|
can->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ;
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -261,14 +260,14 @@ int can_read(can_t *obj, CAN_Message *msg, int handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the Id */
|
/* Get the Id */
|
||||||
msg->format = (CANFormat)((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR);
|
msg->format = (CANFormat)(((uint8_t)0x04 & can->sFIFOMailBox[handle].RIR) >> 2);
|
||||||
if (!msg->format) {
|
if (!msg->format) {
|
||||||
msg->id = (uint32_t)0x000007FF & (can->sFIFOMailBox[handle].RIR >> 21);
|
msg->id = (uint32_t)0x000007FF & (can->sFIFOMailBox[handle].RIR >> 21);
|
||||||
} else {
|
} else {
|
||||||
msg->id = (uint32_t)0x1FFFFFFF & (can->sFIFOMailBox[handle].RIR >> 3);
|
msg->id = (uint32_t)0x1FFFFFFF & (can->sFIFOMailBox[handle].RIR >> 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->type = (CANType)((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR);
|
msg->type = (CANType)(((uint8_t)0x02 & can->sFIFOMailBox[handle].RIR) >> 1);
|
||||||
/* Get the DLC */
|
/* Get the DLC */
|
||||||
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[handle].RDTR;
|
msg->len = (uint8_t)0x0F & can->sFIFOMailBox[handle].RDTR;
|
||||||
/* Get the FMI */
|
/* Get the FMI */
|
||||||
|
@ -460,37 +459,47 @@ static void can_irq(CANName name, int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TARGET_STM32F0)
|
#if defined(TARGET_STM32F0)
|
||||||
void CAN_IRQHandler(void) {
|
void CAN_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
#elif defined(TARGET_STM32F3)
|
#elif defined(TARGET_STM32F3)
|
||||||
void CAN_RX0_IRQHandler(void) {
|
void CAN_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
void CAN_TX_IRQHandler(void) {
|
void CAN_TX_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
void CAN_SCE_IRQHandler(void) {
|
void CAN_SCE_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void CAN1_RX0_IRQHandler(void) {
|
void CAN1_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
void CAN1_TX_IRQHandler(void) {
|
void CAN1_TX_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
void CAN1_SCE_IRQHandler(void) {
|
void CAN1_SCE_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_1, 0);
|
can_irq(CAN_1, 0);
|
||||||
}
|
}
|
||||||
#if defined(CAN2_BASE) && (CAN_NUM == 2)
|
#if defined(CAN2_BASE) && (CAN_NUM == 2)
|
||||||
void CAN2_RX0_IRQHandler(void) {
|
void CAN2_RX0_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_2, 1);
|
can_irq(CAN_2, 1);
|
||||||
}
|
}
|
||||||
void CAN2_TX_IRQHandler(void) {
|
void CAN2_TX_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_2, 1);
|
can_irq(CAN_2, 1);
|
||||||
}
|
}
|
||||||
void CAN2_SCE_IRQHandler(void) {
|
void CAN2_SCE_IRQHandler(void)
|
||||||
|
{
|
||||||
can_irq(CAN_2, 1);
|
can_irq(CAN_2, 1);
|
||||||
}
|
}
|
||||||
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)
|
#endif // defined(CAN2_BASE) && (CAN_NUM == 2)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue