Skip to content

Commit d0db9b2

Browse files
authored
Extend cbridge to support generation as pair - improved (#165)
1 parent 86c2259 commit d0db9b2

1,482 files changed

Lines changed: 1372911 additions & 28331 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/stm32CubeMX/mxDevice.go

Lines changed: 59 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -193,80 +193,68 @@ func writeMXdeviceH(contextMap map[string]map[string]string, srcFolder string, m
193193
}
194194

195195
if generatedAsPair == "true" {
196-
/* search into file peripheral */
197-
if strings.Contains(peripheral, "I2C") {
198-
i2c := path.Join(srcFolderAbs, "i2c.c")
199-
i2c = filepath.Clean(i2c)
200-
i2c = filepath.ToSlash(i2c)
201-
fI2C, errI2c := os.Open(i2c)
202-
if errI2c != nil {
203-
return errI2c
204-
} else {
205-
i2cInfo, err = getI2cInfo(fI2C, peripheral)
206-
if err != nil {
207-
return err
208-
}
209-
pins, err = getPins(contextMap, fI2C, peripheral)
210-
if err != nil {
211-
return err
212-
}
213-
defer fI2C.Close()
214-
}
215-
} else if strings.Contains(peripheral, "USB") {
216-
usbFileName := "usb.c"
217-
if strings.Contains(peripheral, "OTG") {
218-
usbFileName = "usb_otg.c"
219-
}
220-
usb := path.Join(srcFolderAbs, usbFileName)
221-
usb = filepath.Clean(usb)
222-
usb = filepath.ToSlash(usb)
223-
fUsb, errUsb := os.Open(usb)
224-
if errUsb != nil {
225-
return errUsb
226-
} else {
227-
usbHandle, err = getUSBHandle(fUsb, peripheral)
228-
if err != nil {
229-
return err
230-
}
231-
pins, err = getPins(contextMap, fUsb, peripheral)
232-
if err != nil {
233-
return err
196+
197+
periName := map[string]string{
198+
"USART": "usart.c",
199+
"UART": "usart.c",
200+
"LPUART": "usart.c",
201+
"SPI": "spi.c",
202+
"I2C": "i2c.c",
203+
"ETH": "eth.c",
204+
"SDMMC": "sdmmc.c",
205+
"CAN": "can.c",
206+
"USB": "usb.c",
207+
"SDIO": "sdio.c"}
208+
209+
for key, value := range periName {
210+
/* search for peripherals to handle pins*/
211+
if strings.Contains(peripheral, key) {
212+
fileName := value
213+
if strings.Contains(peripheral, "OTG") {
214+
fileName = "usb_otg.c"
215+
} else if strings.Contains(peripheral, "FD") {
216+
fileName = "fdcan.c"
234217
}
235-
defer fUsb.Close()
236-
}
237-
} else if strings.Contains(peripheral, "SDMMC") {
238-
mmc := path.Join(srcFolderAbs, "sdmmc.c")
239-
mmc = filepath.Clean(mmc)
240-
mmc = filepath.ToSlash(mmc)
241-
fMMC, errMmc := os.Open(mmc)
242-
if errMmc != nil {
243-
return errMmc
244-
} else {
245-
mciMode, err = getMCIMode(fMMC, peripheral)
246-
if err != nil {
247-
return err
218+
periPath := path.Join(srcFolderAbs, fileName)
219+
periPath = filepath.Clean(periPath)
220+
periPath = filepath.ToSlash(periPath)
221+
fPeri, errPeri := os.Open(periPath)
222+
if errPeri != nil {
223+
return errPeri
224+
} else {
225+
pins, err = getPins(contextMap, fPeri, peripheral)
226+
if err != nil {
227+
return err
228+
}
248229
}
249-
pins, err = getPins(contextMap, fMMC, peripheral)
250-
if err != nil {
251-
return err
230+
/* peripherals custom infos */
231+
if strings.Contains(peripheral, "I2C") {
232+
i2cInfo, err = getI2cInfo(fPeri, peripheral)
233+
if err != nil {
234+
return err
235+
}
236+
} else if strings.Contains(peripheral, "USB") {
237+
usbHandle, err = getUSBHandle(fPeri, peripheral)
238+
if err != nil {
239+
return err
240+
}
241+
} else if strings.Contains(peripheral, "SDMMC") {
242+
mciMode, err = getMCIMode(fPeri, peripheral)
243+
if err != nil {
244+
return err
245+
}
246+
} else if strings.Contains(peripheral, "SDIO") {
247+
mciMode, err = getMCIMode(fPeri, peripheral)
248+
if err != nil {
249+
return err
250+
}
251+
} else if strings.Contains(peripheral, "SPI") {
252+
if freq == "" {
253+
freq = getSPIFreq(fPeri, contextMap, peripheral)
254+
}
252255
}
253-
defer fMMC.Close()
254-
}
255-
} else if strings.Contains(peripheral, "SPI") {
256-
spi := path.Join(srcFolderAbs, "spi.c")
257-
spi = filepath.Clean(spi)
258-
spi = filepath.ToSlash(spi)
259-
fSPI, errSpi := os.Open(spi)
260-
if errSpi != nil {
261-
return errSpi
262-
}
263-
defer fSPI.Close()
264-
pins, err = getPins(contextMap, fSPI, peripheral)
265-
if err != nil {
266-
return err
267-
}
268-
if freq == "" {
269-
freq = getSPIFreq(fSPI, contextMap, peripheral)
256+
defer fPeri.Close()
257+
break
270258
}
271259
}
272260
} else {

internal/stm32CubeMX/mxDevice_test.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,92 @@ import (
1212
"errors"
1313
"io"
1414
"os"
15+
"path/filepath"
1516
"reflect"
17+
"strings"
1618
"testing"
1719
"time"
1820
)
1921

22+
func Test_MXDeviceContexts(t *testing.T) {
23+
24+
tests := []struct {
25+
name string
26+
cfgPath string
27+
cfgName string
28+
cfgRefName string
29+
wantErr bool
30+
}{
31+
{"STM32H7_SC", "STM32H7_SC/STM32CubeMX/device/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
32+
{"STM32H7_DC:CM4", "STM32H7_DC/STM32CubeMX/STM32H745BGTx/MX_Device/CM4/", "MX_Device.h", "MX_Device_ref.h", false},
33+
{"STM32H7_DC:CM7", "STM32H7_DC/STM32CubeMX/STM32H745BGTx/MX_Device/CM7/", "MX_Device.h", "MX_Device_ref.h", false},
34+
{"STM32U5_noTZ", "STM32U5_noTZ/STM32CubeMX/Board/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
35+
{"STM32U5_TZ:NonSecure", "STM32U5_TZ/STM32CubeMX/Board/MX_Device/NonSecure/", "MX_Device.h", "MX_Device_ref.h", false},
36+
{"STM32U5_TZ:Secure", "STM32U5_TZ/STM32CubeMX/Board/MX_Device/Secure/", "MX_Device.h", "MX_Device_ref.h", false},
37+
{"STM32WL_DC:CM0PLUS", "STM32WL_DC/test/STM32CubeMX/STM32WL54CCUx/MX_Device/CM0PLUS/", "MX_Device.h", "MX_Device_ref.h", false},
38+
{"STM32WL_DC:CM4", "STM32WL_DC/test/STM32CubeMX/STM32WL54CCUx/MX_Device/CM4/", "MX_Device.h", "MX_Device_ref.h", false},
39+
{"STM32H5", "STM32H5/STM32CubeMX/STM32H573IIKxQ/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
40+
{"STM32H7", "STM32H7/STM32CubeMX/STM32H743XIHx/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
41+
{"STM32F7", "STM32F7/STM32CubeMX/STM32F746NGHx/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
42+
{"STM32U5", "STM32U5/STM32CubeMX/STM32U5G9ZJTxQ/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
43+
{"STM32F2", "STM32F2/STM32CubeMX/STM32F217IGHx/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
44+
{"STM32F4", "STM32F4/STM32CubeMX/STM32F469NIHx/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
45+
{"STM32G4", "STM32G4/STM32CubeMX/STM32G474QETx/MX_Device/", "MX_Device.h", "MX_Device_ref.h", false},
46+
}
47+
for _, tt := range tests {
48+
t.Run(tt.name, func(t *testing.T) {
49+
50+
tt.cfgPath = filepath.Join("../../testdata/testExamples/", tt.cfgPath)
51+
52+
data, err := os.ReadFile(filepath.Join(tt.cfgPath, tt.cfgName))
53+
if err != nil {
54+
t.Errorf(" %s; cannot open MX_Device.h file", tt.name)
55+
return
56+
}
57+
58+
dataRef, errRef := os.ReadFile(filepath.Join(tt.cfgPath, tt.cfgRefName))
59+
if errRef != nil {
60+
t.Errorf(" %s; cannot open MX_Device_ref.h file", tt.name)
61+
return
62+
}
63+
64+
// Normalize line endings inline
65+
content := strings.ReplaceAll(string(data), "\r\n", "\n")
66+
contentRef := strings.ReplaceAll(string(dataRef), "\r\n", "\n")
67+
68+
lines := strings.Split(content, "\n")
69+
linesRef := strings.Split(contentRef, "\n")
70+
71+
content = strings.Join(lines[3:], "\n")
72+
contentRef = strings.Join(linesRef[3:], "\n")
73+
74+
if reflect.DeepEqual((content != contentRef), !tt.wantErr) {
75+
t.Errorf(" %s; MX_Device.h file content mismatch", tt.name)
76+
}
77+
})
78+
}
79+
}
80+
81+
func Test_ReadContexts(t *testing.T) {
82+
83+
tests := []struct {
84+
name string
85+
iocFile string
86+
params BridgeParamType
87+
wantErr bool
88+
}{
89+
{"STM32H7_SC", "../../testdata/testExamples/STM32H7_SC/STM32CubeMX/device/STM32CubeMX/STM32CubeMX.ioc", BridgeParamType{"device", "", "STM32H743AGIx", "", "test", "single-core", "", "", "AC6", "", "test", "", ""}, false},
90+
}
91+
for _, tt := range tests {
92+
t.Run(tt.name, func(t *testing.T) {
93+
argsSlice := []BridgeParamType{tt.params}
94+
if err := ReadContexts(tt.iocFile, argsSlice); (err != nil) != tt.wantErr {
95+
t.Errorf("ReadContexts() %s error = %v, wantErr %v", tt.name, err, tt.wantErr)
96+
}
97+
})
98+
}
99+
}
100+
20101
func Test_createContextMap(t *testing.T) {
21102
t.Parallel()
22103

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# A project translates into one executable or library.
2+
project:
3+
4+
# List components to use for your application.
5+
# A software component is a re-usable unit that may be configurable.
6+
components:
7+
- component: ARM::CMSIS:CORE
8+
- component: Device:CubeMX
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# A solution is a collection of related projects that share same base configuration.
2+
solution:
3+
created-for: CMSIS-Toolbox@2.6.0
4+
cdefault:
5+
6+
# List of tested compilers that can be selected
7+
select-compiler:
8+
- compiler: AC6
9+
- compiler: GCC
10+
- compiler: IAR
11+
12+
# List the packs that define the device and/or board.
13+
packs:
14+
- pack: Keil::STM32F2xx_DFP
15+
- pack: ARM::CMSIS
16+
17+
# List different hardware targets that are used to deploy the solution.
18+
target-types:
19+
- type: STM32F217IGHx
20+
device: STM32F217IGHx
21+
# device: STMicroelectronics::STM32F103RB
22+
23+
# List of different build configurations.
24+
build-types:
25+
- type: Debug
26+
debug: on
27+
optimize: none
28+
29+
- type: Release
30+
debug: off
31+
optimize: balanced
32+
33+
# List related projects.
34+
projects:
35+
- project: CubeMX.cproject.yml
36+
compiler: AC6
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
generator-import:
2+
for-device: STM32F217IGHx
3+
define:
4+
- USE_HAL_DRIVER
5+
- STM32F217xx
6+
add-path:
7+
- ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Inc
8+
- ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Inc/Legacy
9+
- ./STM32CubeMX/Drivers/CMSIS/Device/ST/STM32F2xx/Include
10+
- ./STM32CubeMX/Inc
11+
- ./MX_Device
12+
groups:
13+
- group: CubeMX
14+
files:
15+
- file: ./STM32CubeMX/Src/main.c
16+
- file: ./STM32CubeMX/Src/gpio.c
17+
- file: ./STM32CubeMX/Src/eth.c
18+
- file: ./STM32CubeMX/Src/i2c.c
19+
- file: ./STM32CubeMX/Src/sdio.c
20+
- file: ./STM32CubeMX/Src/spi.c
21+
- file: ./STM32CubeMX/Src/usart.c
22+
- file: ./STM32CubeMX/Src/usb_otg.c
23+
- file: ./STM32CubeMX/Src/stm32f2xx_it.c
24+
- file: ./STM32CubeMX/Src/stm32f2xx_hal_msp.c
25+
- file: ./STM32CubeMX/MDK-ARM/startup_stm32f217xx.s
26+
- file: ./STM32CubeMX/Src/system_stm32f2xx.c
27+
- group: STM32 HAL Driver
28+
files:
29+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_eth.c
30+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal.c
31+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_rcc.c
32+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_rcc_ex.c
33+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_cortex.c
34+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_flash.c
35+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_flash_ex.c
36+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pwr.c
37+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_pwr_ex.c
38+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_gpio.c
39+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_dma.c
40+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_dma_ex.c
41+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_exti.c
42+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_i2c.c
43+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_ll_sdmmc.c
44+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_sd.c
45+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_mmc.c
46+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_spi.c
47+
- file: ./STM32CubeMX/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_uart.c

0 commit comments

Comments
 (0)