Skip to content

Commit ef18bf2

Browse files
authored
Merge pull request #774 from facchinm/m4_extrafixes
STM32H747: general M4 fixes
2 parents fcbb950 + 57d6f9a commit ef18bf2

File tree

13 files changed

+67
-73
lines changed

13 files changed

+67
-73
lines changed

Diff for: libraries/Arduino_CAN/src/Arduino_CAN.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* COMPILE TIME CHECKS
2525
**************************************************************************************/
2626

27-
#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA))
27+
#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA) || defined(CORE_CM4))
2828
# error "CAN only available on Arduino Portenta H7 and Arduino Giga (of all ArduinoCore-mbed enabled boards)."
2929
#endif
3030

Diff for: libraries/Arduino_H7_Video/src/H7DisplayShield.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ int USBCVideoClass::init(int edidmode) {
2222
struct edid recognized_edid;
2323
int err_code = 0;
2424

25+
memset(&recognized_edid, 0, sizeof(recognized_edid));
26+
2527
//Initialization of ANX7625
2628
err_code = anx7625_init(0);
2729
if(err_code < 0) {

Diff for: libraries/Arduino_H7_Video/src/anx7625.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <drivers/DigitalInOut.h>
2626
#include <drivers/I2C.h>
2727

28-
#if defined(ARDUINO_PORTENTA_H7_M7)
28+
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(PORTENTA_H7_PINS)
2929

3030
#include "dsi.h"
3131
#include "anx7625.h"
@@ -42,9 +42,12 @@
4242
#define ANXDEBUG(format, ...) \
4343
printk(BIOS_DEBUG, "%s: " format, __func__, ##__VA_ARGS__)
4444
#else
45-
#define ANXERROR(format, ...)
46-
#define ANXINFO(format, ...)
47-
#define ANXDEBUG(format, ...)
45+
#define ANXERROR(format, ...) \
46+
do { static volatile int _i = 5; _i++; } while (0)
47+
#define ANXINFO(format, ...) \
48+
do { } while (0)
49+
#define ANXDEBUG(format, ...) \
50+
do { } while (0)
4851
#endif
4952

5053
#define FLASH_LOAD_STA 0x05
@@ -506,7 +509,7 @@ int anx7625_init(uint8_t bus) {
506509
return -1;
507510
}
508511
ANXINFO("Powering on anx7625 successfull.\n");
509-
mdelay(200); // Wait for anx7625 to be stable
512+
mdelay(500); // Wait for anx7625 to be stable
510513

511514
if(anx7625_is_power_provider(0)) {
512515
ANXINFO("OTG_ON = 0 -> VBUS ON\n");

Diff for: libraries/Arduino_H7_Video/src/dsi.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ int dsi_init(uint8_t bus, struct edid *edid, struct display_timing *dt) {
5151
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV3;
5252
static const uint32_t DSI_PLLODF = DSI_PLL_OUT_DIV1;
5353
static const uint32_t DSI_TXEXCAPECLOCKDIV = 4;
54+
#undef HSE_VALUE
55+
#define HSE_VALUE 16000000
5456
#else
5557
static const uint32_t DSI_PLLNDIV = 40;
5658
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV2;

Diff for: libraries/Arduino_H7_Video/src/edid.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@
4747
#define EDIDDEBUG(format, ...) \
4848
printk(BIOS_SPEW, "%s: " format, __func__, ##__VA_ARGS__)
4949
#else
50-
#define EDIDERROR(format, ...)
51-
#define EDIDWARNING(format, ...)
52-
#define EDIDDEBUG(format, ...)
50+
#define EDIDERROR(format ...) \
51+
do { } while (0)
52+
#define EDIDWARNING(format ...) \
53+
do { } while (0)
54+
#define EDIDDEBUG(format ...) \
55+
do { } while (0)
5356
#endif
5457

5558
struct edid_context {
@@ -1034,7 +1037,7 @@ parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
10341037
}
10351038

10361039
static const struct {
1037-
int x, y, refresh;
1040+
unsigned int x, y, refresh;
10381041
} established_timings[] = {
10391042
/* 0x23 bit 7 - 0 */
10401043
{720, 400, 70},

Diff for: libraries/Portenta_SDRAM/src/SDRAM.cpp

+34-46
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@ extern "C" {
33
#include "ram_internal.h"
44
}
55

6+
static void MPU_Config() {
7+
MPU_Region_InitTypeDef MPU_InitStruct;
8+
9+
/* Disable the MPU */
10+
HAL_MPU_Disable();
11+
12+
// Initialize SDRAM Start as shareable
13+
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
14+
MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS;
15+
MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_8MB;
16+
//MPU_InitStruct.SubRegionDisable = 0x00;
17+
MPU_InitStruct.Number = MPU_REGION_NUMBER5;
18+
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
19+
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
20+
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
21+
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
22+
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
23+
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;
24+
25+
HAL_MPU_ConfigRegion(&MPU_InitStruct);
26+
27+
/* Enable the MPU */
28+
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
29+
}
30+
631
int SDRAMClass::begin(uint32_t start_address) {
732

8-
printf("FMC_SDRAM_DEVICE->SDCMR: %x\n", FMC_SDRAM_DEVICE->SDCMR);
933
if (FMC_SDRAM_DEVICE->SDCMR == 0x00000000U) {
10-
printf("initializing external ram\n");
1134
bool ret = sdram_init();
1235
if (ret == false) {
1336
return 0;
@@ -18,51 +41,16 @@ int SDRAMClass::begin(uint32_t start_address) {
1841
then enable access/caching for the size used
1942
*/
2043

21-
if (SDRAM_START_ADDRESS != 0xC0000000) {
22-
printf("remap ram to 0x60000000\n");
44+
if (SDRAM_START_ADDRESS == 0x60000000) {
2345
HAL_SetFMCMemorySwappingConfig(FMC_SWAPBMAP_SDRAM_SRAM);
2446
}
2547

26-
#if 0
27-
28-
printf("setup mpu\n");
29-
#define MPU_SDRAM_EXEC_REGION_NUMBER MPU_REGION_SDRAM1
30-
#define MPU_SDRAM_REGION_TEX (0x4 << MPU_RASR_TEX_Pos) /* Cached memory */
31-
#define MPU_SDRAM_EXEC_REGION_SIZE (22 << MPU_RASR_SIZE_Pos) /* 2^(22+1) = 8Mo */
32-
#define MPU_SDRAM_ACCESS_PERMSSION (0x03UL << MPU_RASR_AP_Pos)
33-
#define MPU_SDRAM_REGION_CACHABLE (0x01UL << MPU_RASR_C_Pos)
34-
#define MPU_SDRAM_REGION_BUFFERABLE (0x01UL << MPU_RASR_B_Pos)
35-
36-
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
37-
/* Configure SDARM region as first region */
38-
MPU->RNR = MPU_SDRAM_EXEC_REGION_NUMBER;
39-
/* Set MPU SDARM base address (0xD0000000) */
40-
MPU->RBAR = SDRAM_START_ADDRESS;
41-
/*
42-
- Execute region: RASR[size] = 22 -> 2^(22+1) -> size 8MB
43-
- Access permission: Full access: RASR[AP] = 0b011
44-
- Cached memory: RASR[TEX] = 0b0100
45-
- Disable the Execute Never option: to allow the code execution on SDRAM: RASR[XN] = 0
46-
- Enable the region MPU: RASR[EN] = 1
47-
*/
48-
MPU->RASR = (MPU_SDRAM_EXEC_REGION_SIZE | MPU_SDRAM_ACCESS_PERMSSION | MPU_SDRAM_REGION_TEX | \
49-
MPU_RASR_ENABLE_Msk | MPU_SDRAM_REGION_BUFFERABLE) & ~MPU_RASR_XN_Msk ;
50-
51-
/* Enable MPU and leave the predefined regions to default configuration */
52-
MPU->CTRL |= MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk;
53-
#endif
54-
55-
#if 0
56-
mpu_config_start();
57-
mpu_config_region(MPU_REGION_SDRAM1, SDRAM_START_ADDRESS, MPU_CONFIG_DISABLE(0x00, MPU_REGION_SIZE_512MB));
58-
mpu_config_region(MPU_REGION_SDRAM2, SDRAM_START_ADDRESS, MPU_CONFIG_SDRAM(SDRAM_MPU_REGION_SIZE));
59-
mpu_config_end();
60-
#endif
61-
48+
#ifdef CORE_CM4
49+
MPU_Config();
50+
#endif
6251
}
6352

6453
if (start_address) {
65-
printf("malloc_addblock: allocate %d bytes\n", SDRAM_END_ADDRESS - start_address);
6654
malloc_addblock((void*)start_address, SDRAM_END_ADDRESS - start_address);
6755
}
6856

@@ -77,7 +65,7 @@ void SDRAMClass::free(void* ptr) {
7765
ea_free(ptr);
7866
}
7967

80-
bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
68+
bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast, Stream& _serial) {
8169
uint8_t const pattern = 0xaa;
8270
uint8_t const antipattern = 0x55;
8371
uint8_t *const mem_base = (uint8_t*)SDRAM_START_ADDRESS;
@@ -86,7 +74,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
8674
for (uint8_t i = 1; i; i <<= 1) {
8775
*mem_base = i;
8876
if (*mem_base != i) {
89-
printf("data bus lines test failed! data (%d)\n", i);
77+
_serial.println("data bus lines test failed! data (" + String(i) + ")");
9078
__asm__ volatile ("BKPT");
9179
}
9280
}
@@ -96,7 +84,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
9684
for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) {
9785
mem_base[i] = pattern;
9886
if (mem_base[i] != pattern) {
99-
printf("address bus lines test failed! address (%p)\n", &mem_base[i]);
87+
_serial.println("address bus lines test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
10088
__asm__ volatile ("BKPT");
10189
}
10290
}
@@ -105,7 +93,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
10593
mem_base[0] = antipattern;
10694
for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) {
10795
if (mem_base[i] != pattern) {
108-
printf("address bus overlap %p\n", &mem_base[i]);
96+
_serial.println("address bus overlap! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
10997
__asm__ volatile ("BKPT");
11098
}
11199
}
@@ -115,7 +103,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
115103
for (uint32_t i = 0; i < HW_SDRAM_SIZE; ++i) {
116104
mem_base[i] = pattern;
117105
if (mem_base[i] != pattern) {
118-
printf("address bus test failed! address (%p)\n", &mem_base[i]);
106+
_serial.println("address bus test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
119107
__asm__ volatile ("BKPT");
120108
}
121109
}

Diff for: libraries/Portenta_SDRAM/src/SDRAM.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@
44

55
#include "Arduino.h"
66

7-
#if !defined(CORE_CM4)
87
#define SDRAM_END_ADDRESS (0x60800000)
98
#define SDRAM_START_ADDRESS (0x60000000)
10-
#else
11-
#define SDRAM_END_ADDRESS (0xC0800000)
12-
#define SDRAM_START_ADDRESS (0xC0000000)
13-
#endif
149

1510
class SDRAMClass {
1611
public:
1712
SDRAMClass() {}
1813
int begin(uint32_t start_address = SDRAM_START_ADDRESS);
1914
void* malloc(size_t size);
2015
void free(void* ptr);
21-
bool test(bool fast = false);
16+
bool test(bool fast = false, Stream& _serial = Serial);
2217
private:
2318
void mpu_config_start(void) {
2419
__disable_irq();

Diff for: libraries/SocketWrapper/src/MbedUdp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
4242
SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port);
4343

4444
if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) {
45-
printf("Error joining the multicast group\n");
45+
//printf("Error joining the multicast group\n");
4646
return 0;
4747
}
4848

Diff for: libraries/USBHOST/src/USB251xB.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ void write_hub_configuration(struct usb251xb* hub) {
133133
wbuf[0] = USB251XB_I2C_WRITE_SZ;
134134
memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ);
135135

136-
printf("writing %d byte block %d to 0x%02X\n",
137-
USB251XB_I2C_WRITE_SZ, i, offset);
136+
//printf("writing %d byte block %d to 0x%02X\n",
137+
// USB251XB_I2C_WRITE_SZ, i, offset);
138138

139139
Wire.beginTransmission(0x2C);
140140
Wire.write(offset);

Diff for: libraries/WiFi/src/WiFi.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void* arduino::WiFiClass::handleAPEvents(whd_interface_t ifp, const whd_event_he
9090
if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) {
9191
osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag);
9292
if (result != osOK) {
93-
printf("Release whd_wifi_sleep_flag ERROR: %d", result);
93+
//printf("Release whd_wifi_sleep_flag ERROR: %d", result);
9494
}
9595
}
9696
}

Diff for: libraries/openamp_arduino/src/mailbox_hsem_if.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ void HAL_HSEM_FreeCallback(uint32_t SemMask)
7777
UNUSED(SemMask);
7878
msg_received = RX_NEW_MSG;
7979

80-
osSignalSet(eventHandlerThreadId, 0x1);
81-
8280
#ifdef CORE_CM7
8381
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_1));
8482
#endif
8583
#ifdef CORE_CM4
8684
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
8785
#endif
86+
87+
osSignalSet(eventHandlerThreadId, 0x1);
8888
}
8989

9090
/**

Diff for: libraries/openamp_arduino/src/openamp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb)
135135
}
136136

137137
rpmsg_virtio_init_shm_pool(&shpool, (void *)VRING_BUFF_ADDRESS,
138-
(size_t)SHM_SIZE);
138+
(size_t)VRING_BUFF_SIZE);
139139
rpmsg_init_vdev(&rvdev, vdev, ns_bind_cb, shm_io, &shpool);
140140

141141

@@ -175,7 +175,7 @@ int OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline)
175175
MAILBOX_Poll(rvdev.vdev);
176176
}
177177
if (millis() >= deadline) {
178-
printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept);
178+
//printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept);
179179
return -1;
180180
}
181181
return 0;

Diff for: libraries/openamp_arduino/src/openamp_conf.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ extern int __OPENAMP_region_end__[];
154154
#endif
155155

156156
#define VRING_RX_ADDRESS SHM_START_ADDRESS
157-
#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x400)
158-
#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x800)
159-
#define VRING_ALIGNMENT 4
157+
#define VRING_TX_ADDRESS (SHM_START_ADDRESS + 0x1000)
158+
#define VRING_BUFF_ADDRESS (SHM_START_ADDRESS + 0x2000)
159+
#define VRING_BUFF_SIZE (SHM_SIZE - 0x2000)
160+
#define VRING_ALIGNMENT 32
160161
#define VRING_NUM_BUFFS 16 /* number of rpmsg buffers */
161162

162163
/* Fixed parameter */

0 commit comments

Comments
 (0)