Skip to content

STM32H7: FDCAN: use PLL1Q frequency for calculations - Part 2 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5ec0afa
STM32: USBPhy: enable HS clock sleep
facchinm Oct 28, 2020
1e5f463
STM32H747xI: allow overriding SetSysClock
facchinm Oct 28, 2020
acc18e3
STM32: QSPI: allow setting SAMPLE_SHIFTING mode
facchinm Oct 28, 2020
40a6ce2
STM32H7: DualCore: allow no forced CM4 boot
facchinm Oct 28, 2020
07b7800
STM32H7: dual core: handle interrupts on CM4
facchinm Oct 8, 2020
5090d13
STM32: EMAC: allow compiling on MCUs without DCACHE
facchinm Oct 28, 2020
caa47c5
Add Arduino Portenta H7 target
facchinm Oct 28, 2020
2be3df0
lwip: use adeguate mem-size for Portenta H7
facchinm Oct 28, 2020
67a7c96
PortentaH7: add Ethernet support
facchinm Oct 28, 2020
ea877a8
Portenta: enable ETH power supply
pennam Nov 11, 2020
6d663bf
Fix missing licenses for Arduino original code
facchinm Nov 2, 2020
6363d42
Add SPDX-License
facchinm Nov 13, 2020
9c8405a
[Portenta] Add Cmake rules
facchinm Nov 23, 2020
011ce31
WHD: make independent from TARGET_Cypress
facchinm Oct 28, 2020
897b9a5
Import WHD component from TARGET_PSOC6
facchinm Oct 28, 2020
1f15c1a
Portenta: WHD: remove unnecessary firmwares
facchinm Oct 28, 2020
d28ee58
WHD: port to STM32H7 SDIO interface
facchinm Oct 28, 2020
4043d60
PortentaH7: enable WiFi
facchinm Oct 28, 2020
d379093
STM32: include QSPI HAL in build
facchinm Oct 28, 2020
987b432
Portenta: WHD: store WLAN firmware in filesystem
facchinm Oct 28, 2020
3282729
Portenta: enable certificates in filesystem
facchinm Oct 28, 2020
83891e3
CYW43XXX: make transport layer generic
facchinm Oct 28, 2020
9f9797f
BLE: CYW43XXX: set default baud rate on init()
facchinm Oct 29, 2020
beb9422
PortentaH7: add BLE support
facchinm Oct 28, 2020
d8307bc
I2CSlave.read(buf, count) returns the number of bytes actually read
facchinm Apr 1, 2020
3708100
Arduino_NANO33BLE: don't define Arduino pins if compiling in Arduino …
facchinm Mar 12, 2020
7425a9e
Add AnalogIn configure function
polldo May 13, 2020
ed825d7
HACK: avoid #10862 by not firing the assert
facchinm Jul 31, 2019
74711da
BlockDevices: specify mbed namespace where needed
facchinm Oct 4, 2019
54e6690
portentaH7: Change BLE public address
polldo Oct 29, 2020
f47383f
TLSSocketWrapper: add method to retrieve certificates from filesystem
facchinm Nov 9, 2020
2308304
TLSSocketWrapper: Add unit test for set_root_ca_cert_path
facchinm Nov 9, 2020
68b013a
TLSSocketWrapper: add test for certificates stored in filesystem
facchinm Nov 9, 2020
a580b77
STM32: Compute I2C timing according current I2C clock source and requ…
pennam Nov 16, 2020
b57c686
Increase Cordio memory pool for nRF52832
facchinm Nov 27, 2020
b38a822
SleepTracing: don't spam logs if no lock is held
facchinm Nov 27, 2020
14b743d
nRF52: properly clean pwm structures on deinit()
facchinm Dec 1, 2020
522ebb4
STM32H7: FDCAN: use PLL1Q frequency for calculations
facchinm Dec 3, 2020
9602524
STM32H7: FDCAN: use PLL1Q frequency for calculations - Part 2
manchoz Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "CyH4TransportDriver.h"
#include "mbed_power_mgmt.h"
#include "drivers/InterruptIn.h"
#include "cybsp_types.h"
#include "Callback.h"
#include "rtos/ThisThread.h"
#include <chrono>
Expand All @@ -32,28 +31,26 @@ namespace cypress_ble {
using namespace std::chrono_literals;

CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud, PinName bt_host_wake_name, PinName bt_device_wake_name, uint8_t host_wake_irq, uint8_t dev_wake_irq) :
cts(cts), rts(rts),
uart(tx, rx), cts(cts), rts(rts),
bt_host_wake_name(bt_host_wake_name),
bt_device_wake_name(bt_device_wake_name),
bt_host_wake(bt_host_wake_name, PIN_INPUT, PullNone, 0),
bt_device_wake(bt_device_wake_name, PIN_OUTPUT, PullNone, 1),
host_wake_irq_event(host_wake_irq),
dev_wake_irq_event(dev_wake_irq)
{
cyhal_uart_init(&uart, tx, rx, NULL, NULL);
enabled_powersave = true;
bt_host_wake_active = false;
}

CyH4TransportDriver::CyH4TransportDriver(PinName tx, PinName rx, PinName cts, PinName rts, int baud) :
cts(cts),
uart(tx, rx), cts(cts),
rts(rts),
bt_host_wake_name(NC),
bt_device_wake_name(NC),
bt_host_wake(bt_host_wake_name),
bt_device_wake(bt_device_wake_name)
{
cyhal_uart_init(&uart, tx, rx, NULL, NULL);
enabled_powersave = false;
bt_host_wake_active = false;
sleep_manager_lock_deep_sleep();
Expand Down Expand Up @@ -101,16 +98,15 @@ void CyH4TransportDriver::bt_host_wake_fall_irq_handler(void)
}
}

static void on_controller_irq(void *callback_arg, cyhal_uart_event_t event)
void CyH4TransportDriver::on_controller_irq()
{
(void)(event);
cyhal_uart_t *uart_obj = (cyhal_uart_t *)callback_arg;
sleep_manager_lock_deep_sleep();

while (cyhal_uart_readable(uart_obj)) {
while (uart.readable()) {
uint8_t char_received;
cyhal_uart_getc(uart_obj, &char_received, 0);
CyH4TransportDriver::on_data_received(&char_received, 1);
if (uart.read(&char_received, 1)) {
CordioHCITransportDriver::on_data_received(&char_received, 1);
}
}

sleep_manager_unlock_deep_sleep();
Expand All @@ -124,11 +120,24 @@ void CyH4TransportDriver::initialize()

sleep_manager_lock_deep_sleep();

const cyhal_uart_cfg_t uart_cfg = { .data_bits = 8, .stop_bits = 1, .parity = CYHAL_UART_PARITY_NONE, .rx_buffer = NULL, .rx_buffer_size = 0 };
cyhal_uart_configure(&uart, &uart_cfg);
cyhal_uart_set_flow_control(&uart, cts, rts);
cyhal_uart_register_callback(&uart, &on_controller_irq, &uart);
cyhal_uart_enable_event(&uart, CYHAL_UART_IRQ_RX_NOT_EMPTY, CYHAL_ISR_PRIORITY_DEFAULT, true);
uart.baud(DEF_BT_BAUD_RATE);

uart.format(
/* bits */ 8,
/* parity */ mbed::SerialBase::None,
/* stop bit */ 1
);

uart.set_flow_control(
/* flow */ mbed::SerialBase::RTSCTS,
/* rts */ rts,
/* cts */ cts
);

uart.attach(
mbed::callback(this, &CyH4TransportDriver::on_controller_irq),
mbed::SerialBase::RxIrq
);

#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)
if (bt_host_wake_name != NC) {
Expand Down Expand Up @@ -160,11 +169,11 @@ uint16_t CyH4TransportDriver::write(uint8_t type, uint16_t len, uint8_t *pData)

while (i < len + 1) {
uint8_t to_write = i == 0 ? type : pData[i - 1];
while (cyhal_uart_writable(&uart) == 0);
cyhal_uart_putc(&uart, to_write);
while (uart.writeable() == 0);
uart.write(&to_write, 1);
++i;
}
while(cyhal_uart_is_tx_active(&uart));
while (uart.writeable() == 0);

deassert_bt_dev_wake();
sleep_manager_unlock_deep_sleep();
Expand Down Expand Up @@ -200,8 +209,7 @@ void CyH4TransportDriver::deassert_bt_dev_wake()

void CyH4TransportDriver::update_uart_baud_rate(int baud)
{
uint32_t ignore;
cyhal_uart_set_baud(&uart, (uint32_t)baud, &ignore);
uart.baud((uint32_t)baud);
}

bool CyH4TransportDriver::get_enabled_powersave()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdint.h>
#include "ble/driver/CordioHCITransportDriver.h"
#include "drivers/DigitalInOut.h"
#include "cyhal_uart.h"
#include "drivers/UnbufferedSerial.h"

namespace ble {
namespace vendor {
Expand Down Expand Up @@ -80,6 +80,7 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
private:
void assert_bt_dev_wake();
void deassert_bt_dev_wake();
void on_controller_irq();

// Use HAL serial because Cypress UART is buffered.
// The PUTC function does not actually blocks until data is fully transmitted,
Expand All @@ -88,8 +89,7 @@ class CyH4TransportDriver : public CordioHCITransportDriver {
// However UART APIs does not prevent the BT radio from going to sleep.
// Use the HAL APIs to prevent the radio from going to sleep until UART transmition is complete.
// Mbed layer has no API that distinguish between data in HW buffer v.s. data already transmitted.

cyhal_uart_t uart;
mbed::UnbufferedSerial uart;
PinName cts;
PinName rts;
PinName bt_host_wake_name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,24 @@ class HCIDriver : public CordioHCIDriver {
#endif /* BT_UART_NO_3M_SUPPORT */
}

void inject_bdaddr(uint8_t* pBuf)
{
if (service_pack_ptr + service_pack_index == brcm_patchram_buf) {
uint8_t bdAddr[6] = { 0xFF, 0xFF, 0xFF, 0x0A, 0x61, 0xA8 };
uint32_t uniqueId = HAL_GetUIDw0() ^ HAL_GetUIDw1() ^ HAL_GetUIDw2();
memcpy(bdAddr, &uniqueId, 3);
memcpy(&pBuf[33], bdAddr, sizeof(bdAddr));
}
}

void send_service_pack_command(void)
{
uint16_t cmd_len = service_pack_ptr[service_pack_index + 2];
uint16_t cmd_opcode = (service_pack_ptr[service_pack_index + 1] << 8) | service_pack_ptr[service_pack_index + 0];
uint8_t *pBuf = hciCmdAlloc(cmd_opcode, cmd_len);
if (pBuf) {
memcpy(pBuf + HCI_CMD_HDR_LEN, service_pack_ptr + service_pack_index + HCI_CMD_HDR_LEN, cmd_len);
inject_bdaddr(pBuf);
hciCmdSend(pBuf);
} else {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*******************************************************************************
* \file cy_bt_cordio_cfg.cpp
* \version 1.0
*
*
* Low Power Assist BT Pin configuration implementation.
*
********************************************************************************
* \copyright
* Copyright 2019 Cypress Semiconductor Corporation
* 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.
*******************************************************************************/

#include <stdio.h>
#include "ble/driver/CordioHCIDriver.h"
#include "hci_api.h"
#include "hci_cmd.h"
#include "hci_core.h"
#include "bstream.h"
#include "assert.h"
#include <stdbool.h>
#include "hci_mbed_os_adaptation.h"
#include "CyH4TransportDriver.h"

#define cyhal_gpio_to_rtos(x) (x)
#define CYCFG_BT_LP_ENABLED (1)
#define CYCFG_BT_HOST_WAKE_IRQ_EVENT WAKE_EVENT_ACTIVE_LOW
#define CYCFG_BT_DEV_WAKE_POLARITY WAKE_EVENT_ACTIVE_LOW

/*******************************************************************************
* Function Name: ble_cordio_get_h4_transport_driver
********************************************************************************
*
* Strong implementation of function which calls CyH4TransportDriver constructor and return it
*
* \param none
*
* \return
* Returns the transport driver object
*******************************************************************************/
ble::vendor::cypress_ble::CyH4TransportDriver& ble_cordio_get_h4_transport_driver()
{
#if (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER)

#if (defined(CYCFG_BT_LP_ENABLED))
if (CYCFG_BT_LP_ENABLED) {
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS), DEF_BT_BAUD_RATE,
cyhal_gpio_to_rtos(CYBSP_BT_HOST_WAKE),
cyhal_gpio_to_rtos(CYBSP_BT_DEVICE_WAKE),
CYCFG_BT_HOST_WAKE_IRQ_EVENT,
CYCFG_BT_DEV_WAKE_POLARITY
);
return s_transport_driver;
} else { /* CYCFG_BT_LP_ENABLED */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS), DEF_BT_BAUD_RATE);
return s_transport_driver;
}
#else /* (defined(CYCFG_BT_LP_ENABLED)) */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS), DEF_BT_BAUD_RATE,
cyhal_gpio_to_rtos(CYBSP_BT_HOST_WAKE), cyhal_gpio_to_rtos(CYBSP_BT_DEVICE_WAKE)
);
return s_transport_driver;
#endif /* (defined(CYCFG_BT_LP_ENABLED)) */

#else /* (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER) */
static ble::vendor::cypress_ble::CyH4TransportDriver s_transport_driver(
/* TX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_TX),
/* RX */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RX),
/* cts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_CTS),
/* rts */ cyhal_gpio_to_rtos(CYBSP_BT_UART_RTS), DEF_BT_BAUD_RATE);
return s_transport_driver;
#endif /* (defined(MBED_TICKLESS) && DEVICE_SLEEP && DEVICE_LPTICKER) */
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ using namespace ble;

#else

#define CORDIO_LL_MEMORY_FOOTPRINT 12500UL
#define CORDIO_LL_MEMORY_FOOTPRINT 13000UL

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CyDhcpServer {
NetworkStack *_nstack = NULL;
NetworkInterface *_niface = NULL;
UDPSocket _socket;
Thread _thread;
rtos::Thread _thread;
bool _running = false;

cy_ip_addr_t _available_addr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "whd_emac.h"
#include "whd_wifi_api.h"
#include "whd_wlioctl.h"
#include "cy_utils.h"

#define CMP_MAC( a, b ) (((((unsigned char*)a)[0])==(((unsigned char*)b)[0]))&& \
((((unsigned char*)a)[1])==(((unsigned char*)b)[1]))&& \
Expand Down
Loading