diff --git a/.github/workflows/basic_checks.yml b/.github/workflows/basic_checks.yml index 3ec2e19d8f7..f476d18acec 100644 --- a/.github/workflows/basic_checks.yml +++ b/.github/workflows/basic_checks.yml @@ -1,4 +1,4 @@ - This workflow performs the checks like license check, +# This workflow performs the checks like license check, # doxygen, unit tests etc. name: Basic Checks diff --git a/connectivity/FEATURE_BLE/README.md b/connectivity/FEATURE_BLE/README.md index 6030bd3515d..221b64ccc4b 100644 --- a/connectivity/FEATURE_BLE/README.md +++ b/connectivity/FEATURE_BLE/README.md @@ -8,3 +8,19 @@ This is the Github repository for the `BLE_API`. Please see the [Mbed OS Example * [Mbed OS example BLE GitHub repo](https://github.com/ARMmbed/mbed-os-example-ble) for all Mbed OS BLE examples. * [Mbed OS BLE introduction](https://os.mbed.com/docs/latest/apis/ble.html) for an introduction to Mbed BLE. * [Mbed OS BLE API page](https://os.mbed.com/docs/latest/apis/bluetooth.html) for the Mbed BLE API documentation. + +## Privacy notice + +The Cordio Bluetooth stack only stores one single signing key. This key is then +shared across all bonded devices. If a malicious device bonds with the Mbed OS +application it then gains knowledge of the shared signing key of the Mbed OS device. +The malicious device can then track the Mbed OS device whenever a signing write +is issued from it. + +To overcome this privacy issue do not issue signed writes from the Mbed OS device. +A signed write occurs when the member function `write` of `GattClient` is called +with its `cmd` argument set to `GATT_OP_SIGNED_WRITE_CMD`. + +Instead of using signed writes, enable encryption on the connection. This is achieved + by calling the function `setLinkEncryption` of the `SecurityManager`. Set the encryption +to at least `ENCRYPTED`. diff --git a/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h b/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h index 20fe6c139e9..07a5f90dad2 100755 --- a/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h +++ b/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h @@ -67,7 +67,7 @@ class AT_CellularDevice : public CellularDevice { }; public: - AT_CellularDevice(FileHandle *fh); + AT_CellularDevice(FileHandle *fh, char *delim = "\r"); virtual ~AT_CellularDevice(); virtual nsapi_error_t clear(); diff --git a/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp b/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp index 83ab47a3c49..e3fd5b551a3 100644 --- a/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp +++ b/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp @@ -39,9 +39,9 @@ using namespace std::chrono_literals; #define DEFAULT_AT_TIMEOUT 1s // at default timeout const int MAX_SIM_RESPONSE_LENGTH = 16; -AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : +AT_CellularDevice::AT_CellularDevice(FileHandle *fh, char *delim): CellularDevice(), - _at(fh, _queue, DEFAULT_AT_TIMEOUT, "\r"), + _at(fh, _queue, DEFAULT_AT_TIMEOUT, delim), #if MBED_CONF_CELLULAR_USE_SMS _sms(0), #endif // MBED_CONF_CELLULAR_USE_SMS diff --git a/connectivity/cellular/tests/UNITTESTS/doubles/AT_CellularDevice_stub.cpp b/connectivity/cellular/tests/UNITTESTS/doubles/AT_CellularDevice_stub.cpp index f65362bcde7..300962bd7ae 100644 --- a/connectivity/cellular/tests/UNITTESTS/doubles/AT_CellularDevice_stub.cpp +++ b/connectivity/cellular/tests/UNITTESTS/doubles/AT_CellularDevice_stub.cpp @@ -33,9 +33,9 @@ bool AT_CellularDevice_stub::pin_needed = false; bool AT_CellularDevice_stub::supported_bool = false; int AT_CellularDevice_stub::max_sock_value = 1; -AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : +AT_CellularDevice::AT_CellularDevice(FileHandle *fh, char *delim) : CellularDevice(), - _at(fh, _queue, get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), "\r"), + _at(fh, _queue, get_property(AT_CellularDevice::PROPERTY_AT_SEND_DELAY), delim), #if MBED_CONF_CELLULAR_USE_SMS _sms(0), #endif // MBED_CONF_CELLULAR_USE_SMS diff --git a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp index 80b74bd8620..c4a1bbcf96a 100644 --- a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp +++ b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac.cpp @@ -89,14 +89,13 @@ emac_mem_buf_t *SMSC9220_EMAC::low_level_input() message_length -= CRC_LENGTH_BYTES; } - p = _memory_manager->alloc_heap(SMSC9220_ETH_MAX_FRAME_SIZE, + p = _memory_manager->alloc_heap(message_length, SMSC9220_BUFF_ALIGNMENT); if (p != NULL) { _RXLockMutex.lock(); - received_bytes = smsc9220_receive_by_chunks(dev, - (char*)_memory_manager->get_ptr(p), - _memory_manager->get_len(p)); + received_bytes = smsc9220_receive_packet(dev, + _memory_manager->get_ptr(p)); if(received_bytes == 0){ _memory_manager->free(p); p = nullptr; @@ -148,7 +147,6 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf) if(buf == NULL) { return false; } else { - uint32_t buffer_chain_length = 0; enum smsc9220_error_t error = SMSC9220_ERROR_NONE; /* If buffer is chained or not aligned then * make a contiguous aligned copy of it */ @@ -170,16 +168,12 @@ bool SMSC9220_EMAC::link_out(emac_mem_buf_t *buf) buf = copy_buf; } - buffer_chain_length = _memory_manager->get_total_len(buf); - _TXLockMutex.lock(); - error = smsc9220_send_by_chunks(dev, - buffer_chain_length, - true, - (const char*)_memory_manager->get_ptr(buf), + error = smsc9220_send_packet(dev, + _memory_manager->get_ptr(buf), _memory_manager->get_len(buf)); _memory_manager->free(buf); - _TXLockMutex.unlock(); + _TXLockMutex.unlock(); return (error == SMSC9220_ERROR_NONE); } } @@ -211,7 +205,7 @@ bool SMSC9220_EMAC::power_up() this)); /* Initialize the hardware */ - enum smsc9220_error_t init_successful = smsc9220_init(dev, &ThisThread::sleep_for); + enum smsc9220_error_t init_successful = smsc9220_init(dev, &thread_sleep_for); if (init_successful != SMSC9220_ERROR_NONE) { return false; } @@ -237,7 +231,7 @@ bool SMSC9220_EMAC::power_up() &SMSC9220_EMAC::link_status_task)); /* Allow the Link Status task to detect the initial link state */ - ThisThread::sleep_for(10); + ThisThread::sleep_for(10ms); _link_status_task_handle = mbed::mbed_event_queue()->call_every( LINK_STATUS_TASK_PERIOD_MS, mbed::callback(this, diff --git a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac_config.h b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac_config.h index a96a008357a..5f618308c50 100644 --- a/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac_config.h +++ b/connectivity/drivers/emac/TARGET_ARM_SSG/COMPONENT_SMSC9220/smsc9220_emac_config.h @@ -36,7 +36,7 @@ #define FLAG_RX 1U #define LINK_STATUS_THREAD_PRIORITY (osPriorityNormal) #define LINK_STATUS_THREAD_STACKSIZE 512U -#define LINK_STATUS_TASK_PERIOD_MS 200U +#define LINK_STATUS_TASK_PERIOD_MS 200ms #define PHY_STATE_LINK_DOWN false #define PHY_STATE_LINK_UP true #define CRC_LENGTH_BYTES 4U diff --git a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/des/des_alt.c b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/des/des_alt.c index 83863ca37b8..d0bf68dcf61 100644 --- a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/des/des_alt.c +++ b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/des/des_alt.c @@ -375,7 +375,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S * 1. BE for byte sequence in word * 2. BE for word sequence in double-word */ - TDES_Open(CRPT + TDES_Open(CRPT, 0, // Channel number (0~4) enc, // 0: decode, 1: encode (tdes_opmode & CRPT_TDES_CTL_TMODE_Msk) ? 1 : 0, // 0: DES, 1: TDES diff --git a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c index c0c116b2154..c028923ed77 100644 --- a/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c +++ b/connectivity/drivers/mbedtls/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c @@ -502,6 +502,11 @@ NU_STATIC int internal_run_eccop(const mbedtls_ecp_group *grp, return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED; } + /* NOTE: Engine doesn't support P + Q when P and Q are the same. Workaround by 2*P */ + if (mbedtls_ecp_point_cmp(P, Q) == 0) { + return internal_run_eccop(grp, R, NULL, P, NULL, NULL, ECCOP_POINT_DOUBLE); + } + int ret; bool ecc_done; diff --git a/connectivity/lwipstack/lwip/src/apps/lwiperf/lwip_lwiperf.c b/connectivity/lwipstack/lwip/src/apps/lwiperf/lwip_lwiperf.c index dbec4dae91e..6895ebc047a 100644 --- a/connectivity/lwipstack/lwip/src/apps/lwiperf/lwip_lwiperf.c +++ b/connectivity/lwipstack/lwip/src/apps/lwiperf/lwip_lwiperf.c @@ -263,7 +263,7 @@ lwiperf_tcp_close(lwiperf_state_tcp_t *conn, enum lwiperf_report_type report_typ /* don't want to wait for free memory here... */ tcp_abort(conn->conn_pcb); } - } else { + } else if (conn->server_pcb != NULL) { /* no conn pcb, this is the listener pcb */ err = tcp_close(conn->server_pcb); LWIP_ASSERT("error", err == ERR_OK); @@ -565,6 +565,11 @@ lwiperf_tcp_err(void *arg, err_t err) { lwiperf_state_tcp_t *conn = (lwiperf_state_tcp_t *)arg; LWIP_UNUSED_ARG(err); + + /* pcb is already deallocated, prevent double-free */ + conn->conn_pcb = NULL; + conn->server_pcb = NULL; + lwiperf_tcp_close(conn, LWIPERF_TCP_ABORTED_REMOTE); } diff --git a/connectivity/mbedtls/source/ecp_curves.c b/connectivity/mbedtls/source/ecp_curves.c index 839fb5e36e9..72dfacd9af7 100644 --- a/connectivity/mbedtls/source/ecp_curves.c +++ b/connectivity/mbedtls/source/ecp_curves.c @@ -770,6 +770,8 @@ int mbedtls_ecp_group_load( mbedtls_ecp_group *grp, mbedtls_ecp_group_id id ) ECP_VALIDATE_RET( grp != NULL ); mbedtls_ecp_group_free( grp ); + mbedtls_ecp_group_init( grp ); + grp->id = id; switch( id ) diff --git a/drivers/include/drivers/PwmOut.h b/drivers/include/drivers/PwmOut.h index 462c5760b91..9a901c4b758 100644 --- a/drivers/include/drivers/PwmOut.h +++ b/drivers/include/drivers/PwmOut.h @@ -133,8 +133,15 @@ class PwmOut { /** Read the PWM pulsewidth * @returns - * The PWM pulsewith, specified in microseconds (int) + * The PWM pulsewidth, specified in microseconds (int) */ + int read_pulsewidth_us(); + + /** Read the PWM pulsewidth + * @returns + * The PWM pulsewidth, specified in microseconds (int) + */ + MBED_DEPRECATED("use read_pulsewidth_us() instead") int read_pulsewitdth_us(); /** Suspend PWM operation diff --git a/drivers/source/PwmOut.cpp b/drivers/source/PwmOut.cpp index ccada968ed7..cc717f8e99a 100644 --- a/drivers/source/PwmOut.cpp +++ b/drivers/source/PwmOut.cpp @@ -113,7 +113,7 @@ void PwmOut::pulsewidth_us(int us) core_util_critical_section_exit(); } -int PwmOut::read_pulsewitdth_us() +int PwmOut::read_pulsewidth_us() { core_util_critical_section_enter(); auto val = pwmout_read_pulsewidth_us(&_pwm); @@ -121,6 +121,11 @@ int PwmOut::read_pulsewitdth_us() return val; } +int PwmOut::read_pulsewitdth_us() +{ + return read_pulsewidth_us(); +} + void PwmOut::suspend() { core_util_critical_section_enter(); diff --git a/hal/include/hal/pwmout_api.h b/hal/include/hal/pwmout_api.h index c606183931a..dc8fd84182e 100644 --- a/hal/include/hal/pwmout_api.h +++ b/hal/include/hal/pwmout_api.h @@ -158,7 +158,7 @@ void pwmout_pulsewidth_us(pwmout_t *obj, int us); /** Read the PWM pulsewidth specified in microseconds * * @param obj The pwmout object - * @return A int output pulsewitdth + * @return A int output pulsewidth */ int pwmout_read_pulsewidth_us(pwmout_t *obj); diff --git a/platform/tests/UNITTESTS/doubles/CMakeLists.txt b/platform/tests/UNITTESTS/doubles/CMakeLists.txt index e3c21e547ba..3b6c440ce4b 100644 --- a/platform/tests/UNITTESTS/doubles/CMakeLists.txt +++ b/platform/tests/UNITTESTS/doubles/CMakeLists.txt @@ -32,6 +32,7 @@ target_sources(mbed-stubs-platform nvic_wrapper_stub.c randLIB_stub.c randLIB_stub.cpp + ../../../source/SingletonPtr.cpp ) target_include_directories(mbed-stubs-platform PUBLIC diff --git a/storage/filesystem/fat/source/FATFileSystem.cpp b/storage/filesystem/fat/source/FATFileSystem.cpp index 3eb4886a882..72d4157b62e 100644 --- a/storage/filesystem/fat/source/FATFileSystem.cpp +++ b/storage/filesystem/fat/source/FATFileSystem.cpp @@ -755,6 +755,7 @@ int FATFileSystem::file_truncate(fs_file_t file, off_t length) return fat_error_remap(res); } + unlock(); return 0; } diff --git a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c index 289ac873659..7d2b2e50154 100644 --- a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c +++ b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.c @@ -284,73 +284,6 @@ enum gpio_cfg_bits_t{ GPIO_CFG_GPIO2_LED_INDEX = 30U /*< GPIO2 set to LED3 */ }; - -static void fill_tx_fifo(const struct smsc9220_eth_dev_t* dev, - uint8_t *data, uint32_t size_bytes) -{ - struct smsc9220_eth_reg_map_t* register_map = - (struct smsc9220_eth_reg_map_t*)dev->cfg->base; - - uint32_t tx_data_port_tmp = 0; - uint8_t *tx_data_port_tmp_ptr = (uint8_t *)&tx_data_port_tmp; - - /*If the data length is not a multiple of 4, then the beginning of the first - * DWORD of the TX DATA FIFO gets filled up with zeros and a byte offset is - * set accordingly to guarantee proper transmission.*/ - uint32_t remainder_bytes = (size_bytes % 4); - uint32_t filler_bytes = (4 - remainder_bytes); - for(uint32_t i = 0; i < 4; i++){ - if(i < filler_bytes){ - tx_data_port_tmp_ptr[i] = 0; - } else { - tx_data_port_tmp_ptr[i] = data[i-filler_bytes]; - } - } - register_map->tx_data_port = tx_data_port_tmp; - size_bytes -= remainder_bytes; - data += remainder_bytes; - - while (size_bytes > 0) { - /* Keep the same endianness in data as in the temp variable */ - tx_data_port_tmp_ptr[0] = data[0]; - tx_data_port_tmp_ptr[1] = data[1]; - tx_data_port_tmp_ptr[2] = data[2]; - tx_data_port_tmp_ptr[3] = data[3]; - register_map->tx_data_port = tx_data_port_tmp; - data += 4; - size_bytes -= 4; - } -} - -static void empty_rx_fifo(const struct smsc9220_eth_dev_t* dev, - uint8_t *data, uint32_t size_bytes) -{ - struct smsc9220_eth_reg_map_t* register_map = - (struct smsc9220_eth_reg_map_t*)dev->cfg->base; - - uint32_t rx_data_port_tmp = 0; - uint8_t *rx_data_port_tmp_ptr = (uint8_t *)&rx_data_port_tmp; - - uint32_t remainder_bytes = (size_bytes % 4); - size_bytes -= remainder_bytes; - - while (size_bytes > 0) { - /* Keep the same endianness in data as in the temp variable */ - rx_data_port_tmp = register_map->rx_data_port; - data[0] = rx_data_port_tmp_ptr[0]; - data[1] = rx_data_port_tmp_ptr[1]; - data[2] = rx_data_port_tmp_ptr[2]; - data[3] = rx_data_port_tmp_ptr[3]; - data += 4; - size_bytes -= 4; - } - - rx_data_port_tmp = register_map->rx_data_port; - for(uint32_t i = 0; i < remainder_bytes; i++) { - data[i] = rx_data_port_tmp_ptr[i]; - } -} - enum smsc9220_error_t smsc9220_mac_regread( const struct smsc9220_eth_dev_t* dev, enum smsc9220_mac_reg_offsets_t regoffset, @@ -949,77 +882,45 @@ enum smsc9220_error_t smsc9220_init( return SMSC9220_ERROR_NONE; } -enum smsc9220_error_t smsc9220_send_by_chunks( +enum smsc9220_error_t smsc9220_send_packet ( const struct smsc9220_eth_dev_t* dev, - uint32_t total_payload_length, - bool is_new_packet, - const char *data, uint32_t current_size) + void *data, uint32_t dlen) { struct smsc9220_eth_reg_map_t* register_map = (struct smsc9220_eth_reg_map_t*)dev->cfg->base; - bool is_first_segment = false; - bool is_last_segment = false; - uint32_t txcmd_a, txcmd_b = 0; + uint32_t txcmd_a = 0, txcmd_b = 0; uint32_t tx_buffer_free_space = 0; - volatile uint32_t xmit_stat = 0; if (!data) { return SMSC9220_ERROR_PARAM; } - if (is_new_packet) { - is_first_segment = true; - dev->data->ongoing_packet_length = total_payload_length; - dev->data->ongoing_packet_length_sent = 0; - } else if (dev->data->ongoing_packet_length != total_payload_length || - dev->data->ongoing_packet_length_sent >= total_payload_length) { - return SMSC9220_ERROR_PARAM; - } - /* Would next chunk fit into buffer? */ tx_buffer_free_space = GET_BIT_FIELD(register_map->tx_fifo_inf, FIFO_USED_SPACE_MASK, DATA_FIFO_USED_SPACE_POS); - if (current_size > tx_buffer_free_space) { + if (dlen > tx_buffer_free_space) { return SMSC9220_ERROR_INTERNAL; /* Not enough space in FIFO */ } - if ((dev->data->ongoing_packet_length_sent + current_size) == - total_payload_length) { - is_last_segment = true; - } - - txcmd_a = 0; - txcmd_b = 0; - - if (is_last_segment) { - SET_BIT(txcmd_a, TX_COMMAND_A_LAST_SEGMENT_INDEX); - } - if (is_first_segment) { - SET_BIT(txcmd_a, TX_COMMAND_A_FIRST_SEGMENT_INDEX); - } - - uint32_t data_start_offset_bytes = (4 - (current_size % 4)); - - SET_BIT_FIELD(txcmd_a, TX_CMD_PKT_LEN_BYTES_MASK, 0, current_size); - SET_BIT_FIELD(txcmd_a, TX_CMD_DATA_START_OFFSET_BYTES_MASK, - TX_CMD_DATA_START_OFFSET_BYTES_POS, - data_start_offset_bytes); - - SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_LEN_BYTES_MASK, 0, current_size); - SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_TAG_MASK, TX_CMD_PKT_TAG_POS, - current_size); + SET_BIT(txcmd_a, TX_COMMAND_A_LAST_SEGMENT_INDEX); + SET_BIT(txcmd_a, TX_COMMAND_A_FIRST_SEGMENT_INDEX); + SET_BIT_FIELD(txcmd_a, TX_CMD_PKT_LEN_BYTES_MASK, 0, dlen); + SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_LEN_BYTES_MASK, 0, dlen); + SET_BIT_FIELD(txcmd_b, TX_CMD_PKT_TAG_MASK, TX_CMD_PKT_TAG_POS, dlen); register_map->tx_data_port = txcmd_a; register_map->tx_data_port = txcmd_b; - fill_tx_fifo(dev, (uint8_t *)data, current_size); - - if (is_last_segment) { - /* Pop status port for error check */ - xmit_stat = register_map->tx_status_port; - (void)xmit_stat; + /* Ethernet data port is padding to 32bit aligned data */ + uint32_t dwords_to_write = (dlen + 3) >> 2; + uint32_t *data_ptr = (uint32_t *) data; + for(uint32_t i = 0; i < dwords_to_write; i++) { + register_map->tx_data_port = data_ptr[i]; } - dev->data->ongoing_packet_length_sent += current_size; + + /* Pop status port for error check */ + (void) (register_map->tx_status_port); + return SMSC9220_ERROR_NONE; } @@ -1033,10 +934,9 @@ uint32_t smsc9220_get_rxfifo_data_used_space(const struct DATA_FIFO_USED_SPACE_POS); } -uint32_t smsc9220_receive_by_chunks(const struct smsc9220_eth_dev_t* dev, - char *data, uint32_t dlen) +uint32_t smsc9220_receive_packet(const struct smsc9220_eth_dev_t* dev, + void *data) { - uint32_t rxfifo_inf = 0; uint32_t rxfifo_stat = 0; uint32_t packet_length_byte = 0; struct smsc9220_eth_reg_map_t* register_map = @@ -1045,22 +945,22 @@ uint32_t smsc9220_receive_by_chunks(const struct smsc9220_eth_dev_t* dev, if (!data) { return 0; /* Invalid input parameter, cannot read */ } - rxfifo_inf = register_map->rx_fifo_inf; - - if(rxfifo_inf & 0xFFFF) { /* If there's data */ - rxfifo_stat = register_map->rx_status_port; - if(rxfifo_stat != 0) { /* Fetch status of this packet */ - /* Ethernet controller is padding to 32bit aligned data */ - packet_length_byte = GET_BIT_FIELD(rxfifo_stat, - RX_FIFO_STATUS_PKT_LENGTH_MASK, - RX_FIFO_STATUS_PKT_LENGTH_POS); - packet_length_byte -= 4; - dev->data->current_rx_size_words = packet_length_byte; - } + + /* Status port not empty from smsc9220_peek_next_packet_size */ + rxfifo_stat = register_map->rx_status_port; + packet_length_byte = GET_BIT_FIELD(rxfifo_stat, + RX_FIFO_STATUS_PKT_LENGTH_MASK, + RX_FIFO_STATUS_PKT_LENGTH_POS); + packet_length_byte -= 4; /* Discard last word (CRC) */ + + /* Ethernet data port is padding to 32bit aligned data */ + uint32_t dwords_to_read = (packet_length_byte + 3) >> 2; + uint32_t *data_ptr = (uint32_t *) data; + for(uint32_t i = 0; i < dwords_to_read; i++) { + data_ptr[i] = register_map->rx_data_port; } + (void) (register_map->rx_data_port); /* Discard last word (CRC) */ - empty_rx_fifo(dev, (uint8_t *)data, packet_length_byte); - dev->data->current_rx_size_words = 0; return packet_length_byte; } diff --git a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h index 073b84e2e7f..93f135db2d7 100644 --- a/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h +++ b/targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/device/drivers/smsc9220_eth_drv.h @@ -480,40 +480,34 @@ uint32_t smsc9220_get_tx_data_fifo_size(const struct /** * \brief Sends data from the given buffer as an Ethernet packet. - * The full packet length must be specified at the beginning - * of a new packet transmission. + * The data to send must be a full packet. * * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t - * \param[in] total_payload_length Length of the ethernet payload. - * Should be equal to the sum of passed buffers within a packet. - * \param[in] is_new_packet Should be set to true if the input buffer has to - * be sent as the start of a new packet or as a full packet. - * \param[in] data Pointer to the data buffer to be sent. - * \param[in] current_size Size of the data in bytes. + * \param[in] data Pointer to the word aligned packet buffer to be sent. + * \param[in] dlen Size of the packet in bytes. * * \return error code /ref smsc9220_error_t */ -enum smsc9220_error_t smsc9220_send_by_chunks( +enum smsc9220_error_t smsc9220_send_packet( const struct smsc9220_eth_dev_t* dev, - uint32_t total_payload_length, - bool is_new_packet, - const char *data, uint32_t current_size); + void *data, uint32_t dlen); /** * \brief Reads an incoming Ethernet packet into the given buffer. * Stops reading at packet border. * * \param[in] dev Ethernet device structure \ref smsc9220_eth_dev_t - * \param[in,out] data Pointer to a pre-allocated input buffer. - * Allocating sufficient memory space is the caller's + * \param[in,out] data Pointer to a pre-allocated word aligned input buffer. + * Availability of packets, as well as, alignment and + * allocating sufficient memory space is the caller's * responsibility, which is typically done by calling * \ref smsc9220_peek_next_packet_size. - * \param[in] dlen Length of the allocated data in bytes. * * \return Number of bytes read from the Rx FIFO into the given buffer. */ -uint32_t smsc9220_receive_by_chunks(const struct smsc9220_eth_dev_t* dev, - char *data, uint32_t dlen); +uint32_t smsc9220_receive_packet( + const struct smsc9220_eth_dev_t* dev, + void *data); /** * \brief Get the used space of Rx fifo in bytes. diff --git a/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt b/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt index cc56e6c42ac..03a40ec15af 100644 --- a/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt +++ b/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/CMakeLists.txt @@ -51,6 +51,7 @@ target_sources(mbed-apollo3 device/sleep.c device/spi_api.c device/us_ticker.c + device/itm_api.c sdk/CMSIS/AmbiqMicro/Source/system_apollo3.c diff --git a/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/itm_api.c b/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/itm_api.c new file mode 100644 index 00000000000..8ecace91202 --- /dev/null +++ b/targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/itm_api.c @@ -0,0 +1,48 @@ +/* mbed Microcontroller Library + * Copyright (c) 2017 ARM Limited + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if DEVICE_ITM + +#include "hal/itm_api.h" +#include "cmsis.h" +#include "am_bsp.h" + +#include + +/* SWO frequency: 1000 kHz */ + +#ifndef AM_BSP_GPIO_ITM_SWO +#define AM_GPIO_ITM_SWO 22 + +const am_hal_gpio_pincfg_t g_AM_GPIO_ITM_SWO = +{ + .uFuncSel = AM_HAL_PIN_22_SWO, + .eDriveStrength = AM_HAL_GPIO_PIN_DRIVESTRENGTH_2MA +}; +#endif + + +void itm_init(void) +{ + #ifdef AM_BSP_GPIO_ITM_SWO + am_bsp_itm_printf_enable(); + #else + am_bsp_itm_printf_enable(AM_GPIO_ITM_SWO,g_AM_GPIO_ITM_SWO); + #endif +} + +#endif diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F411xE/TARGET_MTS_MDOT_F411RE/system_clock.c b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F411xE/TARGET_MTS_MDOT_F411RE/system_clock.c new file mode 100644 index 00000000000..3b5235d1d73 --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F411xE/TARGET_MTS_MDOT_F411RE/system_clock.c @@ -0,0 +1,198 @@ +/* mbed Microcontroller Library + * SPDX-License-Identifier: BSD-3-Clause + ****************************************************************************** + * + * Copyright (c) 2015-2021 STMicroelectronics. + * All rights reserved. + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/** + * This file configures the system clock as follows: + *----------------------------------------------------------------------------- + * System clock source | 1- USE_PLL_HSE_EXTC (external 8 MHz clock) | DEVICE_USBDEVICE=1 + * | 2- USE_PLL_HSE_XTAL (external 8 MHz xtal) | + * | 3- USE_PLL_HSI (internal 16 MHz) | + *----------------------------------------------------------------------------- + * SYSCLK(MHz) | 100 | 96 + * AHBCLK (MHz) | 100 | 96 + * APB1CLK (MHz) | 50 | 48 + * APB2CLK (MHz) | 100 | 96 + * USB capable | NO | YES + *----------------------------------------------------------------------------- +**/ + +#include "stm32f4xx.h" +#include "mbed_error.h" + +// clock source is selected with CLOCK_SOURCE in json config +#define USE_PLL_HSE_EXTC 0x8 // Use external clock (ST Link MCO) +#define USE_PLL_HSE_XTAL 0x4 // Use external xtal (X3 on board - not provided by default) +#define USE_PLL_HSI 0x2 // Use HSI internal clock + +#if ( ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) ) +uint8_t SetSysClock_PLL_HSE(uint8_t bypass); +#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */ + +#if ((CLOCK_SOURCE) & USE_PLL_HSI) +uint8_t SetSysClock_PLL_HSI(void); +#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */ + + +/** +* @brief Configures the System clock source, PLL Multiplier and Divider factors, +* AHB/APBx prescalers and Flash settings +* @note This function should be called only once the RCC clock configuration +* is reset to the default reset state (done in SystemInit() function). + * @param None + * @retval None + */ + +MBED_WEAK void SetSysClock(void) +{ +#if ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) + /* 1- Try to start with HSE and external clock */ + if (SetSysClock_PLL_HSE(1) == 0) +#endif + { +#if ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) + /* 2- If fail try to start with HSE and external xtal */ + if (SetSysClock_PLL_HSE(0) == 0) +#endif + { +#if ((CLOCK_SOURCE) & USE_PLL_HSI) + /* 3- If fail start with HSI clock */ + if (SetSysClock_PLL_HSI() == 0) +#endif + { + { + error("SetSysClock failed\n"); + } + } + } + } + + /* Output clock on MCO2 pin(PC9) for debugging purpose */ + //HAL_RCC_MCOConfig(RCC_MCO2, RCC_MCO2SOURCE_SYSCLK, RCC_MCODIV_4); +} + +#if ( ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) ) +/******************************************************************************/ +/* PLL (clocked by HSE) used as System clock source */ +/******************************************************************************/ +MBED_WEAK uint8_t SetSysClock_PLL_HSE(uint8_t bypass) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); + + /* Get the Clocks configuration according to the internal RCC registers */ + HAL_RCC_GetOscConfig(&RCC_OscInitStruct); + + /* PLL could be already configured by bootlader */ + if (RCC_OscInitStruct.PLL.PLLState != RCC_PLL_ON) { + + // Enable HSE oscillator and activate PLL with HSE as source + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + if (bypass == 0) { + RCC_OscInitStruct.HSEState = RCC_HSE_ON; // External 8 MHz xtal on OSC_IN/OSC_OUT + } else { + RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS; // External 8 MHz clock on OSC_IN + } + + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = HSE_VALUE / 1000000; // VCO input clock +#if (DEVICE_USBDEVICE) + RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 384 MHz (2 MHz * 192) +#else /* DEVICE_USBDEVICE */ + RCC_OscInitStruct.PLL.PLLN = 200; // VCO output clock = 400 MHz (2 MHz * 200) +#endif /* DEVICE_USBDEVICE */ + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; // PLLCLK = 100 MHz or 96 MHz (depending on DEVICE_USBDEVICE) + RCC_OscInitStruct.PLL.PLLQ = 4; // USB clock = 48 MHz (DEVICE_USBDEVICE=1) + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + return 0; // FAIL + } + } + + // Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; // 100/96 MHz + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; // 100/96 MHz + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; // 50/48 MHz + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; // 100/96 MHz + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { + return 0; // FAIL + } + + /* Output clock on MCO1 pin(PA8) for debugging purpose */ + //if (bypass == 0) + // HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_2); // 4 MHz with xtal + //else + // HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSE, RCC_MCODIV_1); // 8 MHz with external clock + + return 1; // OK +} +#endif /* ((CLOCK_SOURCE) & USE_PLL_HSE_XTAL) || ((CLOCK_SOURCE) & USE_PLL_HSE_EXTC) */ + +#if ((CLOCK_SOURCE) & USE_PLL_HSI) +/******************************************************************************/ +/* PLL (clocked by HSI) used as System clock source */ +/******************************************************************************/ +uint8_t SetSysClock_PLL_HSI(void) +{ + RCC_OscInitTypeDef RCC_OscInitStruct; + RCC_ClkInitTypeDef RCC_ClkInitStruct; + + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_RCC_PWR_CLK_ENABLE(); + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); + + // Enable HSI oscillator and activate PLL with HSI as source + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI | RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSEState = RCC_HSE_OFF; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLM = 8; // VCO input clock = 2 MHz (16 MHz / 8) +#if (DEVICE_USBDEVICE) + RCC_OscInitStruct.PLL.PLLN = 192; // VCO output clock = 384 MHz (2 MHz * 192) +#else /* DEVICE_USBDEVICE */ + RCC_OscInitStruct.PLL.PLLN = 200; // VCO output clock = 400 MHz (2 MHz * 200) +#endif /* DEVICE_USBDEVICE */ + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; // PLLCLK = 100 MHz or 96 MHz (depending on DEVICE_USBDEVICE) + RCC_OscInitStruct.PLL.PLLQ = 8; // USB clock = 48 MHz (DEVICE_USBDEVICE=1) + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { + return 0; // FAIL + } + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK) { + return 0; // FAIL + } + + /* Output clock on MCO1 pin(PA8) for debugging purpose */ + //HAL_RCC_MCOConfig(RCC_MCO1, RCC_MCO1SOURCE_HSI, RCC_MCODIV_1); // 16 MHz + + return 1; // OK +} +#endif /* ((CLOCK_SOURCE) & USE_PLL_HSI) */ diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct index 7aff08bc288..827b6a92d91 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_ARM/stm32f412xe.sct @@ -37,6 +37,14 @@ /* Round up VECTORS_SIZE to 8 bytes */ #define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) AND ~7) +#define MBED_CRASH_REPORT_RAM_SIZE 0x100 + +#define MBED_IRAM1_START (MBED_RAM_START + VECTORS_SIZE + MBED_CRASH_REPORT_RAM_SIZE) +#define MBED_IRAM1_SIZE (MBED_RAM_SIZE - VECTORS_SIZE - MBED_CRASH_REPORT_RAM_SIZE) + + +#define RAM_FIXED_SIZE (MBED_CONF_TARGET_BOOT_STACK_SIZE + VECTORS_SIZE + MBED_CRASH_REPORT_RAM_SIZE) + LR_IROM1 MBED_APP_START MBED_APP_SIZE { ER_IROM1 MBED_APP_START MBED_APP_SIZE { @@ -45,11 +53,14 @@ LR_IROM1 MBED_APP_START MBED_APP_SIZE { .ANY (+RO) } - RW_IRAM1 (MBED_RAM_START + VECTORS_SIZE) { ; RW data - .ANY (+RW +ZI) + RW_m_crash_data (MBED_RAM_START + VECTORS_SIZE) EMPTY MBED_CRASH_REPORT_RAM_SIZE { ; RW data + } + + RW_IRAM1 MBED_IRAM1_START MBED_IRAM1_SIZE { ; RW data + .ANY (+RW +ZI) } - ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_RAM_START + MBED_RAM_SIZE - MBED_CONF_TARGET_BOOT_STACK_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up + ARM_LIB_HEAP AlignExpr(+0, 16) EMPTY (MBED_IRAM1_START + MBED_RAM_SIZE - RAM_FIXED_SIZE - AlignExpr(ImageLimit(RW_IRAM1), 16)) { ; Heap growing up } ARM_LIB_STACK (MBED_RAM_START + MBED_RAM_SIZE) EMPTY -MBED_CONF_TARGET_BOOT_STACK_SIZE { ; Stack region growing down diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld index 5f479936c85..7acf3c6bc3d 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_GCC_ARM/stm32f412xe.ld @@ -35,6 +35,8 @@ /* Round up VECTORS_SIZE to 8 bytes */ #define VECTORS_SIZE (((NVIC_NUM_VECTORS * 4) + 7) & 0xFFFFFFF8) +M_CRASH_DATA_RAM_SIZE = 0x100; + MEMORY { FLASH (rx) : ORIGIN = MBED_APP_START, LENGTH = MBED_APP_SIZE @@ -114,6 +116,18 @@ SECTIONS __etext = .; _sidata = .; + .crash_data_ram : + { + . = ALIGN(8); + __CRASH_DATA_RAM__ = .; + __CRASH_DATA_RAM_START__ = .; /* Create a global symbol at data start */ + KEEP(*(.keep.crash_data_ram)) + *(.m_crash_data_ram) /* This is a user defined section */ + . += M_CRASH_DATA_RAM_SIZE; + . = ALIGN(8); + __CRASH_DATA_RAM_END__ = .; /* Define a global symbol at data end */ + } > RAM + .data : AT (__etext) { __data_start__ = .; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf index 6a3021d3bf3..940f6ced874 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/TOOLCHAIN_IAR/stm32f412xe.icf @@ -39,8 +39,13 @@ if (!isdefinedsymbol(MBED_CONF_TARGET_BOOT_STACK_SIZE)) { /* Round up VECTORS_SIZE to 8 bytes */ define symbol VECTORS_SIZE = ((VECTORS * 4) + 7) & ~7; -define symbol RAM_REGION_START = MBED_RAM_START + VECTORS_SIZE; -define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE; + +define symbol CRASH_DATA_START = MBED_RAM_START + VECTORS_SIZE; +define symbol CRASH_DATA_SIZE = 0x100; +define exported symbol __CRASH_DATA_RAM_START__ = CRASH_DATA_START; + +define symbol RAM_REGION_START = CRASH_DATA_START + CRASH_DATA_SIZE; +define symbol RAM_REGION_SIZE = MBED_RAM_SIZE - VECTORS_SIZE - CRASH_DATA_SIZE; define memory mem with size = 4G; define region ROM_region = mem:[from MBED_APP_START size MBED_APP_SIZE]; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h new file mode 100644 index 00000000000..6fca0192c4d --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F412xE/flash_data.h @@ -0,0 +1,55 @@ +/* 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. + ******************************************************************************* + */ +#ifndef MBED_FLASH_DATA_H +#define MBED_FLASH_DATA_H + +#include "device.h" +#include + +#if DEVICE_FLASH + +/* Exported types ------------------------------------------------------------*/ +/* Exported constants --------------------------------------------------------*/ +/* Exported macro ------------------------------------------------------------*/ +/* Flash size */ +#define FLASH_SIZE (uint32_t) 0x80000 // 512 KB + +/* Base address of the Flash sectors Bank 1 */ +#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */ +#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */ +#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */ +#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */ + +#endif +#endif diff --git a/targets/TARGET_STM/serial_api.c b/targets/TARGET_STM/serial_api.c index c805669331e..b7ce63f546e 100644 --- a/targets/TARGET_STM/serial_api.c +++ b/targets/TARGET_STM/serial_api.c @@ -629,8 +629,12 @@ HAL_StatusTypeDef init_uart(serial_t *obj) #if defined(UART_ONE_BIT_SAMPLE_DISABLE) // F0/F3/F7/G0/H7/L0/L4/L5/WB huart->Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; #endif -#if defined(UART_PRESCALER_DIV1) // G0/H7/L4/L5/WB - huart->Init.ClockPrescaler = UART_PRESCALER_DIV1; +#if defined(UART_PRESCALER_DIV1) // G0/G4/H7/L4/L5/U5/WB/WL + if (obj_s->baudrate < 4800) { + huart->Init.ClockPrescaler = UART_PRESCALER_DIV16; + } else { + huart->Init.ClockPrescaler = UART_PRESCALER_DIV1; + } #endif #if defined(UART_ADVFEATURE_NO_INIT) // F0/F3/F7/G0/H7/L0/L4//5/WB huart->AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; diff --git a/targets/targets.json b/targets/targets.json index 86a38cba728..0da7d42eac5 100644 --- a/targets/targets.json +++ b/targets/targets.json @@ -1900,7 +1900,7 @@ "HSE_VALUE=26000000" ], "overrides": { - "clock_source": "USE_PLL_HSI" + "clock_source": "USE_PLL_HSE_XTAL" }, "components_remove": [ "FLASHIAP" @@ -1914,6 +1914,22 @@ "0320" ] }, + "MCU_STM32F412xE": { + "inherits": [ + "MCU_STM32F4" + ], + "public": false, + "extra_labels_add": [ + "STM32F412xE" + ], + "macros_add": [ + "STM32F412Zx" + ], + "device_has_add": [ + "CAN", + "TRNG" + ] + }, "MCU_STM32F412xG": { "inherits": [ "MCU_STM32F4" @@ -9065,7 +9081,8 @@ "FLASH", "SPI", "I2C", - "SLEEP" + "SLEEP", + "ITM" ], "components": [ "FLASHIAP" diff --git a/tools/cmake/UploadMethodManager.cmake b/tools/cmake/UploadMethodManager.cmake index ae9784263ea..339f515f2e3 100644 --- a/tools/cmake/UploadMethodManager.cmake +++ b/tools/cmake/UploadMethodManager.cmake @@ -46,7 +46,10 @@ set(MBED_UPLOAD_SUPPORTS_DEBUG ${UPLOAD_SUPPORTS_DEBUG} CACHE INTERNAL "" FORCE) function(mbed_generate_upload_debug_targets target) # add upload target - gen_upload_target(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex) + gen_upload_target(${target} + ${CMAKE_CURRENT_BINARY_DIR}/$.bin + ${CMAKE_CURRENT_BINARY_DIR}/$.hex + ) # add debug target if(MBED_UPLOAD_SUPPORTS_DEBUG) diff --git a/tools/cmake/mbed_set_post_build.cmake b/tools/cmake/mbed_set_post_build.cmake index 7b78982d7c9..d33ba00ca79 100644 --- a/tools/cmake/mbed_set_post_build.cmake +++ b/tools/cmake/mbed_set_post_build.cmake @@ -6,32 +6,35 @@ # function(mbed_generate_bin_hex target) get_property(elf_to_bin GLOBAL PROPERTY ELF2BIN) + + set(artifact_name $) + if (MBED_TOOLCHAIN STREQUAL "GCC_ARM") # The first condition is quoted in case MBED_OUTPUT_EXT is unset if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} -O binary $ ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" + COMMAND ${elf_to_bin} -O binary $ ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin" ) endif() if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} -O ihex $ ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" + COMMAND ${elf_to_bin} -O ihex $ ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex" ) endif() elseif(MBED_TOOLCHAIN STREQUAL "ARM") get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER) if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "bin") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin $ - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.bin" + COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --bin -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin $ + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.bin" ) endif() if ("${MBED_OUTPUT_EXT}" STREQUAL "" OR MBED_OUTPUT_EXT STREQUAL "hex") list(APPEND CMAKE_POST_BUILD_COMMAND - COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex $ - COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${target}.hex" + COMMAND ${elf_to_bin} ${mbed_studio_arm_compiler} --i32combined -o ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex $ + COMMAND ${CMAKE_COMMAND} -E echo "-- built: ${CMAKE_CURRENT_BINARY_DIR}/${artifact_name}.hex" ) endif() endif()