update and NTP

This commit is contained in:
Martijn Scheepers
2024-06-26 12:27:08 +02:00
parent e128396e4b
commit db15b894b5
37 changed files with 2770 additions and 395 deletions

View File

@@ -43,13 +43,22 @@ def post_bin_action(source, target, env):
#print("prog_path:", env["PROG_PATH"])
#print("pioenv:", env["PIOENV"])
hashfile = os.path.join(env["PROJECT_BUILD_DIR"], env["PIOENV"], "firmware.hash")
hashfile = os.path.join(env["PROJECT_BUILD_DIR"], env["PIOENV"], "UPDATE.BIN.hash")
#print("dest:", hashfile)
fp = open(hashfile, 'w')
fp.write(hash)
fp.close()
for filename in os.listdir("data"):
hash = hashlib.md5(open(filename, 'rb').read()).hexdigest()
print(filename, " HASH:", hash)
#hashfile = os.path.join(env["PROJECT_BUILD_DIR"], env["PIOENV"], "UPDATE.BIN.hash")
#print("dest:", hashfile)
fp = open(hashfile + ".hash", 'w')
fp.write(hash)
fp.close()
#with open(bin_path, 'rb') as f_in:
# with gzip.open('firmware.bin.gz', 'wb') as f_out:
# shutil.copyfileobj(f_in, f_out)
@@ -57,7 +66,7 @@ def post_bin_action(source, target, env):
print("create tar file")
with tarfile.open("firmware.tar", "w", format=tarfile.GNU_FORMAT) as tar:
tar.add(bin_path, arcname="UPDATE.BIN")
tar.add(hashfile, arcname="firmware.hash")
tar.add(hashfile, arcname="UPDATE.BIN.hash")
#tar.add("data", arcname=os.path.basename("data"))
tar.add("data", arcname=os.path.basename(""))

View File

@@ -29,33 +29,33 @@
"QSPI_NO_SAMPLE_SHIFT",
"USE_FULL_LL_DRIVER",
"USE_HAL_DRIVER",
"MBED_TICKLESS"
"MBED_TICKLESS"
],
"features_add": [
],
"features_remove": [
],
"extra_labels_add": [
"extra_labels_add": [
],
"components_add": [
"QSPIF"
],
"components_remove":[
"FLASHIAP"
"FLASHIAP"
],
"device_has_add": [
"DIR",
"CRC",
"EMAC",
"EMAC",
"CRC",
"INTERRUPTIN",
"LPTICKER",
"MPU",
"PORTIN",
"PORTINOUT",
"PORTOUT",
"PORTOUT",
"QSPI",
"RESET_REASON",
"RTC",
"SLEEP",
"SERIAL",
"SERIAL_ASYNCH",
"SPI",
@@ -75,9 +75,8 @@
"ANALOGIN",
"PWMOUT",
"CAN",
"SERIAL_FC",
"SERIAL_FC",
"I2CSLAVE",
"SLEEP",
"FLASH"
],
"device_name": "STM32H747XIHx"

View File

@@ -17,6 +17,7 @@
<li class="navitem"><a class="active" href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -11,6 +11,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a class="active" href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -17,6 +17,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a class="active" href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -11,6 +11,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -25,6 +25,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -50,6 +50,7 @@ function UpdateInputState(jsonObj){
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a class="active" href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

50
data/ntp.html Normal file
View File

@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href="style.css">
<script type="text/javascript" src="page.js"></script>
<meta charset='UTF-8'>
<title>NTP Config</title>
</head>
<script>
window.onload = function() {
getPageContent("/ntp.json");
};
</script>
<body>
<ul class="navbar">
<li class="navitem"><a href="/"><h3>Home</h3></a></li>
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a class="active" href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>
<li class="navitem"><a href="help.html"><h3>Help</h3></a></li>
</ul>
<h1>NTP Config</h1>
<div id="main">
<form method='post' action='ntp'>
<div class="datafield">
<h2>NTP Settings</h2>
<div class="dataitem">
<label>NTP Server :</label>
<input id="ntpserver" name='ntpserver' maxlength='63' size='64' type='text'>
</div>
<div class="dataitem">
<label>NTP Server Port :</label>
<input id="ntpserverport" name='ntpserverport' min='0' max='65535' type='number'>
</div>
</div>
<div class='datafield'>
<div class="dataitem itemcenter saveconfig">
<input type='submit' value='Save Settings'>
</div>
</div>
</form>
</div>
</body>
</html>

View File

@@ -3,15 +3,34 @@ function getPageContent(url) {
return new Promise(function (resolve) {
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
//console.log(this.responseText);
console.log(this.responseText);
var jsonObj = JSON.parse(this.responseText);
for (var key in jsonObj) {
if (jsonObj.hasOwnProperty(key)) {
//console.log(key + ": " + jsonObj[key]);
console.log(key + ": " + jsonObj[key]);
if (document.getElementById(key)) {
console.log(key + ": " + typeof jsonObj[key]);
if (typeof jsonObj[key] === 'boolean') {
document.getElementById(key).checked = jsonObj[key];
}
else if (typeof jsonObj[key] === 'object') {
var list = jsonObj[key];
console.log(list);
var ul = document.getElementById(key);
console.log(ul);
for (var i = 0; i < list.length; i++) {
var name = list[i];
var li = document.createElement('li');
li.appendChild(document.createTextNode(name));
ul.appendChild(li);
}
}
else {
document.getElementById(key).value = jsonObj[key];
}

View File

@@ -11,6 +11,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a class="active" href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a href="update.html"><h3>Firmware Update</h3></a></li>

View File

@@ -37,7 +37,7 @@ h2{
margin: 5px;
padding: 0;
width: 200px;
height: 305px;
height: 355px;
background:#F1F3F4;
position: fixed;
overflow: auto;

View File

@@ -19,6 +19,7 @@
<li class="navitem"><a href="acs.html"><h3>ACS</h3></a></li>
<li class="navitem"><a href="inputs.html"><h3>Inputs / Outputs</h3></a></li>
<li class="navitem"><a href="credentials.html"><h3>Credentials</h3></a></li>
<li class="navitem"><a href="ntp.html"><h3>NTP</h3></a></li>
<li class="navitem"><a href="clear.html"><h3>Default Settings</h3></a></li>
<li class="navitem"><a href="reboot.html"><h3>Reboot</h3></a></li>
<li class="navitem"><a class="active" href="update.html"><h3>Firmware Update</h3></a></li>
@@ -32,9 +33,27 @@
<label>Current Version :</label>
<input id="gitver" type='text' disabled>
</div>
<div class='dataitem'>
<label>Firmware TAR file :</label>
<input type='checkbox' id='hasfile' name='hasfile' disabled>
</div>
<div class='dataitem'>
<label>OTA Files :</label>
<ul id='files' name='files'>
</ul>
</div>
</div>
<div class="datafield">
<h2>Upload Firmware</h2>
<h2>1: Delete Current Files</h2>
<div class="dataitem itemcenter saveconfig">
<form method='POST' action='firmware'>
<input type="hidden" id="mode" name="mode" value="delete">
<input type='submit' value='Delete Files'>
</form>
</div>
</div>
<div class="datafield">
<h2>2: Upload Firmware</h2>
<div class="dataitem itemcenter saveconfig">
<form method='POST' action='uploadfirmware' enctype='multipart/form-data'>
<input type='file' accept='.tar' name='firmware'>
@@ -43,19 +62,18 @@
</div>
</div>
<div class="datafield">
<h2>Unpack Firmware</h2>
updates website files.
<h2>3: Unpack Firmware</h2>
<div class="dataitem itemcenter saveconfig">
<form method='POST' action='unpackfirmware'>
<form method='POST' action='firmware'>
<input type="hidden" id="mode" name="mode" value="unpack">
<input type='submit' value='Unpack Firmware'>
</form>
</div>
</div>
<div class="datafield">
<h2>Update Firmware</h2>
<h2>4: Update Firmware</h2>
<div class="dataitem itemcenter saveconfig">
<form method='POST' action='updatefirmware'>
<form method='POST' action='firmware'>
<input type="hidden" id="mode" name="mode" value="update">
<input type='submit' value='Update Firmware'>
</form>

View File

@@ -31,20 +31,20 @@ class ACSFileSystem
static void processUSB();
static void erasePartitions();
static void formatPartitions();
static void listPartitions();
static int formatPartitions();
//static void listPartitions();
//static FileSystemStore* getFileSystemStore();
static TDBStore* getTDBStore();
//static OptaBoardInfo getSecureInfo();
static int openFile(const char* filename, mbed::File *file, int flags, bool ota = false);
static int removeFile(const char* filename, bool ota = false);
static int createDirectory(const char* path, mode_t mode, bool ota = false);
static bool hasFile(const char* filename);
static int openFile(const char* filename, mbed::File *file, int flags);
static int removeFile(const char* filename);
static int createDirectory(const char* path, mode_t mode);
static int removeDirectory(const char* path);
static int clearDirectory(const char* path);
//static void listDirectory(char* name);
//static std::vector<std::string> directoryList(char *name);
static void listDirectory(const char *path);
static std::vector<std::string> directoryList(const char *path);
private:

View File

@@ -51,6 +51,9 @@ class ConfigStore
Config_kv_t username {"username"};
Config_kv_t password {"password"};
Config_kv_t ntpserver {"ntpserver"};
Config_kv_t ntpserverport {"ntpserverport"};
std::array<Relay_t, 5> acsrelays;
std::array<Input_t, 9> acsinputs;
};

View File

@@ -18,10 +18,10 @@ class Console
//static int updateTime(int /*argc*/ = 0, char** /*argv*/ = NULL);
static int diskActions(int /*argc*/ = 0, char** /*argv*/ = NULL);
//static int configActions(int /*argc*/ = 0, char** /*argv*/ = NULL);
//static int securityKey(int /*argc*/ = 0, char** /*argv*/ = NULL);
static int printBoardInfo(int /*argc*/ = 0, char** /*argv*/ = NULL);
//static void resetReason();
//static String resetReasonString(reset_reason_t val);
static int otaAction(int /*argc*/ = 0, char** /*argv*/ = NULL);
};
#endif

View File

@@ -3,14 +3,11 @@
#include "mbed.h"
#define NTP_DEFULT_NIST_SERVER_ADDRESS "nl.pool.ntp.org"
#define NTP_DEFULT_NIST_SERVER_PORT 123
class NTP{
public:
static void checkUpdateTime(bool connected);
private:
static void updateTime();
private:
static time_t get_timestamp(int timeout);
static uint32_t ntohl(uint32_t x);
};

184
include/network/opta_emac.h Normal file
View File

@@ -0,0 +1,184 @@
// /* Copyright (c) 2017 ARM Limited
// * Copyright (c) 2017 STMicroelectronics
// * 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.
// */
// #ifndef OPTA_EMAC_H_
// #define OPTA_EMAC_H_
// #include "EMAC.h"
// #include "rtos/Mutex.h"
// #include "mbed.h"
// class STM32_EMAC : public EMAC {
// public:
// STM32_EMAC();
// static STM32_EMAC &get_instance();
// /**
// * Return maximum transmission unit
// *
// * @return MTU in bytes
// */
// virtual uint32_t get_mtu_size() const;
// /**
// * Gets memory buffer alignment preference
// *
// * Gets preferred memory buffer alignment of the Emac device. IP stack may or may not
// * align link out memory buffer chains using the alignment.
// *
// * @return Memory alignment requirement in bytes
// */
// virtual uint32_t get_align_preference() const;
// /**
// * Return interface name
// *
// * @param name Pointer to where the name should be written
// * @param size Maximum number of character to copy
// */
// virtual void get_ifname(char *name, uint8_t size) const;
// /**
// * Returns size of the underlying interface HW address size.
// *
// * @return HW address size in bytes
// */
// virtual uint8_t get_hwaddr_size() const;
// /**
// * Return interface-supplied HW address
// *
// * Copies HW address to provided memory, @param addr has to be of correct size see @a get_hwaddr_size
// *
// * HW address need not be provided if this interface does not have its own HW
// * address configuration; stack will choose address from central system
// * configuration if the function returns false and does not write to addr.
// *
// * @param addr HW address for underlying interface
// * @return true if HW address is available
// */
// virtual bool get_hwaddr(uint8_t *addr) const;
// /**
// * Set HW address for interface
// *
// * Provided address has to be of correct size, see @a get_hwaddr_size
// *
// * Called to set the MAC address to actually use - if @a get_hwaddr is provided
// * the stack would normally use that, but it could be overridden, eg for test
// * purposes.
// *
// * @param addr Address to be set
// */
// virtual void set_hwaddr(const uint8_t *addr);
// /**
// * Sends the packet over the link
// *
// * That can not be called from an interrupt context.
// *
// * @param buf Packet to be send
// * @return True if the packet was send successfully, False otherwise
// */
// virtual bool link_out(emac_mem_buf_t *buf);
// /**
// * Initializes the HW
// *
// * @return True on success, False in case of an error.
// */
// virtual bool power_up();
// /**
// * Deinitializes the HW
// *
// */
// virtual void power_down();
// /**
// * Sets a callback that needs to be called for packets received for that interface
// *
// * @param input_cb Function to be register as a callback
// */
// virtual void set_link_input_cb(emac_link_input_cb_t input_cb);
// /**
// * Sets a callback that needs to be called on link status changes for given interface
// *
// * @param state_cb Function to be register as a callback
// */
// virtual void set_link_state_cb(emac_link_state_change_cb_t state_cb);
// /** Add device to a multicast group
// *
// * @param address A multicast group hardware address
// */
// virtual void add_multicast_group(const uint8_t *address);
// /** Remove device from a multicast group
// *
// * @param address A multicast group hardware address
// */
// virtual void remove_multicast_group(const uint8_t *address);
// /** Request reception of all multicast packets
// *
// * @param all True to receive all multicasts
// * False to receive only multicasts addressed to specified groups
// */
// virtual void set_all_multicast(bool all);
// /** Sets memory manager that is used to handle memory buffers
// *
// * @param mem_mngr Pointer to memory manager
// */
// virtual void set_memory_manager(EMACMemoryManager &mem_mngr);
// // Called from driver functions
// ETH_HandleTypeDef EthHandle;
// osThreadId_t thread; /**< Processing thread */
// EMACMemoryManager *memory_manager; /**< Memory manager */
// private:
// bool low_level_init_successful();
// void packet_rx();
// int low_level_input(emac_mem_buf_t **buf);
// static void thread_function(void *pvParameters);
// static void rmii_watchdog_thread_function(void *pvParameters);
// void phy_task();
// void enable_interrupts();
// void disable_interrupts();
// mbed_rtos_storage_thread_t thread_cb;
// #if defined (STM32F767xx) || defined (STM32F769xx) || defined (STM32F777xx) || defined (STM32F779xx)
// mbed_rtos_storage_thread_t rmii_watchdog_thread_cb;
// osThreadId_t rmii_watchdog_thread; /**< Watchdog processing thread */
// #endif
// rtos::Mutex TXLockMutex;/**< TX critical section mutex */
// rtos::Mutex RXLockMutex;/**< RX critical section mutex */
// emac_link_input_cb_t emac_link_input_cb; /**< Callback for incoming data */
// emac_link_state_change_cb_t emac_link_state_cb; /**< Link state change callback */
// //EMACMemoryManager *memory_manager; /**< Memory manager */
// //uint32_t phy_status;
// int32_t phy_status;
// int phy_task_handle; /**< Handle for phy task event */
// };
// #endif /* STM32_EMAC_H_ */

View File

@@ -0,0 +1,658 @@
/**
******************************************************************************
* @file stm32h7xx_hal_conf_template.h
* @author MCD Application Team
* @brief HAL configuration template file.
* This file should be copied to the application folder and renamed
* to stm32h7xx_hal_conf.h.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
* All rights reserved.</center></h2>
*
* 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
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef STM32H7xx_HAL_CONF_H
#define STM32H7xx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
#define HAL_ADC_MODULE_ENABLED
//#define HAL_CEC_MODULE_ENABLED
#define HAL_COMP_MODULE_ENABLED
#define HAL_CORDIC_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_CRC_MODULE_ENABLED
//#define HAL_CRYP_MODULE_ENABLED
#define HAL_DAC_MODULE_ENABLED
#define HAL_DCMI_MODULE_ENABLED
#define HAL_DFSDM_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_DMA2D_MODULE_ENABLED
#define HAL_DTS_MODULE_ENABLED
#define HAL_DSI_MODULE_ENABLED
//#define HAL_ETH_MODULE_ENABLED
//#define HAL_ETH_LEGACY_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_FDCAN_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_GFXMMU_MODULE_ENABLED
#define HAL_FMAC_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
//#define HAL_HASH_MODULE_ENABLED
#define HAL_HCD_MODULE_ENABLED
#define HAL_HRTIM_MODULE_ENABLED
#define HAL_HSEM_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
//#define HAL_I2S_MODULE_ENABLED
//#define HAL_IRDA_MODULE_ENABLED
#define HAL_IWDG_MODULE_ENABLED
//#define HAL_JPEG_MODULE_ENABLED
#define HAL_LPTIM_MODULE_ENABLED
#define HAL_LTDC_MODULE_ENABLED
#define HAL_MDIOS_MODULE_ENABLED
#define HAL_MDMA_MODULE_ENABLED
#define HAL_MMC_MODULE_ENABLED
#define HAL_NAND_MODULE_ENABLED
#define HAL_NOR_MODULE_ENABLED
#define HAL_OPAMP_MODULE_ENABLED
#define HAL_OSPI_MODULE_ENABLED
#define HAL_OTFDEC_MODULE_ENABLED
#define HAL_PCD_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_PSSI_MODULE_ENABLED
#define HAL_QSPI_MODULE_ENABLED
#define HAL_RAMECC_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_RNG_MODULE_ENABLED
#define HAL_RTC_MODULE_ENABLED
#define HAL_SAI_MODULE_ENABLED
#define HAL_SD_MODULE_ENABLED
//#define HAL_SDRAM_MODULE_ENABLED
//#define HAL_SMARTCARD_MODULE_ENABLED
//#define HAL_SMBUS_MODULE_ENABLED
//#define HAL_SPDIFRX_MODULE_ENABLED
#define HAL_SPI_MODULE_ENABLED
#define HAL_SRAM_MODULE_ENABLED
#define HAL_SWPMI_MODULE_ENABLED
#define HAL_TIM_MODULE_ENABLED
#define HAL_UART_MODULE_ENABLED
#define HAL_USART_MODULE_ENABLED
#define HAL_WWDG_MODULE_ENABLED
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE (25000000UL) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal oscillator (CSI) default value.
* This value is the default CSI value after Reset.
*/
#if !defined (CSI_VALUE)
#define CSI_VALUE (4000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* CSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined (HSI_VALUE)
#define HSI_VALUE (64000000UL) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined (LSE_VALUE)
#define LSE_VALUE (32768UL) /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
#if !defined (LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */
#endif /* LSE_STARTUP_TIMEOUT */
#if !defined (LSI_VALUE)
#define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/
#endif /* LSI_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief External clock source for I2S peripheral
* This value is used by the I2S HAL module to compute the I2S clock source
* frequency, this source is inserted directly through I2S_CKIN pad.
*/
#if !defined (EXTERNAL_CLOCK_VALUE)
#define EXTERNAL_CLOCK_VALUE 12288000UL /*!< Value of the External clock in Hz*/
#endif /* EXTERNAL_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE (3300UL) /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY (0x0FUL) /*!< tick interrupt priority */
#define USE_RTOS 0
#define USE_SD_TRANSCEIVER 0U /*!< use uSD Transceiver */
#define USE_SPI_CRC 1U /*!< use CRC in SPI */
#if !defined (USE_HAL_ADC_REGISTER_CALLBACKS)
#define USE_HAL_ADC_REGISTER_CALLBACKS 0U /* ADC register callback disabled */
#endif
#if !defined (USE_HAL_CEC_REGISTER_CALLBACKS)
#define USE_HAL_CEC_REGISTER_CALLBACKS 0U /* CEC register callback disabled */
#endif
#if !defined (USE_HAL_COMP_REGISTER_CALLBACKS)
#define USE_HAL_COMP_REGISTER_CALLBACKS 0U /* COMP register callback disabled */
#endif
#if !defined (USE_HAL_CORDIC_REGISTER_CALLBACKS)
#define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U /* CORDIC register callback disabled */
#endif
#if !defined (USE_HAL_CRYP_REGISTER_CALLBACKS)
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0U /* CRYP register callback disabled */
#endif
#if !defined (USE_HAL_DAC_REGISTER_CALLBACKS)
#define USE_HAL_DAC_REGISTER_CALLBACKS 0U /* DAC register callback disabled */
#endif
#if !defined (USE_HAL_DCMI_REGISTER_CALLBACKS)
#define USE_HAL_DCMI_REGISTER_CALLBACKS 0U /* DCMI register callback disabled */
#endif
#if !defined (USE_HAL_DFSDM_REGISTER_CALLBACKS)
#define USE_HAL_DFSDM_REGISTER_CALLBACKS 0U /* DFSDM register callback disabled */
#endif
#if !defined (USE_HAL_DMA2D_REGISTER_CALLBACKS)
#define USE_HAL_DMA2D_REGISTER_CALLBACKS 0U /* DMA2D register callback disabled */
#endif
#if !defined (USE_HAL_DSI_REGISTER_CALLBACKS)
#define USE_HAL_DSI_REGISTER_CALLBACKS 0U /* DSI register callback disabled */
#endif
#if !defined (USE_HAL_DTS_REGISTER_CALLBACKS)
#define USE_HAL_DTS_REGISTER_CALLBACKS 0U /* DTS register callback disabled */
#endif
#if !defined (USE_HAL_ETH_REGISTER_CALLBACKS)
#define USE_HAL_ETH_REGISTER_CALLBACKS 0U /* ETH register callback disabled */
#endif
#if !defined (USE_HAL_FDCAN_REGISTER_CALLBACKS)
#define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U /* FDCAN register callback disabled */
#endif
#if !defined (USE_HAL_FMAC_REGISTER_CALLBACKS)
#define USE_HAL_FMAC_REGISTER_CALLBACKS 0U /* FMAC register callback disabled */
#endif
#if !defined (USE_HAL_NAND_REGISTER_CALLBACKS)
#define USE_HAL_NAND_REGISTER_CALLBACKS 0U /* NAND register callback disabled */
#endif
#if !defined (USE_HAL_NOR_REGISTER_CALLBACKS)
#define USE_HAL_NOR_REGISTER_CALLBACKS 0U /* NOR register callback disabled */
#endif
#if !defined (USE_HAL_SDRAM_REGISTER_CALLBACKS)
#define USE_HAL_SDRAM_REGISTER_CALLBACKS 0U /* SDRAM register callback disabled */
#endif
#if !defined (USE_HAL_SRAM_REGISTER_CALLBACKS)
#define USE_HAL_SRAM_REGISTER_CALLBACKS 0U /* SRAM register callback disabled */
#endif
#if !defined (USE_HAL_HASH_REGISTER_CALLBACKS)
#define USE_HAL_HASH_REGISTER_CALLBACKS 0U /* HASH register callback disabled */
#endif
#if !defined (USE_HAL_HCD_REGISTER_CALLBACKS)
#define USE_HAL_HCD_REGISTER_CALLBACKS 0U /* HCD register callback disabled */
#endif
#if !defined (USE_HAL_GFXMMU_REGISTER_CALLBACKS)
#define USE_HAL_GFXMMU_REGISTER_CALLBACKS 0U /* GFXMMU register callback disabled */
#endif
#if !defined (USE_HAL_HRTIM_REGISTER_CALLBACKS)
#define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U /* HRTIM register callback disabled */
#endif
#if !defined (USE_HAL_I2C_REGISTER_CALLBACKS)
#define USE_HAL_I2C_REGISTER_CALLBACKS 0U /* I2C register callback disabled */
#endif
#if !defined (USE_HAL_I2S_REGISTER_CALLBACKS)
#define USE_HAL_I2S_REGISTER_CALLBACKS 0U /* I2S register callback disabled */
#endif
#if !defined (USE_HAL_IRDA_REGISTER_CALLBACKS)
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0U /* IRDA register callback disabled */
#endif
#if !defined (USE_HAL_JPEG_REGISTER_CALLBACKS)
#define USE_HAL_JPEG_REGISTER_CALLBACKS 0U /* JPEG register callback disabled */
#endif
#if !defined (USE_HAL_LPTIM_REGISTER_CALLBACKS)
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U /* LPTIM register callback disabled */
#endif
#if !defined (USE_HAL_LTDC_REGISTER_CALLBACKS)
#define USE_HAL_LTDC_REGISTER_CALLBACKS 0U /* LTDC register callback disabled */
#endif
#if !defined (USE_HAL_MDIOS_REGISTER_CALLBACKS)
#define USE_HAL_MDIOS_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
#endif
#if !defined (USE_HAL_MMC_REGISTER_CALLBACKS)
#define USE_HAL_MMC_REGISTER_CALLBACKS 0U /* MMC register callback disabled */
#endif
#if !defined (USE_HAL_OPAMP_REGISTER_CALLBACKS)
#define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U /* MDIO register callback disabled */
#endif
#if !defined (USE_HAL_OSPI_REGISTER_CALLBACKS)
#define USE_HAL_OSPI_REGISTER_CALLBACKS 0U /* OSPI register callback disabled */
#endif
#if !defined (USE_HAL_OTFDEC_REGISTER_CALLBACKS)
#define USE_HAL_OTFDEC_REGISTER_CALLBACKS 0U /* OTFDEC register callback disabled */
#endif
#if !defined (USE_HAL_PCD_REGISTER_CALLBACKS)
#define USE_HAL_PCD_REGISTER_CALLBACKS 0U /* PCD register callback disabled */
#endif
#if !defined (USE_HAL_QSPI_REGISTER_CALLBACKS)
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0U /* QSPI register callback disabled */
#endif
#if !defined (USE_HAL_RNG_REGISTER_CALLBACKS)
#define USE_HAL_RNG_REGISTER_CALLBACKS 0U /* RNG register callback disabled */
#endif
#if !defined (USE_HAL_RTC_REGISTER_CALLBACKS)
#define USE_HAL_RTC_REGISTER_CALLBACKS 0U /* RTC register callback disabled */
#endif
#if !defined (USE_HAL_SAI_REGISTER_CALLBACKS)
#define USE_HAL_SAI_REGISTER_CALLBACKS 0U /* SAI register callback disabled */
#endif
#if !defined (USE_HAL_SD_REGISTER_CALLBACKS)
#define USE_HAL_SD_REGISTER_CALLBACKS 0U /* SD register callback disabled */
#endif
#if !defined (USE_HAL_SMARTCARD_REGISTER_CALLBACKS)
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U /* SMARTCARD register callback disabled */
#endif
#if !defined (USE_HAL_SPDIFRX_REGISTER_CALLBACKS)
#define USE_HAL_SPDIFRX_REGISTER_CALLBACKS 0U /* SPDIFRX register callback disabled */
#endif
#if !defined (USE_HAL_SMBUS_REGISTER_CALLBACKS)
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U /* SMBUS register callback disabled */
#endif
#if !defined (USE_HAL_SPI_REGISTER_CALLBACKS)
#define USE_HAL_SPI_REGISTER_CALLBACKS 0U /* SPI register callback disabled */
#endif
#if !defined (USE_HAL_SWPMI_REGISTER_CALLBACKS)
#define USE_HAL_SWPMI_REGISTER_CALLBACKS 0U /* SWPMI register callback disabled */
#endif
#if !defined (USE_HAL_TIM_REGISTER_CALLBACKS)
#define USE_HAL_TIM_REGISTER_CALLBACKS 0U /* TIM register callback disabled */
#endif
#if !defined (USE_HAL_UART_REGISTER_CALLBACKS)
#define USE_HAL_UART_REGISTER_CALLBACKS 0U /* UART register callback disabled */
#endif
#if !defined (USE_HAL_USART_REGISTER_CALLBACKS)
#define USE_HAL_USART_REGISTER_CALLBACKS 0U /* USART register callback disabled */
#endif
#if !defined (USE_HAL_WWDG_REGISTER_CALLBACKS)
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* WWDG register callback disabled */
#endif
/* ########################### Ethernet Configuration ######################### */
#ifdef MBED_CONF_STM32_EMAC_ETH_RXBUFNB
/* default value in connectivity/drivers/emac/TARGET_STM/mbed_lib.json */
#define ETH_TX_DESC_CNT MBED_CONF_STM32_EMAC_ETH_TXBUFNB /* number of Ethernet Tx DMA descriptors */
#define ETH_RX_DESC_CNT MBED_CONF_STM32_EMAC_ETH_RXBUFNB /* number of Ethernet Rx DMA descriptors */
#else
/* ex: bare metal profile */
#define ETH_TX_DESC_CNT 0 /* Tx buffers of size ETH_TX_BUF_SIZE */
#define ETH_RX_DESC_CNT 0 /* Rx buffers of size ETH_RX_BUF_SIZE */
#endif
#define ETH_MAC_ADDR0 (0x02UL)
#define ETH_MAC_ADDR1 (0x00UL)
#define ETH_MAC_ADDR2 (0x00UL)
#define ETH_MAC_ADDR3 (0x00UL)
#define ETH_MAC_ADDR4 (0x00UL)
#define ETH_MAC_ADDR5 (0x00UL)
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
/* #define USE_FULL_ASSERT 1 */
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32h7xx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32h7xx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32h7xx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_MDMA_MODULE_ENABLED
#include "stm32h7xx_hal_mdma.h"
#endif /* HAL_MDMA_MODULE_ENABLED */
#ifdef HAL_HASH_MODULE_ENABLED
#include "stm32h7xx_hal_hash.h"
#endif /* HAL_HASH_MODULE_ENABLED */
#ifdef HAL_DCMI_MODULE_ENABLED
#include "stm32h7xx_hal_dcmi.h"
#endif /* HAL_DCMI_MODULE_ENABLED */
#ifdef HAL_DMA2D_MODULE_ENABLED
#include "stm32h7xx_hal_dma2d.h"
#endif /* HAL_DMA2D_MODULE_ENABLED */
#ifdef HAL_DSI_MODULE_ENABLED
#include "stm32h7xx_hal_dsi.h"
#endif /* HAL_DSI_MODULE_ENABLED */
#ifdef HAL_DFSDM_MODULE_ENABLED
#include "stm32h7xx_hal_dfsdm.h"
#endif /* HAL_DFSDM_MODULE_ENABLED */
#ifdef HAL_DTS_MODULE_ENABLED
#include "stm32h7xx_hal_dts.h"
#endif /* HAL_DTS_MODULE_ENABLED */
#ifdef HAL_ETH_MODULE_ENABLED
#include "stm32h7xx_hal_eth.h"
#endif /* HAL_ETH_MODULE_ENABLED */
#ifdef HAL_ETH_LEGACY_MODULE_ENABLED
#include "Legacy/stm32h7xx_hal_eth_legacy.h"
#endif /* HAL_ETH_LEGACY_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32h7xx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32h7xx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32h7xx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_FDCAN_MODULE_ENABLED
#include "stm32h7xx_hal_fdcan.h"
#endif /* HAL_FDCAN_MODULE_ENABLED */
#ifdef HAL_CEC_MODULE_ENABLED
#include "stm32h7xx_hal_cec.h"
#endif /* HAL_CEC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32h7xx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORDIC_MODULE_ENABLED
#include "stm32h7xx_hal_cordic.h"
#endif /* HAL_CORDIC_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32h7xx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32h7xx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_DAC_MODULE_ENABLED
#include "stm32h7xx_hal_dac.h"
#endif /* HAL_DAC_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32h7xx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_GFXMMU_MODULE_ENABLED
#include "stm32h7xx_hal_gfxmmu.h"
#endif /* HAL_GFXMMU_MODULE_ENABLED */
#ifdef HAL_FMAC_MODULE_ENABLED
#include "stm32h7xx_hal_fmac.h"
#endif /* HAL_FMAC_MODULE_ENABLED */
#ifdef HAL_HRTIM_MODULE_ENABLED
#include "stm32h7xx_hal_hrtim.h"
#endif /* HAL_HRTIM_MODULE_ENABLED */
#ifdef HAL_HSEM_MODULE_ENABLED
#include "stm32h7xx_hal_hsem.h"
#endif /* HAL_HSEM_MODULE_ENABLED */
#ifdef HAL_SRAM_MODULE_ENABLED
#include "stm32h7xx_hal_sram.h"
#endif /* HAL_SRAM_MODULE_ENABLED */
#ifdef HAL_NOR_MODULE_ENABLED
#include "stm32h7xx_hal_nor.h"
#endif /* HAL_NOR_MODULE_ENABLED */
#ifdef HAL_NAND_MODULE_ENABLED
#include "stm32h7xx_hal_nand.h"
#endif /* HAL_NAND_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32h7xx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_I2S_MODULE_ENABLED
#include "stm32h7xx_hal_i2s.h"
#endif /* HAL_I2S_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32h7xx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_JPEG_MODULE_ENABLED
#include "stm32h7xx_hal_jpeg.h"
#endif /* HAL_JPEG_MODULE_ENABLED */
#ifdef HAL_MDIOS_MODULE_ENABLED
#include "stm32h7xx_hal_mdios.h"
#endif /* HAL_MDIOS_MODULE_ENABLED */
#ifdef HAL_MMC_MODULE_ENABLED
#include "stm32h7xx_hal_mmc.h"
#endif /* HAL_MMC_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32h7xx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_LTDC_MODULE_ENABLED
#include "stm32h7xx_hal_ltdc.h"
#endif /* HAL_LTDC_MODULE_ENABLED */
#ifdef HAL_OPAMP_MODULE_ENABLED
#include "stm32h7xx_hal_opamp.h"
#endif /* HAL_OPAMP_MODULE_ENABLED */
#ifdef HAL_OSPI_MODULE_ENABLED
#include "stm32h7xx_hal_ospi.h"
#endif /* HAL_OSPI_MODULE_ENABLED */
#ifdef HAL_OTFDEC_MODULE_ENABLED
#include "stm32h7xx_hal_otfdec.h"
#endif /* HAL_OTFDEC_MODULE_ENABLED */
#ifdef HAL_PSSI_MODULE_ENABLED
#include "stm32h7xx_hal_pssi.h"
#endif /* HAL_PSSI_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32h7xx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32h7xx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RAMECC_MODULE_ENABLED
#include "stm32h7xx_hal_ramecc.h"
#endif /* HAL_RAMECC_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32h7xx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32h7xx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32h7xx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SD_MODULE_ENABLED
#include "stm32h7xx_hal_sd.h"
#endif /* HAL_SD_MODULE_ENABLED */
#ifdef HAL_SDRAM_MODULE_ENABLED
#include "stm32h7xx_hal_sdram.h"
#endif /* HAL_SDRAM_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32h7xx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_SPDIFRX_MODULE_ENABLED
#include "stm32h7xx_hal_spdifrx.h"
#endif /* HAL_SPDIFRX_MODULE_ENABLED */
#ifdef HAL_SWPMI_MODULE_ENABLED
#include "stm32h7xx_hal_swpmi.h"
#endif /* HAL_SWPMI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32h7xx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32h7xx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32h7xx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32h7xx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32h7xx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32h7xx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32h7xx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32h7xx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_HCD_MODULE_ENABLED
#include "stm32h7xx_hal_hcd.h"
#endif /* HAL_HCD_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h" // MBED patch
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* STM32H7xx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -32,6 +32,8 @@ class WebServer
static void SwitchPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void credentialsGet(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void credentialsPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void ntpGet(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void ntpPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void clearPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res);
static void rebootPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res);

View File

@@ -20,13 +20,18 @@
"platform.callback-nontrivial": false,
"platform.all-stats-enabled": true,
"platform.memory-tracing-enabled": true,
"platform.error-filename-capture-enabled": true,
"rtos.main-thread-stack-size": 16384,
"qspif.enable-and-reset": true,
"qspif.num-status-register": 2,
"lwip.debug-enabled": false,
"stm32-emac.eth-rxbufnb": 4,
"stm32-emac.eth-txbufnb": 10,
"stm32-emac.thread-stacksize": 1024,
"lwip.debug-enabled": true,
"nsapi.socket-stats-enabled": true,
"lwip.socket-max": 20,
"lwip.tcp-server-max": 10,

View File

@@ -52,16 +52,16 @@
// #define MBEDTLS_SHA256_C
// #define MBEDTLS_SHA256_ALT
// #define MBEDTLD_MD5_C
#define MBEDTLS_MD5_C
// #define MBEDTLS_MD5_ALT
//#define MBEDTLD_AES_C
//#define MBEDTLS_AES_C
//#define MBEDTLS_AES_ALT
//#define MBEDTLD_CCM_C
//#define MBEDTLS_CCM_C
//#define MBEDTLS_CCM_ALT
//#define MBEDTLD_GCM_C
//#define MBEDTLS_GCM_C
//#define MBEDTLS_GCM_ALT

View File

@@ -30,10 +30,13 @@ build_unflags =
build_flags =
-I$PROJECT_SRC_DIR/Target_opta_sdn
-I$PROJECT_SRC_DIR/webserver
-I$PROJECT_SRC_DIR/network
-I$PROJECT_INCLUDE_DIR/webserver
-I$PROJECT_INCLUDE_DIR/AADP
-I$PROJECT_INCLUDE_DIR/network
;mbed-os/tools/profiles/debug.json
-DMBED_BUILD_PROFILE_DEBUG
-DETH_IP_VERSION_V3
-Wpedantic
;-std=gnu++2a
-std=c++2a

View File

@@ -24,18 +24,6 @@
QSPIFBlockDevice root(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_1, 40000000);
//QSPIFBlockDevice root(QSPI_FLASH1_IO0, QSPI_FLASH1_IO1, QSPI_FLASH1_IO2, QSPI_FLASH1_IO3, QSPI_FLASH1_SCK, QSPI_FLASH1_CSN, QSPIF_POLARITY_MODE_1, 80000000);
//SlicingBlockDevice config_data(&root, CONFIG_START, CONFIG_SIZE);
//TDBStore *config_store;
//SlicingBlockDevice user_data(&root, USER_START, (USER_START + USER_SIZE));
//FATFileSystem *user_data_fs;
//SlicingBlockDevice ota_data(&root, OTA_START, (OTA_START + OTA_SIZE));
//FATFileSystem *ota_data_fs;
//FileSystemStore *system_store;
SlicingBlockDevice user_data(&root, USER_START, USER_SIZE);
FATFileSystem *user_data_fs;
@@ -64,56 +52,26 @@ void ACSFileSystem::begin()
tr_error("user fs mount error: %d", err);
//printf("user fs mount error: %d\r\n", err_code(err));
//erasePartitions();
//formatPartitions();
err = FATFileSystem::format(&user_data);
if(err != 0)
{
tr_err("user fs format error: %d", err);
return;
}
formatPartitions();
// err = FATFileSystem::format(&user_data);
// if(err != 0)
// {
// tr_err("user fs format error: %d", err);
// return;
// }
}
mbed::File file;
err = file.open(user_data_fs, "user.txt", O_CREAT);
if(err != 0)
{
tr_error("user file write error: %d", err);
}
file.close();
// ota_data_fs = new FATFileSystem("ota");
// err = ota_data_fs->mount(&ota_data);
// if (err != 0)
// {
// tr_err("ota fs mount error: %d", err);
// //printf("ota fs mount error: %d\r\n", err_code(err));
// //erasePartitions();
// //formatPartitions();
// err = FATFileSystem::format(&ota_data);
// if(err != 0)
// {
// tr_err("ota fs format error: %d", err);
// return;
// }
// }
// err = file.open(ota_data_fs, "ota.txt", O_CREAT);
// mbed::File file;
// err = file.open(user_data_fs, "user.txt", O_CREAT);
// if(err != 0)
// {
// tr_err("ota file write error: %d", err);
// tr_error("user file write error: %d", err);
// }
// file.close();
// system_store = new FileSystemStore(user_data_fs);
// int res = system_store->init();
// if(res != 0)
// {
// tr_err("system store init error: %d", res);
// }
config_store = new TDBStore(&config_data);
int res = config_store->init();
if(res != 0)
@@ -129,20 +87,14 @@ void ACSFileSystem::processUSB()
void ACSFileSystem::erasePartitions()
{
printf("Start erasing partitions");
tr_info("Start erasing partitions");
int err = user_data_fs->unmount();
if (err != 0)
{
tr_error("user unmount error: %d", err);
return;
}
// ota_data_fs->unmount();
// if (err != 0)
// {
// printf("ota unmount error: %d\r\n", err);
// return;
// }
}
const bd_size_t erase_size = root.get_erase_size();
const bd_size_t size = root.size();
@@ -155,143 +107,175 @@ void ACSFileSystem::erasePartitions()
for (bd_size_t i = 0; i < eraseSectors; i++) {
int err = root.erase(i * erase_size, erase_size);
if (i % 64 == 0) {
printf("sector: %lld\r\n", i);
tr_info("sector: %lld", i);
}
if (err != 0) {
printf("Error erasing sector: %lld\r\n", i);
tr_error("Error erasing sector: %lld", i);
return;
}
}
printf("Done erasing\r\n");
tr_info("Done erasing");
}
void ACSFileSystem::formatPartitions()
int ACSFileSystem::formatPartitions()
{
//tr_info("Start formatting partitions");
tr_info("Formatting user partition");
//user_data_fs.unmount();
//ota_data_fs.unmount();
printf("Formatting user partition...\r\n");
int err = user_data_fs->format(&user_data);
if (err != 0) {
tr_error("Error formatting user partition: %d", err);
return;
return err;
}
printf("done.\r\n");
tr_info("done");
return 0;
// printf("Formatting ota partition... \r\n");
// //err = ota_data_fs.reformat(&ota_data);
// err = ota_data_fs->format(&ota_data);
// if (err != 0) {
// printf("Error formatting ota partition: %d\r\n", err);
// return;
// mbed::File file;
// err = file.open(user_data_fs, "user.txt", O_CREAT);
// if(err != 0)
// {
// tr_error("file write error\r\n");
// }
// printf("done.\r\n");
mbed::File file;
err = file.open(user_data_fs, "user.txt", O_CREAT);
if(err != 0)
{
tr_error("file write error\r\n");
}
file.close();
// file.close();
}
// FileSystemStore* ACSFileSystem::getFileSystemStore()
// {
// return system_store;
// }
TDBStore* ACSFileSystem::getTDBStore()
{
return config_store;
}
// OptaBoardInfo ACSFileSystem::getSecureInfo()
// {
// static OptaBoardInfo info;
// uint8_t temp_buf[sizeof(OptaBoardInfo) + 1];
// int ret = 0;
// //static SecureQSPIFBlockDevice secure_root;
// //secure_root.init();
// // read secure sector 2 ( address 1 << 13 )
// //ret = secure_root.readSecure(temp_buf, (1 << 13), sizeof(temp_buf));
// // size_t len = sizeof(temp_buf);
// // ret = root.read(0x48, -1, (unsigned int)(1 << 13), (char *)temp_buf, len)
// // //root._qspi_send_read_command()
// // memcpy(&info, &temp_buf[1], sizeof(OptaBoardInfo));
// // if (info.magic == OTP_QSPI_MAGIC) {
// // _boardInfo = (uint8_t*)&info;
// // has_otp_info = true;
// // }
// // secure_root.deinit();
// // return ret == 0;
// }
int ACSFileSystem::openFile(const char* filename, mbed::File *file, int flags, bool ota)
bool ACSFileSystem::hasFile(const char* filename)
{
//struct stat *fno;
if(user_data_fs->stat(filename, NULL) == FR_OK)
{
return true;
}
return false;
}
int ACSFileSystem::openFile(const char* filename, mbed::File *file, int flags)
{
// if(ota)
// {
// //return file->open(ota_data_fs, filename, flags);
// // if(user_data_fs->mkdir("ota/", S_IRWXO) != MBED_SUCCESS)
// // {
// // tr_error("ota folder create");
// // }
// }
return file->open(user_data_fs, filename, flags);
}
int ACSFileSystem::removeFile(const char* filename, bool ota)
int ACSFileSystem::removeFile(const char* filename)
{
// if(ota)
// {
// //return ota_data_fs->remove(filename);
// }
return user_data_fs->remove(filename);
}
int ACSFileSystem::createDirectory(const char* path, mode_t mode, bool ota)
int ACSFileSystem::createDirectory(const char* path, mode_t mode)
{
// if(ota)
// {
// return ota_data_fs.mkdir(path, mode);
// }
if(user_data_fs->stat(path, NULL) == FR_OK)
{
return MBED_SUCCESS;
}
return user_data_fs->mkdir(path, mode);
}
int ACSFileSystem::removeDirectory(const char* path)
{
if(user_data_fs->stat(path, NULL) == FR_OK)
{
//printf("folder exists\r\n");
return user_data_fs->remove(path);
}
//printf("folder NOT exists\r\n");
return MBED_SUCCESS;
}
// void ACSFileSystem::listDirectory(char* name)
// {
// DIR *d = opendir(name);
// struct dirent *p;
// if (d != NULL) {
// while ((p = readdir(d)) != NULL) {
// printf(" %c\r\n", p->d_name);
// }
// }
// closedir(d);
// }
int ACSFileSystem::clearDirectory(const char* path)
{
mbed::Dir dir;
if(dir.open(user_data_fs, path) == MBED_SUCCESS)
{
dirent ent;
while ((dir.read(&ent)) > 0)
{
char fullpath[40];
strcpy(fullpath, path);
strcat(fullpath, ent.d_name);
if(user_data_fs->remove(fullpath) != MBED_SUCCESS)
{
printf("failed to remove file\r\n");
}
}
dir.close();
}
return MBED_SUCCESS;
}
// std::vector<std::string> ACSFileSystem::directoryList(char *name)
// {
// DIR *dir = opendir(name);
// struct dirent *entry;
// std::vector<std::string> fileList;
// if (dir != NULL) {
// while ((entry = readdir(dir)) != NULL) {
// printf(" %c\r\n", entry->d_name);
// fileList.push_back(entry->d_name);
// }
// }
// closedir(dir);
// return fileList;
// }
void ACSFileSystem::listDirectory(const char *path)
{
printf("path %s\r\n", path);
mbed::Dir dir;
if(dir.open(user_data_fs, path) == MBED_SUCCESS)
{
dirent ent;
while ((dir.read(&ent)) > 0)
{
switch (ent.d_type) {
case DT_DIR: {
printf("Directory %s\r\n", ent.d_name);
break;
}
case DT_REG: {
printf("Regular File %s\r\n", ent.d_name);
// Declare and open the file in read-only mode
// mbed::File file;
// auto ret = file.open(&fs, ent.d_name);
// if (ret) {
// Serial.println("Unable to open file");
// continue;
// }
// Serial.print(" [");
// Serial.print(file.size());
// Serial.println(" bytes]");
// if (file.size() > 0) {
// // Print file with an ad-hoc function. YMMV.
// printFile(file);
// // Empty file after reading all the content. YMMV.
// file.close();
// ret = file.open(&fs, ent.d_name, O_TRUNC);
// if (ret < 0)
// Serial.println("Unable to truncate file");
// } else {
// // Remove file if empty. YMMV.
// file.close();
// fs.remove(ent.d_name);
// }
break;
}
default: {
printf("Other ");
break;
}
}
}
dir.close();
}
}
std::vector<std::string> ACSFileSystem::directoryList(const char *path)
{
std::vector<std::string> fileList;
mbed::Dir dir;
if(dir.open(user_data_fs, path) == MBED_SUCCESS)
{
struct dirent entry;
while ((dir.read(&entry)) > 0)
{
//printf(" %s\r\n", entry.d_name);
fileList.push_back(entry.d_name);
}
dir.close();
}
return fileList;
}
@@ -315,9 +299,9 @@ int ACSFileSystem::createDirectory(const char* path, mode_t mode, bool ota)
// unsigned long allocatedSpace {};
void ACSFileSystem::listPartitions()
{
printf("list Partitions\r\n");
//void ACSFileSystem::listPartitions()
//{
// printf("list Partitions\r\n");
// // Serial.println("Opening root directory.");
// // DIR* dir = opendir("/user/");
@@ -423,7 +407,7 @@ void ACSFileSystem::listPartitions()
// // Serial.println(allocatedSpace >> 10);
// // Serial.print("Unallocated Space [KBytes]: ");
// // Serial.println((bd->size() - allocatedSpace) >> 10);
}
//}
// void ACSFileSystem::partition()
// {

View File

@@ -143,6 +143,9 @@ bool ConfigStore::loadConfig()
_config.username.value = getStringValue(_config.username.key, "admin");
_config.password.value = getStringValue(_config.password.key, "admin");
_config.ntpserver.value = getStringValue(_config.ntpserver.key, "nl.pool.ntp.org");
_config.ntpserverport.value = getIntValue(_config.ntpserverport.key, 123);
//active - invert
_config.acsrelays[1] = getRelayValue("relay1", {true, false});
_config.acsrelays[2] = getRelayValue("relay2", {false, false});
@@ -185,6 +188,9 @@ void ConfigStore::saveConfig()
setStringValue(_config.username.key, std::get<std::string>(_config.username.value).c_str());
setStringValue(_config.password.key, std::get<std::string>(_config.password.value).c_str());
setStringValue(_config.ntpserver.key, std::get<std::string>(_config.ntpserver.value).c_str());
setIntValue(_config.ntpserverport.key, std::get<int>(_config.ntpserverport.value));
setRelayValue("relay1", _config.acsrelays[1]);
setRelayValue("relay2", _config.acsrelays[2]);
setRelayValue("relay3", _config.acsrelays[3]);
@@ -213,6 +219,9 @@ void ConfigStore::printConfig()
tr_info("username : %s", std::get<std::string>(_config.username.value).c_str());
tr_info("password : %s", std::get<std::string>(_config.password.value).c_str());
tr_info("ntpserver : %s", std::get<std::string>(_config.ntpserver.value).c_str());
tr_info("ntpserverport : %d", std::get<int>(_config.ntpserverport.value));
tr_info("acsrelays[1].active : %d", _config.acsrelays[1].active);
tr_info("acsrelays[1].invert : %d", _config.acsrelays[1].invert);
tr_info("acsrelays[2].active : %d", _config.acsrelays[2].active);

View File

@@ -6,6 +6,7 @@
#include "NTP.h"
#include "ACSFileSystem.h"
#include "ConfigStore.h"
#include "opta_info.h"
#define TRACE_GROUP "Console"
@@ -60,8 +61,6 @@ namespace mbed
//------- console -----------------
//std::function<void()> _stackPrint;
bool waitResponse()
{
bool confirmation = false;
@@ -98,10 +97,10 @@ void Console::begin()
//shell.addCommand("mem", memoryAction);
SimpleSerialShell::addCommand("stack", stackAction);
SimpleSerialShell::addCommand("lwip", lwipAction);
//shell.addCommand(F("key <cmd>"), securityKey);
SimpleSerialShell::addCommand("time <cmd>", showTime);
SimpleSerialShell::addCommand("board", printBoardInfo);
SimpleSerialShell::addCommand("disk <cmd>", diskActions);
SimpleSerialShell::addCommand("ota", otaAction);
//shell.addCommand("config <cmd>", configActions);
//basic command
//shell.addCommand(F("setTogglePeriod"), setTogglePeriod);
@@ -157,61 +156,6 @@ const char* threadState[] =
"WaitingMailbox"
};
// const char *printThreadState(rtos::Thread::State state)
// {
// switch (state)
// {
// case rtos::Thread::State::Ready:
// return "ready";
// break;
// case rtos::Thread::State::Running:
// return "Running";
// break;
// case rtos::Thread::State::WaitingDelay:
// return "WaitingDelay";
// break;
// case rtos::Thread::State::WaitingJoin:
// return "WaitingJoin";
// break;
// case rtos::Thread::State::WaitingThreadFlag:
// return "WaitingThreadFlag";
// break;
// case rtos::Thread::State::WaitingEventFlag:
// return "WaitingEventFlag";
// break;
// case rtos::Thread::State::WaitingMutex:
// return "WaitingMutex";
// break;
// case rtos::Thread::State::WaitingSemaphore:
// return "WaitingSemaphore";
// break;
// case rtos::Thread::State::WaitingMemoryPool:
// return "WaitingMemoryPool";
// break;
// case rtos::Thread::State::WaitingMessageGet:
// return "WaitingMessageGet";
// break;
// case rtos::Thread::State::WaitingMessagePut:
// return "WaitingMessagePut";
// break;
// case rtos::Thread::State::WaitingInterval:
// return "WaitingInterval";
// break;
// case rtos::Thread::State::WaitingOr:
// return "WaitingOr";
// break;
// case rtos::Thread::State::WaitingAnd:
// return "WaitingAnd";
// break;
// case rtos::Thread::State::WaitingMailbox:
// return "WaitingMailbox";
// break;
// default:
// return "????";
// break;
// }
// }
int Console::stackAction(int argc, char** argv)
{
printf("\nMemoryStats:");
@@ -292,12 +236,10 @@ int Console::lwipAction(int argc, char** argv)
printf(" Time: %lld\n", stats[i].last_change_tick);
}
}
//uint32_t reg = READ_REG(ETH->MACCR);
printf("MACCR : %ld\r\n", READ_REG(ETH->MACCR));
printf("MACECR : %ld\r\n", READ_REG(ETH->MACECR));
printf("MACPFR : %ld\r\n", READ_REG(ETH->MACPFR));
//printf("MACCR : %ld\r\n", READ_REG(ETH->MACCR));
//printf("MACECR : %ld\r\n", READ_REG(ETH->MACECR));
//printf("MACPFR : %ld\r\n", READ_REG(ETH->MACPFR));
return EXIT_SUCCESS;
}
@@ -305,23 +247,16 @@ int Console::lwipAction(int argc, char** argv)
int Console::diskActions(int argc, char** argv)
{
// //shell.println(argv[0]);
// //shell.println(argv[1]);
// //shell.println(argv[2]);
if (argc == 1)
{
ACSFileSystem::listPartitions();
if (argc == 1)
{
//ACSFileSystem::listPartitions();
return EXIT_SUCCESS;
}else if(argc == 2){
}
else if(argc == 2)
{
std::string cmd = argv[1];
printf("time cmd = %s\r\n", cmd.c_str());
if(cmd.compare("erase") == 0)
{
//shell.println("format cmd");
//printf("All the content of the QSPI flash will be erased.\r\n");
printf("Erase flash? Y/[n]\r\n");
if (true == waitResponse())
{
@@ -330,21 +265,17 @@ if (argc == 1)
}
else if(cmd.compare("format") == 0)
{
//shell.println("format cmd");
//printf("All the content of the QSPI flash will be erased.");
printf("Format flash? Y/[n]");
if (true == waitResponse())
{
ACSFileSystem::formatPartitions();
}
}
return EXIT_SUCCESS;
}else if(argc == 3){
std::string cmd = argv[1];
//shell.print("time cmd = ");
//shell.println(cmd);
if(cmd.compare("list") == 0){
//ACSFileSystem::listDirectory(argv[2]);
else
{
printf("\t erase: erase all data \r\n");
printf("\t format: format flash (data and settings)\r\n");
printf("\t help: show this help\r\n");
}
return EXIT_SUCCESS;
}
@@ -394,62 +325,30 @@ if (argc == 1)
int Console::showTime(int argc, char** argv)
{
// for ( int i = 1; i < argc; i++) {
// shell.println(argv[i]);
// }
//shell.println(argv[0]);
//shell.println(argv[1]);
//shell.println(argv[2]);
if (argc == 1)
{
time_t t = time(NULL);
printf("Time: %s\r\n", ctime(&t));
//shell.print(ctime(&t));
//std::tm* now = std::localtime(&t);
return EXIT_SUCCESS;
}else if(argc == 2){
//char cmd = *argv[2];
//String cmd = String(argv[1]);
}
else if(argc == 2)
{
std::string cmd = argv[1];
//shell.print("time cmd = ");
//shell.println(cmd);
if(cmd.compare("update") == 0){
printf("update time cmd\r\n");
//NTP ntp;
//ntp.updateTime();
//NTP.updateTime();
//NTP::updateTime();
if(cmd.compare("update") == 0)
{
NTP::updateTime();
}
else
{
printf("\t update: update time from NTP server\r\n");
printf("\t help: show this help\r\n");
}
return EXIT_SUCCESS;
}
return -1;
}
// int Console::securityKey(int argc, char** argv)
// {
// if (argc == 1)
// {
// //time_t t = time(NULL);
// //shell.print("Time: ");
// //shell.print(ctime(&t));
// return EXIT_SUCCESS;
// }else if(argc == 2){
// //char cmd = *argv[2];
// String cmd = String(argv[1]);
// //shell.print("time cmd = ");
// //shell.println(cmd);
// if(cmd.compareTo("create") == 0){
// shell.println("create key");
// }
// return EXIT_SUCCESS;
// }
// return -1;
// }
int Console::printBoardInfo(int argc, char** argv){
//Console::resetReason();
@@ -519,10 +418,13 @@ int Console::printBoardInfo(int argc, char** argv){
mbed_stats_sys_t sysStats;
mbed_stats_sys_get(&sysStats);
printf("%ld\r\n", sysStats.cpu_id);
printf("%d\r\n", sysStats.compiler_id);
printf("%ld\r\n", sysStats.compiler_version);
printf("%ld\r\n", sysStats.os_version);
printf("cpu_id %ld\r\n", sysStats.cpu_id);
printf("compiler_id %d\r\n", sysStats.compiler_id);
printf("complier_version %ld\r\n", sysStats.compiler_version);
printf("os_version %ld\r\n", sysStats.os_version);
getBoardInfo();
getSecureFlashData();
return 0;
}
@@ -566,3 +468,44 @@ int Console::printBoardInfo(int argc, char** argv){
// return F("N/A");
// }
// }
int Console::otaAction(int argc, char** argv)
{
// for ( int i = 1; i < argc; i++) {
// shell.println(argv[i]);
// }
//shell.println(argv[0]);
//shell.println(argv[1]);
//shell.println(argv[2]);
if (argc == 1)
{
//time_t t = time(NULL);
//printf(": %s\r\n", ctime(&t));
//shell.print(ctime(&t));
printf("ota files\r\n");
//std::vector<std::string> files = ACSFileSystem::directoryList("/ota");
ACSFileSystem::listDirectory("/ota");
return EXIT_SUCCESS;
}
else if(argc == 2)
{
//char cmd = *argv[2];
//String cmd = String(argv[1]);
// std::string cmd = argv[1];
// //shell.print("time cmd = ");
// //shell.println(cmd);
// if(cmd.compare("update") == 0){
// printf("update time cmd\r\n");
// //NTP ntp;
// //ntp.updateTime();
// //NTP.updateTime();
// //NTP::updateTime();
// }
return EXIT_SUCCESS;
}
return -1;
}

View File

@@ -1,5 +1,6 @@
#include "NTP.h"
#include "mbed-trace/mbed_trace.h"
#include "ConfigStore.h"
#define TRACE_GROUP "NTP"
@@ -42,9 +43,11 @@ time_t NTP::get_timestamp(int timeout)
NetworkInterface *net = NetworkInterface::get_default_instance();
ConfigStore::Config_t *config = ConfigStore::getConfig();
SocketAddress nist = SocketAddress();
nist.set_port(NTP_DEFULT_NIST_SERVER_PORT);
if (net->gethostbyname(NTP_DEFULT_NIST_SERVER_ADDRESS, &nist) != NSAPI_ERROR_OK)
nist.set_port(std::get<int>(config->ntpserverport.value));
if (net->gethostbyname(std::get<std::string>(config->ntpserver.value).c_str(), &nist) != NSAPI_ERROR_OK)
{
tr_err("get host failed");
return -1;

View File

@@ -180,8 +180,6 @@ void getBoardInfo()
printf("revid %ld\r\n", HAL_GetREVID());
printf("hal version %ld\r\n", HAL_GetHalVersion());
//printf("UID %d\r\n", HAL_GetDEVID());
//printf("UID %d\r\n", HAL_GetDEVID());
}
@@ -255,15 +253,6 @@ bool getSecureFlashData()
info_secure.plc_license[14],
info_secure.plc_license[15]);
// if (info.magic == OTP_QSPI_MAGIC) {
// _boardInfo = (uint8_t*)&info;
// has_otp_info = true;
// }
secure_root.deinit();
return ret == 0;
}

View File

@@ -55,6 +55,9 @@
#define ETH_RXD1_Pin GPIO_PIN_5
#define ETH_RXD1_GPIO_Port GPIOC
#define ETH_RESET GPIO_PIN_15
#define ETH_RESET_GPIO_Port GPIOJ
/**
* Override HAL Eth Init function
*/
@@ -75,6 +78,7 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
// __HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOJ_CLK_ENABLE();
/* Enable Peripheral clock */
__HAL_RCC_ETH1MAC_CLK_ENABLE();
@@ -85,7 +89,6 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
// TODO
/* Reset ETH Phy */
__HAL_RCC_GPIOJ_CLK_ENABLE();
GPIO_InitTypeDef gpio_eth_rst_init_structure;
gpio_eth_rst_init_structure.Pin = GPIO_PIN_15;
gpio_eth_rst_init_structure.Mode = GPIO_MODE_OUTPUT_PP;
@@ -97,6 +100,7 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
HAL_GPIO_Init(GPIOC, &gpio_eth_rst_init_structure);
HAL_GPIO_WritePin(GPIOC, ETH_RXD0_Pin, 1);
HAL_GPIO_WritePin(GPIOC, ETH_RXD1_Pin, 1);
gpio_eth_rst_init_structure.Pin = ETH_CRS_DV_Pin;
HAL_GPIO_Init(GPIOA, &gpio_eth_rst_init_structure);
HAL_GPIO_WritePin(GPIOA, ETH_CRS_DV_Pin, 1);
@@ -117,6 +121,7 @@ void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
PC4 ------> ETH_RXD0
PC5 ------> ETH_RXD1
*/
GPIO_InitStruct.Pin = ETH_TX_EN_Pin | ETH_TXD1_Pin | ETH_TXD0_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;

View File

@@ -371,8 +371,8 @@ int main()
WebServer::begin();
Aperio::begin();
aperioThread.start(aperioTask);
//Aperio::begin();
//aperioThread.start(aperioTask);
//print_device_info();

1385
src/network/opta_emac.cpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -60,16 +60,16 @@ void Application::process(TCPSocket *client) {
//printf("create Request\r\n");
Request request(client, &response);
printf("start m_process\r\n");
//printf("start m_process\r\n");
m_process(request, response);
printf("headers cleanup\r\n");
//printf("headers cleanup\r\n");
request._headers.clear();
printf("start m_finalize\r\n");
//printf("start m_finalize\r\n");
response.m_finalize();
printf("close Connection\r\n");
//printf("close Connection\r\n");
client->close();
//printf("done\r\n");
}

View File

@@ -129,10 +129,9 @@ bool Request::writeMultipartData(mbed::File *file)
while(len > 0)
{
nsapi_size_or_error_t recv_ret = _socket->recv(buff, sizeof(buff));
//printf("1ret: %d - %d - %d\r\n", recv_ret, len, (_contentLength / len) * 100);
//printf("2ret: %d - %d - %d\r\n", recv_ret, len, (100*_contentLength + len/2)/len);
printf("ret: %d - %d - %d\r\n", recv_ret, len, (100*len + _contentLength/2)/_contentLength);
//printf("4ret: %d - %d - %d\r\n", recv_ret, len, (_contentLength + len/2)/len);
//printf("ret: %d - %d - %d\r\n", recv_ret, len, (100*len + _contentLength/2)/_contentLength);
if(recv_ret < 0)
{
return false;

View File

@@ -88,14 +88,16 @@ tar_state Tar::extract(mbed::File *tarfile, const char *folder)
//filesize = parseoct(buff + 124, 12);
//strncpy(fullpath, buff, sizeof(fullpath));
tr_info("folder: %s", folder);
if(folder != NULL)
{
{
memset(fullpath, 0, TAR_FILENAME_LENGTH);
strcat(fullpath, folder);
strcat(fullpath, block);
if(ACSFileSystem::createDirectory(folder, 0755) != MBED_SUCCESS)
{
tr_error("Folder create failed: %s", fullpath);
}
// if(ACSFileSystem::createDirectory(folder, 0755) != MBED_SUCCESS)
// {
// tr_error("Folder create failed: %s", fullpath);
// }
}
else
{
@@ -174,7 +176,7 @@ tar_state Tar::extract(mbed::File *tarfile, const char *folder)
return TAR_WRITE_ERROR;
}
tr_info("Remaining : %d - %d", filesize, (100*filesize + full_filesize/2)/full_filesize);
//tr_info("Remaining : %d - %d", filesize, (100*filesize + full_filesize/2)/full_filesize);
filesize -= bytes_read;
bytes_read = 0;

View File

@@ -13,9 +13,7 @@
#include "Relays.h"
#include "opta_info.h"
#include "untar.h"
//#include <ArduinoECCX08.h>
//#include "ECCX08.h"
#include "MD5.h"
#define TRACE_GROUP "Webserver"
@@ -25,6 +23,33 @@ HTTPWebServer::Application app;
const char *compileDate = __DATE__;
const char *compileTime = __TIME__;
//ArduinoJson vector converter
namespace ArduinoJson {
template <typename T>
struct Converter<std::vector<T> > {
static void toJson(const std::vector<T>& src, JsonVariant dst) {
JsonArray array = dst.to<JsonArray>();
for (T item : src)
array.add(item);
}
static std::vector<T> fromJson(JsonVariantConst src) {
std::vector<T> dst;
for (T item : src.as<JsonArrayConst>())
dst.push_back(item);
return dst;
}
static bool checkJson(JsonVariantConst src) {
JsonArrayConst array = src;
bool result = array;
for (JsonVariantConst item : array)
result &= item.is<T>();
return result;
}
};
} // namespace ArduinJson
void WebServer::begin()
{
app.notFound(std::bind(&WebServer::notFound, std::placeholders::_1, std::placeholders::_2));
@@ -42,6 +67,7 @@ void WebServer::begin()
app.get("/acs.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/inputs.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/credentials.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/ntp.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/clear.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/reboot.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
app.get("/update.html", std::bind(&WebServer::handleStaticFile, std::placeholders::_1, std::placeholders::_2));
@@ -50,6 +76,7 @@ void WebServer::begin()
app.get("/info.json", std::bind(&WebServer::InfoGet, std::placeholders::_1, std::placeholders::_2));
app.get("/acs.json", std::bind(&WebServer::ACSGet, std::placeholders::_1, std::placeholders::_2));
app.get("/credentials.json", std::bind(&WebServer::credentialsGet, std::placeholders::_1, std::placeholders::_2));
app.get("/ntp.json", std::bind(&WebServer::ntpGet, std::placeholders::_1, std::placeholders::_2));
app.get("/state.json", std::bind(&WebServer::IOStateGet, std::placeholders::_1, std::placeholders::_2));
app.get("/firmware.json", std::bind(&WebServer::firmwareGet, std::placeholders::_1, std::placeholders::_2));
@@ -57,12 +84,12 @@ void WebServer::begin()
app.post("/acs", std::bind(&WebServer::ACSPost, std::placeholders::_1, std::placeholders::_2));
app.post("/switch", std::bind(&WebServer::SwitchPost, std::placeholders::_1, std::placeholders::_2));
app.post("/credentials", std::bind(&WebServer::credentialsPost, std::placeholders::_1, std::placeholders::_2));
app.post("/ntp", std::bind(&WebServer::ntpPost, std::placeholders::_1, std::placeholders::_2));
app.post("/clear", std::bind(&WebServer::clearPost, std::placeholders::_1, std::placeholders::_2));
app.post("/reboot", std::bind(&WebServer::rebootPost, std::placeholders::_1, std::placeholders::_2));
app.post("/uploadfirmware", std::bind(&WebServer::uploadfirmwarePost, std::placeholders::_1, std::placeholders::_2));
app.post("/firmware", std::bind(&WebServer::firmwarePost, std::placeholders::_1, std::placeholders::_2));
//app.post("/firmware", std::bind(&WebServer::updatefirmwarePost, std::placeholders::_1, std::placeholders::_2));
}
void WebServer::listen(bool connected)
@@ -540,11 +567,34 @@ void WebServer::credentialsPost(HTTPWebServer::Request &req, HTTPWebServer::Resp
{
ConfigStore::Config_t *config = ConfigStore::getConfig();
config->username.value = req.getFormData(config->username.key);
config->password.value = req.getFormData(config->password.key);
config->password.value = req.getFormData(config->password.key);
ConfigStore::saveConfig();
getStaticFile((char *)"/credentials.html", res);
}
//----------- NTP ----------------------
void WebServer::ntpGet(HTTPWebServer::Request &req, HTTPWebServer::Response &res)
{
AddJsonHeader(res);
JsonDocument ntpData;
ConfigStore::Config_t *config = ConfigStore::getConfig();
ntpData[config->ntpserver.key] = std::get<std::string>(config->ntpserver.value);
ntpData[config->ntpserverport.key] = std::get<int>(config->ntpserverport.value);
std::string json;
serializeJson(ntpData, json);
res.writeContent(json);
}
void WebServer::ntpPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res)
{
ConfigStore::Config_t *config = ConfigStore::getConfig();
config->ntpserver.value = req.getFormData(config->ntpserver.key);
config->ntpserverport.value = req.getFormDataInt(config->ntpserverport.key);
ConfigStore::saveConfig();
getStaticFile((char *)"/ntp.html", res);
}
//----------- Clear ----------------------
void WebServer::clearPost(HTTPWebServer::Request &req, HTTPWebServer::Response &res)
{
@@ -581,6 +631,8 @@ void WebServer::firmwareGet(HTTPWebServer::Request &req, HTTPWebServer::Response
JsonDocument fileData;
fileData["gitver"] = std::string(GIT_REV);
fileData["hasfile"] = ACSFileSystem::hasFile("/ota/firmware.tar");
fileData["files"] = ACSFileSystem::directoryList("/ota/");
std::string json;
serializeJson(fileData, json);
@@ -591,24 +643,22 @@ void WebServer::uploadfirmwarePost(HTTPWebServer::Request &req, HTTPWebServer::R
{
printf("Firmware upload post\r\n");
int ret = ACSFileSystem::createDirectory("ota/", 0755);
printf("ret %d\r\n", ret);
if(ACSFileSystem::createDirectory("ota/", 0755) != MBED_SUCCESS)
{
req.cancel();
//printf("create dir failed\r\n");
//req.cancel();
res.sendStatus(500, "Cannot create folder on disk");
return;
}
printf("create file\r\n");
//printf("create file\r\n");
mbed::File firmwareFile;
if (ACSFileSystem::openFile("/ota/firmware.tar", &firmwareFile, O_CREAT|O_RDWR) != MBED_SUCCESS)
{
res.sendStatus(500, "Cannot open file on disk");
return;
}
printf("write file\r\n");
//printf("write file\r\n");
if(req.writeMultipartData(&firmwareFile) != true)
{
firmwareFile.close();
@@ -622,36 +672,88 @@ void WebServer::uploadfirmwarePost(HTTPWebServer::Request &req, HTTPWebServer::R
void WebServer::firmwarePost(HTTPWebServer::Request &req, HTTPWebServer::Response &res)
{
printf("Firmware post\r\n");
//printf("Firmware post\r\n");
std::string mode = req.getFormData("mode");
printf("firmware mode %s\r\n", mode.c_str());
//printf("firmware mode %s\r\n", mode.c_str());
if(mode == "unpack")
if(mode == "delete")
{
mbed::File firmwareFile;
if (ACSFileSystem::openFile("firmware.tar", &firmwareFile, O_CREAT|O_RDWR) != MBED_SUCCESS)
if (ACSFileSystem::clearDirectory("/ota/") != MBED_SUCCESS)
{
res.sendStatus(500, "Cannot clear ota folder");
return;
}
}
else if(mode == "unpack")
{
// mbed::File firmwareFile;
// if (ACSFileSystem::openFile("/ota/firmware.tar", &firmwareFile, O_CREAT|O_RDWR) != MBED_SUCCESS)
// {
// res.sendStatus(500, "Cannot open file on disk");
// return;
// }
// if(Tar::extract(&firmwareFile, "/ota/") != TAR_DONE)
// {
// firmwareFile.close();
// res.sendStatus(500, "Untar failed");
// return;
// }
// firmwareFile.close();
printf("TAR unpack done\r\n");
//md5 checksum
mbedtls_md_context_t ctx;
mbedtls_md_init(&ctx);
int ret = mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_MD5), 0);
//printf("setup %d\r\n", ret);
ret = mbedtls_md_starts(&ctx);
//printf("start %d\r\n", ret);
mbed::File updateFile;
if (ACSFileSystem::openFile("/ota/UPDATE.BIN", &updateFile, O_CREAT|O_RDWR) != MBED_SUCCESS)
{
res.sendStatus(500, "Cannot open file on disk");
return;
}
if(Tar::extract(&firmwareFile, "/ota/") != TAR_DONE)
{
firmwareFile.close();
res.sendStatus(500, "Untar failed");
return;
uint8_t buf[512];
size_t len;
while ((len = updateFile.read(buf, 512)) > 0)
{
ret = mbedtls_md_update(&ctx, buf, len);
//printf("update %d\r\n", ret);
}
firmwareFile.close();
updateFile.close();
unsigned char hash[32];
memset(hash, 0, sizeof(hash));
ret = mbedtls_md_finish(&ctx, hash);
//printf("finish %d\r\n", ret);
mbedtls_md_free(&ctx);
printf("hash = %s\r\n", hash);
printf("sizeof = %u\r\n", sizeof(hash));
for (size_t i = 0; i < sizeof(hash); i++)
{
//snprintf(hex, sizeof(hex), "%02x", sha256[i]);
printf("%02x", hash[i]);
}
printf("\r\n");
printf("TAR unpack done\r\n");
//md5 checksum
}
else if(mode == "update")
{
rebootOTA();
}
getStaticFile((char *)"/update.html", res);
}