Skip to content

Commit c5e1fa7

Browse files
authored
Merge pull request #4242 from bcostm/dev_disco-l475-iot
DISCO_L475VG_IOT01A : Add new target
2 parents b30481d + 8ede14d commit c5e1fa7

File tree

33 files changed

+22709
-10
lines changed

33 files changed

+22709
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/* Copyright (c) 2016 mbed.org, MIT License
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4+
* and associated documentation files (the "Software"), to deal in the Software without
5+
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
6+
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7+
* Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or
10+
* substantial portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
#ifndef USBHAL_STM32L475VG
19+
#define USBHAL_STM32L475VG
20+
21+
#define USBHAL_IRQn OTG_FS_IRQn
22+
23+
24+
#define NB_ENDPOINT 4
25+
/* must be multiple of 4 bytes */
26+
#define MAXTRANSFER_SIZE 0x200
27+
#define FIFO_USB_RAM_SIZE (MAXTRANSFER_SIZE+MAX_PACKET_SIZE_EP0+MAX_PACKET_SIZE_EP1+MAX_PACKET_SIZE_EP2+MAX_PACKET_SIZE_EP3)
28+
#if (FIFO_USB_RAM_SIZE > 0x500)
29+
#error "FIFO dimensioning incorrect"
30+
#endif
31+
32+
typedef struct
33+
{
34+
USBHAL *inst;
35+
void (USBHAL::*bus_reset)(void);
36+
void (USBHAL::*sof)(int frame);
37+
void (USBHAL::*connect_change)(unsigned int connected);
38+
void (USBHAL::*suspend_change)(unsigned int suspended);
39+
void (USBHAL::*ep0_setup)(void);
40+
void (USBHAL::*ep0_in)(void);
41+
void (USBHAL::*ep0_out)(void);
42+
void (USBHAL::*ep0_read)(void);
43+
bool (USBHAL::*ep_realise)(uint8_t endpoint, uint32_t maxPacket, uint32_t flags);
44+
bool (USBHAL::*epCallback[2*NB_ENDPOINT-2])(void);
45+
uint8_t epComplete[8];
46+
/* memorize dummy buffer used for reception */
47+
uint32_t pBufRx[MAXTRANSFER_SIZE>>2];
48+
uint32_t pBufRx0[MAX_PACKET_SIZE_EP0>>2];
49+
}USBHAL_Private_t;
50+
51+
uint32_t HAL_PCDEx_GetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo)
52+
{
53+
uint32_t len;
54+
if (fifo == 0) len = hpcd->Instance->DIEPTXF0_HNPTXFSIZ>>16;
55+
else
56+
len = hpcd->Instance->DIEPTXF[fifo - 1] >> 16;
57+
return len*4;
58+
}
59+
void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) {
60+
USBHAL_Private_t *priv=((USBHAL_Private_t *)(hpcd->pData));
61+
USBHAL *obj= priv->inst;
62+
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
63+
uint32_t sofnum = (USBx_DEVICE->DSTS & USB_OTG_DSTS_FNSOF) >> 8;
64+
void (USBHAL::*func)(int frame) = priv->sof;
65+
/* fix me call with same frame number */
66+
(obj->*func)(sofnum);
67+
}
68+
69+
USBHAL * USBHAL::instance;
70+
71+
USBHAL::USBHAL(void) {
72+
/* init parameter */
73+
USBHAL_Private_t *HALPriv = new(USBHAL_Private_t);
74+
/* initialized all field of init including 0 field */
75+
/* constructor does not fill with zero */
76+
hpcd.Instance = USB_OTG_FS;
77+
/* initialized all field of init including 0 field */
78+
/* constructor does not fill with zero */
79+
memset(&hpcd.Init, 0, sizeof(hpcd.Init));
80+
hpcd.Init.dev_endpoints = NB_ENDPOINT;
81+
hpcd.Init.ep0_mps = MAX_PACKET_SIZE_EP0;
82+
hpcd.Init.phy_itface = PCD_PHY_EMBEDDED;
83+
hpcd.Init.Sof_enable = 1;
84+
hpcd.Init.speed = PCD_SPEED_FULL;
85+
/* pass instance for usage inside call back */
86+
HALPriv->inst = this;
87+
HALPriv->bus_reset = &USBHAL::busReset;
88+
HALPriv->suspend_change = &USBHAL::suspendStateChanged;
89+
HALPriv->connect_change = &USBHAL::connectStateChanged;
90+
HALPriv->sof = &USBHAL::SOF;
91+
HALPriv->ep0_setup = &USBHAL::EP0setupCallback;
92+
HALPriv->ep_realise = &USBHAL::realiseEndpoint;
93+
HALPriv->ep0_in = &USBHAL::EP0in;
94+
HALPriv->ep0_out = &USBHAL::EP0out;
95+
HALPriv->ep0_read = &USBHAL::EP0read;
96+
hpcd.pData = (void*)HALPriv;
97+
HALPriv->epCallback[0] = &USBHAL::EP1_OUT_callback;
98+
HALPriv->epCallback[1] = &USBHAL::EP1_IN_callback;
99+
HALPriv->epCallback[2] = &USBHAL::EP2_OUT_callback;
100+
HALPriv->epCallback[3] = &USBHAL::EP2_IN_callback;
101+
HALPriv->epCallback[4] = &USBHAL::EP3_OUT_callback;
102+
HALPriv->epCallback[5] = &USBHAL::EP3_IN_callback;
103+
instance = this;
104+
105+
__HAL_RCC_PWR_CLK_ENABLE();
106+
107+
HAL_PWREx_EnableVddUSB();
108+
/* Configure USB VBUS GPIO */
109+
__HAL_RCC_GPIOC_CLK_ENABLE();
110+
111+
/* Configure USB FS GPIOs */
112+
__HAL_RCC_GPIOA_CLK_ENABLE();
113+
114+
/* Configure DM DP Pins */
115+
pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
116+
pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
117+
118+
/* Configure VBUS Pin */
119+
pin_function(PC_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
120+
121+
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
122+
123+
hpcd.State = HAL_PCD_STATE_RESET;
124+
125+
HAL_PCD_Init(&hpcd);
126+
/* 1.25kbytes */
127+
/* min value 16 (= 16 x 4 bytes) */
128+
/* max value 256 (= 1K bytes ) */
129+
/* maximum sum is 0x140 */
130+
HAL_PCDEx_SetRxFiFo(&hpcd, (MAXTRANSFER_SIZE/4));
131+
/* bulk/int 64 bytes in FS */
132+
HAL_PCDEx_SetTxFiFo(&hpcd, 0, (MAX_PACKET_SIZE_EP0/4)+1);
133+
/* bulk/int bytes in FS */
134+
HAL_PCDEx_SetTxFiFo(&hpcd, 1, (MAX_PACKET_SIZE_EP1/4)+1);
135+
HAL_PCDEx_SetTxFiFo(&hpcd, 2, (MAX_PACKET_SIZE_EP2/4));
136+
/* ISOchronous */
137+
HAL_PCDEx_SetTxFiFo(&hpcd, 3, (MAX_PACKET_SIZE_EP3/4));
138+
139+
NVIC_SetVector(USBHAL_IRQn,(uint32_t)&_usbisr);
140+
NVIC_SetPriority( USBHAL_IRQn, 1);
141+
142+
HAL_PCD_Start(&hpcd);
143+
}
144+
145+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Copyright (c) 2016 mbed.org, MIT License
2+
*
3+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4+
* and associated documentation files (the "Software"), to deal in the Software without
5+
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
6+
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7+
* Software is furnished to do so, subject to the following conditions:
8+
*
9+
* The above copyright notice and this permission notice shall be included in all copies or
10+
* substantial portions of the Software.
11+
*
12+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17+
*/
18+
#include "USBHAL_STM32L475VG.h"

features/unsupported/tests/mbed/analog/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ AnalogOut out(A1);
6666
defined(TARGET_NUCLEO_F303ZE) || \
6767
defined(TARGET_NUCLEO_F410RB) || \
6868
defined(TARGET_NUCLEO_F446ZE) || \
69-
defined(TARGET_NUCLEO_F429ZI)
69+
defined(TARGET_NUCLEO_F429ZI) || defined(TARGET_DISCO_L475VG_IOT01A)
7070
AnalogIn in(A0);
7171
AnalogOut out(D13);
7272

features/unsupported/tests/mbed/can/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main() {
6969
!defined(TARGET_NUCLEO_F042K6) && !defined(TARGET_NUCLEO_F334R8) && \
7070
!defined(TARGET_NUCLEO_F303RE) && !defined(TARGET_NUCLEO_F303K8) && \
7171
!defined(TARGET_NUCLEO_F302R8) && !defined(TARGET_NUCLEO_F103RB) && \
72-
!defined(TARGET_DISCO_L476VG) && !defined(TARGET_NUCLEO_L476RG) && \
72+
!defined(TARGET_DISCO_L476VG) && !defined(TARGET_DISCO_L475VG_IOT01A) && !defined(TARGET_NUCLEO_L476RG) && \
7373
!defined(TARGET_NUCLEO_L432KC)) && !defined(TARGET_DISCO_F303VC)
7474
printf("loop()\n");
7575
if(can2.read(msg)) {

features/unsupported/tests/mbed/can_interrupt/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void send() {
6464
!defined(TARGET_NUCLEO_F042K6) && !defined(TARGET_NUCLEO_F334R8) && \
6565
!defined(TARGET_NUCLEO_F303RE) && !defined(TARGET_NUCLEO_F303K8) && \
6666
!defined(TARGET_NUCLEO_F302R8) && !defined(TARGET_NUCLEO_F103RB) && \
67-
!defined(TARGET_DISCO_L476VG) && !defined(TARGET_NUCLEO_L476RG) && \
67+
!defined(TARGET_DISCO_L476VG) && !defined(TARGET_DISCO_L475VG_IOT01A) && !defined(TARGET_NUCLEO_L476RG) && \
6868
!defined(TARGET_NUCLEO_L432KC) && !defined(TARGET_DISCO_F303VC))
6969
void read() {
7070
CANMessage msg;

features/unsupported/tests/mbed/can_loopback/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CAN can1(P5_9, P5_10);
1818
defined(TARGET_NUCLEO_F303RE) || defined(TARGET_NUCLEO_F303K8) || \
1919
defined(TARGET_NUCLEO_F302R8) || defined(TARGET_NUCLEO_F446RE) || \
2020
defined(TARGET_DISCO_F429ZI) || \
21-
defined(TARGET_NUCLEO_F746ZG) || defined(TARGET_DISCO_L476VG) || \
21+
defined(TARGET_NUCLEO_F746ZG) || defined(TARGET_DISCO_L476VG) || defined(TARGET_DISCO_L475VG_IOT01A) || \
2222
defined(TARGET_NUCLEO_F412ZG) || \
2323
defined(TARGET_NUCLEO_L476RG) || defined(TARGET_NUCLEO_L432KC)
2424
CAN can1(PA_11, PA_12);

features/unsupported/tests/mbed/i2c_master_slave/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ I2CSlave slave(D2, D4);
7272
defined (TARGET_NUCLEO_F072RB)
7373
I2CSlave slave(PB_11, D6);
7474

75+
#elif defined (TARGET_DISCO_L475VG_IOT01A)
76+
I2CSlave slave(A4, A5);
77+
7578
#else
7679
I2CSlave slave(D3, D6);
7780

features/unsupported/tests/mbed/i2c_master_slave_asynch/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ I2C master(D14, D15); // I2C_SDA, I2C_SCL
4747
I2CSlave slave(PB_11, PB_10);
4848
#elif defined(TARGET_NUCLEO_F303RE)
4949
I2CSlave slave(D2, D8);
50+
#elif defined (TARGET_DISCO_L475VG_IOT01A)
51+
I2CSlave slave(A4, A5);
5052
#else
5153
I2CSlave slave(D3, D6);
5254
#endif
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* mbed Microcontroller Library
2+
*******************************************************************************
3+
* Copyright (c) 2017, 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+
LPUART_1 = (int)LPUART1_BASE
56+
} UARTName;
57+
58+
#define STDIO_UART_TX PB_6
59+
#define STDIO_UART_RX PB_7
60+
#define STDIO_UART UART_1
61+
62+
typedef enum {
63+
SPI_1 = (int)SPI1_BASE,
64+
SPI_2 = (int)SPI2_BASE,
65+
SPI_3 = (int)SPI3_BASE
66+
} SPIName;
67+
68+
typedef enum {
69+
I2C_1 = (int)I2C1_BASE,
70+
I2C_2 = (int)I2C2_BASE,
71+
I2C_3 = (int)I2C3_BASE
72+
} I2CName;
73+
74+
typedef enum {
75+
PWM_1 = (int)TIM1_BASE,
76+
PWM_2 = (int)TIM2_BASE,
77+
PWM_3 = (int)TIM3_BASE,
78+
PWM_4 = (int)TIM4_BASE,
79+
PWM_5 = (int)TIM5_BASE,
80+
PWM_8 = (int)TIM8_BASE,
81+
PWM_15 = (int)TIM15_BASE,
82+
PWM_16 = (int)TIM16_BASE,
83+
PWM_17 = (int)TIM17_BASE
84+
} PWMName;
85+
86+
typedef enum {
87+
CAN_1 = (int)CAN1_BASE
88+
} CANName;
89+
90+
#ifdef __cplusplus
91+
}
92+
#endif
93+
94+
#endif

0 commit comments

Comments
 (0)