Skip to content

Commit 7bcb0dd

Browse files
Ashok RaoAshok Rao
authored andcommitted
Adding STM S2_LP as a new target
1 parent 96191e2 commit 7bcb0dd

File tree

7 files changed

+1246
-0
lines changed

7 files changed

+1246
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "stm32f4xx_hal.h"
18+
19+
void _eth_config_mac(ETH_HandleTypeDef *heth)
20+
{
21+
ETH_MACInitTypeDef macconf = {
22+
.Watchdog = ETH_WATCHDOG_ENABLE,
23+
.Jabber = ETH_JABBER_ENABLE,
24+
.InterFrameGap = ETH_INTERFRAMEGAP_96BIT,
25+
.CarrierSense = ETH_CARRIERSENCE_ENABLE,
26+
.ReceiveOwn = ETH_RECEIVEOWN_ENABLE,
27+
.LoopbackMode = ETH_LOOPBACKMODE_DISABLE,
28+
.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE,
29+
.RetryTransmission = ETH_RETRYTRANSMISSION_DISABLE,
30+
.AutomaticPadCRCStrip = ETH_AUTOMATICPADCRCSTRIP_DISABLE,
31+
.BackOffLimit = ETH_BACKOFFLIMIT_10,
32+
.DeferralCheck = ETH_DEFFERRALCHECK_DISABLE,
33+
.ReceiveAll = ETH_RECEIVEAll_DISABLE,
34+
.SourceAddrFilter = ETH_SOURCEADDRFILTER_DISABLE,
35+
.PassControlFrames = ETH_PASSCONTROLFRAMES_BLOCKALL,
36+
.BroadcastFramesReception = ETH_BROADCASTFRAMESRECEPTION_ENABLE,
37+
.DestinationAddrFilter = ETH_DESTINATIONADDRFILTER_NORMAL,
38+
.PromiscuousMode = ETH_PROMISCUOUS_MODE_DISABLE,
39+
.MulticastFramesFilter = ETH_MULTICASTFRAMESFILTER_NONE, // Disable multicast filter
40+
.UnicastFramesFilter = ETH_UNICASTFRAMESFILTER_PERFECT,
41+
.HashTableHigh = 0x0U,
42+
.HashTableLow = 0x0U,
43+
.PauseTime = 0x0U,
44+
.ZeroQuantaPause = ETH_ZEROQUANTAPAUSE_DISABLE,
45+
.PauseLowThreshold = ETH_PAUSELOWTHRESHOLD_MINUS4,
46+
.UnicastPauseFrameDetect = ETH_UNICASTPAUSEFRAMEDETECT_DISABLE,
47+
.ReceiveFlowControl = ETH_RECEIVEFLOWCONTROL_DISABLE,
48+
.TransmitFlowControl = ETH_TRANSMITFLOWCONTROL_DISABLE,
49+
.VLANTagComparison = ETH_VLANTAGCOMPARISON_16BIT,
50+
.VLANTagIdentifier = 0x0U,
51+
};
52+
53+
if (heth->Init.ChecksumMode == ETH_CHECKSUM_BY_HARDWARE) {
54+
macconf.ChecksumOffload = ETH_CHECKSUMOFFLAOD_ENABLE;
55+
} else {
56+
macconf.ChecksumOffload = ETH_CHECKSUMOFFLAOD_DISABLE;
57+
}
58+
59+
(void) HAL_ETH_ConfigMAC(heth, &macconf);
60+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018, STMicroelectronics
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14+
* may be used to endorse or promote products derived from this software
15+
* without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#ifndef USE_USER_DEFINED_HAL_ETH_MSPINIT
30+
31+
#include "stm32f4xx_hal.h"
32+
33+
/**
34+
* Override HAL Eth Init function
35+
*/
36+
void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
37+
{
38+
GPIO_InitTypeDef GPIO_InitStructure;
39+
if (heth->Instance == ETH) {
40+
41+
/* Enable GPIOs clocks */
42+
__HAL_RCC_GPIOA_CLK_ENABLE();
43+
__HAL_RCC_GPIOB_CLK_ENABLE();
44+
__HAL_RCC_GPIOC_CLK_ENABLE();
45+
__HAL_RCC_GPIOG_CLK_ENABLE();
46+
47+
/** ETH GPIO Configuration
48+
RMII_REF_CLK ----------------------> PA1
49+
RMII_MDIO -------------------------> PA2
50+
RMII_MDC --------------------------> PC1
51+
RMII_MII_CRS_DV -------------------> PA7
52+
RMII_MII_RXD0 ---------------------> PC4
53+
RMII_MII_RXD1 ---------------------> PC5
54+
RMII_MII_RXER ---------------------> PG2
55+
RMII_MII_TX_EN --------------------> PG11
56+
RMII_MII_TXD0 ---------------------> PG13
57+
RMII_MII_TXD1 ---------------------> PB13
58+
*/
59+
/* Configure PA1, PA2 and PA7 */
60+
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
61+
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
62+
GPIO_InitStructure.Pull = GPIO_NOPULL;
63+
GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
64+
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
65+
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
66+
67+
/* Configure PB13 */
68+
GPIO_InitStructure.Pin = GPIO_PIN_13;
69+
HAL_GPIO_Init(GPIOB, &GPIO_InitStructure);
70+
71+
/* Configure PC1, PC4 and PC5 */
72+
GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
73+
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
74+
75+
/* Configure PG2, PG11 and PG13 */
76+
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13;
77+
HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
78+
79+
/* Enable the Ethernet global Interrupt */
80+
HAL_NVIC_SetPriority(ETH_IRQn, 0x7, 0);
81+
HAL_NVIC_EnableIRQ(ETH_IRQn);
82+
83+
/* Enable ETHERNET clock */
84+
__HAL_RCC_ETH_CLK_ENABLE();
85+
}
86+
}
87+
88+
/**
89+
* Override HAL Eth DeInit function
90+
*/
91+
void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
92+
{
93+
if (heth->Instance == ETH) {
94+
/* Peripheral clock disable */
95+
__HAL_RCC_ETH_CLK_DISABLE();
96+
97+
/** ETH GPIO Configuration
98+
RMII_REF_CLK ----------------------> PA1
99+
RMII_MDIO -------------------------> PA2
100+
RMII_MDC --------------------------> PC1
101+
RMII_MII_CRS_DV -------------------> PA7
102+
RMII_MII_RXD0 ---------------------> PC4
103+
RMII_MII_RXD1 ---------------------> PC5
104+
RMII_MII_RXER ---------------------> PG2
105+
RMII_MII_TX_EN --------------------> PG11
106+
RMII_MII_TXD0 ---------------------> PG13
107+
RMII_MII_TXD1 ---------------------> PB13
108+
*/
109+
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7);
110+
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
111+
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5);
112+
HAL_GPIO_DeInit(GPIOG, GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13);
113+
114+
/* Disable the Ethernet global Interrupt */
115+
NVIC_DisableIRQ(ETH_IRQn);
116+
}
117+
}
118+
119+
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* mbed Microcontroller Library
2+
*******************************************************************************
3+
* Copyright (c) 2016, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*******************************************************************************
29+
*/
30+
#ifndef MBED_PERIPHERALNAMES_H
31+
#define MBED_PERIPHERALNAMES_H
32+
33+
#include "cmsis.h"
34+
35+
#ifdef __cplusplus
36+
extern "C" {
37+
#endif
38+
39+
typedef enum {
40+
ADC_1 = (int)ADC1_BASE,
41+
ADC_2 = (int)ADC2_BASE,
42+
ADC_3 = (int)ADC3_BASE
43+
} ADCName;
44+
45+
typedef enum {
46+
DAC_1 = (int)DAC_BASE
47+
} DACName;
48+
49+
typedef enum {
50+
UART_1 = (int)USART1_BASE,
51+
UART_2 = (int)USART2_BASE,
52+
UART_3 = (int)USART3_BASE,
53+
UART_4 = (int)UART4_BASE,
54+
UART_5 = (int)UART5_BASE,
55+
UART_6 = (int)USART6_BASE,
56+
UART_7 = (int)UART7_BASE,
57+
UART_8 = (int)UART8_BASE
58+
} UARTName;
59+
60+
typedef enum {
61+
SPI_1 = (int)SPI1_BASE,
62+
SPI_2 = (int)SPI2_BASE,
63+
SPI_3 = (int)SPI3_BASE,
64+
SPI_4 = (int)SPI4_BASE,
65+
SPI_5 = (int)SPI5_BASE,
66+
SPI_6 = (int)SPI6_BASE
67+
} SPIName;
68+
69+
typedef enum {
70+
I2C_1 = (int)I2C1_BASE,
71+
I2C_2 = (int)I2C2_BASE,
72+
I2C_3 = (int)I2C3_BASE
73+
} I2CName;
74+
75+
typedef enum {
76+
PWM_1 = (int)TIM1_BASE,
77+
PWM_2 = (int)TIM2_BASE,
78+
PWM_3 = (int)TIM3_BASE,
79+
PWM_4 = (int)TIM4_BASE,
80+
PWM_5 = (int)TIM5_BASE,
81+
PWM_8 = (int)TIM8_BASE,
82+
PWM_9 = (int)TIM9_BASE,
83+
PWM_10 = (int)TIM10_BASE,
84+
PWM_11 = (int)TIM11_BASE,
85+
PWM_12 = (int)TIM12_BASE,
86+
PWM_13 = (int)TIM13_BASE,
87+
PWM_14 = (int)TIM14_BASE
88+
} PWMName;
89+
90+
typedef enum {
91+
CAN_1 = (int)CAN1_BASE,
92+
CAN_2 = (int)CAN2_BASE
93+
} CANName;
94+
95+
#ifdef __cplusplus
96+
}
97+
#endif
98+
99+
#endif

0 commit comments

Comments
 (0)