-
Notifications
You must be signed in to change notification settings - Fork 36
Arduino Opta support #531
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
base: main
Are you sure you want to change the base?
Arduino Opta support #531
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Copyright (c) 2020 ARM Limited. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| target_sources(mbed-emac | ||
| PRIVATE | ||
| stm32h7_eth_init.c | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* mbed Microcontroller Library | ||
| * Copyright (c) 2022, STMicroelectronics | ||
| * All rights reserved. | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * 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. | ||
| */ | ||
|
|
||
| #define ETHERNET 1 | ||
|
|
||
|
|
||
| #include "stm32h7xx_hal.h" | ||
| #include "opta_power.h" | ||
| #include "platform/mbed_critical.h" | ||
| #include "PinNames.h" | ||
|
|
||
| #define ETH_TX_EN_Pin GPIO_PIN_11 | ||
| #define ETH_TX_EN_GPIO_Port GPIOG | ||
| #define ETH_TXD1_Pin GPIO_PIN_12 | ||
| #define ETH_TXD1_GPIO_Port GPIOG | ||
| #define ETH_TXD0_Pin GPIO_PIN_13 | ||
| #define ETH_TXD0_GPIO_Port GPIOG | ||
| #define ETH_MDC_SAI4_D1_Pin GPIO_PIN_1 | ||
| #define ETH_MDC_SAI4_D1_GPIO_Port GPIOC | ||
| #define ETH_MDIO_Pin GPIO_PIN_2 | ||
| #define ETH_MDIO_GPIO_Port GPIOA | ||
| #define ETH_REF_CLK_Pin GPIO_PIN_1 | ||
| #define ETH_REF_CLK_GPIO_Port GPIOA | ||
| #define ETH_CRS_DV_Pin GPIO_PIN_7 | ||
| #define ETH_CRS_DV_GPIO_Port GPIOA | ||
| #define ETH_RXD0_Pin GPIO_PIN_4 | ||
| #define ETH_RXD0_GPIO_Port GPIOC | ||
| #define ETH_RXD1_Pin GPIO_PIN_5 | ||
| #define ETH_RXD1_GPIO_Port GPIOC | ||
|
|
||
| /** | ||
| * Override HAL Eth Init function | ||
| */ | ||
| void EthInitPinmappings(void) | ||
| { | ||
| GPIO_InitTypeDef GPIO_InitStruct; | ||
| enableEthPowerSupply(); | ||
|
|
||
| /* GPIO Ports Clock Enable */ | ||
| __HAL_RCC_GPIOA_CLK_ENABLE(); | ||
| // __HAL_RCC_GPIOB_CLK_ENABLE(); | ||
| __HAL_RCC_GPIOC_CLK_ENABLE(); | ||
| __HAL_RCC_GPIOG_CLK_ENABLE(); | ||
| // __HAL_RCC_GPIOH_CLK_ENABLE(); | ||
|
|
||
| /* Enable Peripheral clock */ | ||
| __HAL_RCC_ETH1MAC_CLK_ENABLE(); | ||
| __HAL_RCC_ETH1TX_CLK_ENABLE(); | ||
| __HAL_RCC_ETH1RX_CLK_ENABLE(); | ||
|
|
||
| /* Set pinstrap for 100mbit */ | ||
| // TODO | ||
|
|
||
| /* Reset ETH Phy */ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I missed this earlier, oops, but this entire block can be removed. We reset the ethernet phy during its initialization, so as long as you implement
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried removing the reset code but that caused crashes at initialization. Which part did you want removed?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh that's really weird, what was the crash? You should be able to safely remove the following lines: __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;
gpio_eth_rst_init_structure.Pull = GPIO_NOPULL;
gpio_eth_rst_init_structure.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOJ, &gpio_eth_rst_init_structure);and then HAL_Delay(25);
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 0);
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 1);
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still get an Mbed OS crash (4 long/4 short red LED pattern) when I remove the code above. Can't say for sure what's going on as I only have one Opta device and can't really open it up to attach a debugger. What's even curiouser is that I found a call to
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm what if you keep the GPIOJ clock enable but remove everything else? Or if you just remove the second group of lines?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @putertubby Any updates on this? If you can check this out, I'm good to merge the PR!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haven't had the time to dig further yet. I'll try to look into it. 🤞 |
||
| __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; | ||
| gpio_eth_rst_init_structure.Pull = GPIO_NOPULL; | ||
| gpio_eth_rst_init_structure.Speed = GPIO_SPEED_FREQ_LOW; | ||
| HAL_GPIO_Init(GPIOJ, &gpio_eth_rst_init_structure); | ||
|
|
||
| gpio_eth_rst_init_structure.Pin = ETH_RXD0_Pin | ETH_RXD1_Pin; | ||
| 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); | ||
|
|
||
| HAL_Delay(25); | ||
| HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 0); | ||
| HAL_Delay(100); | ||
| HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 1); | ||
|
|
||
| /**ETH GPIO Configuration | ||
| PG11 ------> ETH_TX_EN | ||
| PG12 ------> ETH_TXD1 | ||
| PG13 ------> ETH_TXD0 | ||
| PC1 ------> ETH_MDC | ||
| PA2 ------> ETH_MDIO | ||
| PA1 ------> ETH_REF_CLK | ||
| PA7 ------> ETH_CRS_DV | ||
| 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; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||
| GPIO_InitStruct.Alternate = GPIO_AF11_ETH; | ||
| HAL_GPIO_Init(GPIOG, &GPIO_InitStruct); | ||
|
|
||
| GPIO_InitStruct.Pin = ETH_MDC_SAI4_D1_Pin | ETH_RXD0_Pin | ETH_RXD1_Pin; | ||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||
| GPIO_InitStruct.Alternate = GPIO_AF11_ETH; | ||
| HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); | ||
|
|
||
| GPIO_InitStruct.Pin = ETH_MDIO_Pin | ETH_REF_CLK_Pin | ETH_CRS_DV_Pin; | ||
| GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | ||
| GPIO_InitStruct.Pull = GPIO_NOPULL; | ||
| GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; | ||
| GPIO_InitStruct.Alternate = GPIO_AF11_ETH; | ||
| HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | ||
| } | ||
|
|
||
| /** | ||
| * Override HAL Eth DeInit function | ||
| */ | ||
| void EthDeinitPinmappings() | ||
| { | ||
| /* Peripheral clock disable */ | ||
| __HAL_RCC_ETH1MAC_CLK_DISABLE(); | ||
| __HAL_RCC_ETH1TX_CLK_DISABLE(); | ||
| __HAL_RCC_ETH1RX_CLK_DISABLE(); | ||
|
|
||
| /**ETH GPIO Configuration | ||
| PG11 ------> ETH_TX_EN | ||
| PG12 ------> ETH_TXD1 | ||
| PG13 ------> ETH_TXD0 | ||
| PC1 ------> ETH_MDC | ||
| PA2 ------> ETH_MDIO | ||
| PA1 ------> ETH_REF_CLK | ||
| PA7 ------> ETH_CRS_DV | ||
| PC4 ------> ETH_RXD0 | ||
| PC5 ------> ETH_RXD1 | ||
| */ | ||
| HAL_GPIO_DeInit(GPIOG, ETH_TX_EN_Pin | ETH_TXD1_Pin | ETH_TXD0_Pin); | ||
|
|
||
| HAL_GPIO_DeInit(GPIOC, ETH_MDC_SAI4_D1_Pin | ETH_RXD0_Pin | ETH_RXD1_Pin); | ||
|
|
||
| HAL_GPIO_DeInit(GPIOA, ETH_MDIO_Pin | ETH_REF_CLK_Pin | ETH_CRS_DV_Pin); | ||
|
|
||
| HAL_GPIO_WritePin(GPIOJ, GPIO_PIN_15, 0); | ||
| } | ||
|
|
||
| // Get Ethernet PHY reset pin | ||
| PinName EthGetPhyResetPin(void) | ||
| { | ||
| return PJ_15; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| add_library(mbed-arduino-opta-m4 INTERFACE) | ||
|
|
||
| target_sources(mbed-arduino-opta-m4 | ||
| INTERFACE | ||
| opta_power.cpp | ||
| ) | ||
|
|
||
| target_include_directories(mbed-arduino-opta-m4 | ||
| INTERFACE | ||
| . | ||
| ) | ||
|
|
||
| target_link_libraries(mbed-arduino-opta-m4 INTERFACE mbed-stm32h747xi-cm4) | ||
|
|
||
| add_library(mbed-arduino-opta-m7 INTERFACE) | ||
|
|
||
| target_sources(mbed-arduino-opta-m7 | ||
| INTERFACE | ||
| opta_power.cpp | ||
| ) | ||
|
|
||
| target_include_directories(mbed-arduino-opta-m7 | ||
| INTERFACE | ||
| . | ||
| ) | ||
|
|
||
| target_link_libraries(mbed-arduino-opta-m7 INTERFACE mbed-stm32h747-arduino) |
Uh oh!
There was an error while loading. Please reload this page.