Skip to content
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

STM32H747: general M4 fixes #774

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/Arduino_CAN/src/Arduino_CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* COMPILE TIME CHECKS
**************************************************************************************/

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

Expand Down
2 changes: 2 additions & 0 deletions libraries/Arduino_H7_Video/src/H7DisplayShield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ int USBCVideoClass::init(int edidmode) {
struct edid recognized_edid;
int err_code = 0;

memset(&recognized_edid, 0, sizeof(recognized_edid));

//Initialization of ANX7625
err_code = anx7625_init(0);
if(err_code < 0) {
Expand Down
13 changes: 8 additions & 5 deletions libraries/Arduino_H7_Video/src/anx7625.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <drivers/DigitalInOut.h>
#include <drivers/I2C.h>

#if defined(ARDUINO_PORTENTA_H7_M7)
#if defined(ARDUINO_PORTENTA_H7_M7) || defined(PORTENTA_H7_PINS)

#include "dsi.h"
#include "anx7625.h"
Expand All @@ -42,9 +42,12 @@
#define ANXDEBUG(format, ...) \
printk(BIOS_DEBUG, "%s: " format, __func__, ##__VA_ARGS__)
#else
#define ANXERROR(format, ...)
#define ANXINFO(format, ...)
#define ANXDEBUG(format, ...)
#define ANXERROR(format, ...) \
do { static volatile int _i = 5; _i++; } while (0)
#define ANXINFO(format, ...) \
do { } while (0)
#define ANXDEBUG(format, ...) \
do { } while (0)
#endif

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

if(anx7625_is_power_provider(0)) {
ANXINFO("OTG_ON = 0 -> VBUS ON\n");
Expand Down
2 changes: 2 additions & 0 deletions libraries/Arduino_H7_Video/src/dsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ int dsi_init(uint8_t bus, struct edid *edid, struct display_timing *dt) {
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV3;
static const uint32_t DSI_PLLODF = DSI_PLL_OUT_DIV1;
static const uint32_t DSI_TXEXCAPECLOCKDIV = 4;
#undef HSE_VALUE
#define HSE_VALUE 16000000
#else
static const uint32_t DSI_PLLNDIV = 40;
static const uint32_t DSI_PLLIDF = DSI_PLL_IN_DIV2;
Expand Down
11 changes: 7 additions & 4 deletions libraries/Arduino_H7_Video/src/edid.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@
#define EDIDDEBUG(format, ...) \
printk(BIOS_SPEW, "%s: " format, __func__, ##__VA_ARGS__)
#else
#define EDIDERROR(format, ...)
#define EDIDWARNING(format, ...)
#define EDIDDEBUG(format, ...)
#define EDIDERROR(format ...) \
do { } while (0)
#define EDIDWARNING(format ...) \
do { } while (0)
#define EDIDDEBUG(format ...) \
do { } while (0)
#endif

struct edid_context {
Expand Down Expand Up @@ -1034,7 +1037,7 @@ parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
}

static const struct {
int x, y, refresh;
unsigned int x, y, refresh;
} established_timings[] = {
/* 0x23 bit 7 - 0 */
{720, 400, 70},
Expand Down
80 changes: 34 additions & 46 deletions libraries/Portenta_SDRAM/src/SDRAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@ extern "C" {
#include "ram_internal.h"
}

static void MPU_Config() {
MPU_Region_InitTypeDef MPU_InitStruct;

/* Disable the MPU */
HAL_MPU_Disable();

// Initialize SDRAM Start as shareable
MPU_InitStruct.Enable = MPU_REGION_ENABLE;
MPU_InitStruct.BaseAddress = SDRAM_START_ADDRESS;
MPU_InitStruct.Size = ARM_MPU_REGION_SIZE_8MB;
//MPU_InitStruct.SubRegionDisable = 0x00;
MPU_InitStruct.Number = MPU_REGION_NUMBER5;
MPU_InitStruct.TypeExtField = MPU_TEX_LEVEL0;
MPU_InitStruct.AccessPermission = MPU_REGION_FULL_ACCESS;
MPU_InitStruct.DisableExec = MPU_INSTRUCTION_ACCESS_ENABLE;
MPU_InitStruct.IsShareable = MPU_ACCESS_SHAREABLE;
MPU_InitStruct.IsCacheable = MPU_ACCESS_NOT_CACHEABLE;
MPU_InitStruct.IsBufferable = MPU_ACCESS_NOT_BUFFERABLE;

HAL_MPU_ConfigRegion(&MPU_InitStruct);

/* Enable the MPU */
HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT);
}

int SDRAMClass::begin(uint32_t start_address) {

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

if (SDRAM_START_ADDRESS != 0xC0000000) {
printf("remap ram to 0x60000000\n");
if (SDRAM_START_ADDRESS == 0x60000000) {
HAL_SetFMCMemorySwappingConfig(FMC_SWAPBMAP_SDRAM_SRAM);
}

#if 0

printf("setup mpu\n");
#define MPU_SDRAM_EXEC_REGION_NUMBER MPU_REGION_SDRAM1
#define MPU_SDRAM_REGION_TEX (0x4 << MPU_RASR_TEX_Pos) /* Cached memory */
#define MPU_SDRAM_EXEC_REGION_SIZE (22 << MPU_RASR_SIZE_Pos) /* 2^(22+1) = 8Mo */
#define MPU_SDRAM_ACCESS_PERMSSION (0x03UL << MPU_RASR_AP_Pos)
#define MPU_SDRAM_REGION_CACHABLE (0x01UL << MPU_RASR_C_Pos)
#define MPU_SDRAM_REGION_BUFFERABLE (0x01UL << MPU_RASR_B_Pos)

MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
/* Configure SDARM region as first region */
MPU->RNR = MPU_SDRAM_EXEC_REGION_NUMBER;
/* Set MPU SDARM base address (0xD0000000) */
MPU->RBAR = SDRAM_START_ADDRESS;
/*
- Execute region: RASR[size] = 22 -> 2^(22+1) -> size 8MB
- Access permission: Full access: RASR[AP] = 0b011
- Cached memory: RASR[TEX] = 0b0100
- Disable the Execute Never option: to allow the code execution on SDRAM: RASR[XN] = 0
- Enable the region MPU: RASR[EN] = 1
*/
MPU->RASR = (MPU_SDRAM_EXEC_REGION_SIZE | MPU_SDRAM_ACCESS_PERMSSION | MPU_SDRAM_REGION_TEX | \
MPU_RASR_ENABLE_Msk | MPU_SDRAM_REGION_BUFFERABLE) & ~MPU_RASR_XN_Msk ;

/* Enable MPU and leave the predefined regions to default configuration */
MPU->CTRL |= MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk;
#endif

#if 0
mpu_config_start();
mpu_config_region(MPU_REGION_SDRAM1, SDRAM_START_ADDRESS, MPU_CONFIG_DISABLE(0x00, MPU_REGION_SIZE_512MB));
mpu_config_region(MPU_REGION_SDRAM2, SDRAM_START_ADDRESS, MPU_CONFIG_SDRAM(SDRAM_MPU_REGION_SIZE));
mpu_config_end();
#endif

#ifdef CORE_CM4
MPU_Config();
#endif
}

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

Expand All @@ -77,7 +65,7 @@ void SDRAMClass::free(void* ptr) {
ea_free(ptr);
}

bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast, Stream& _serial) {
uint8_t const pattern = 0xaa;
uint8_t const antipattern = 0x55;
uint8_t *const mem_base = (uint8_t*)SDRAM_START_ADDRESS;
Expand All @@ -86,7 +74,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
for (uint8_t i = 1; i; i <<= 1) {
*mem_base = i;
if (*mem_base != i) {
printf("data bus lines test failed! data (%d)\n", i);
_serial.println("data bus lines test failed! data (" + String(i) + ")");
__asm__ volatile ("BKPT");
}
}
Expand All @@ -96,7 +84,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) {
mem_base[i] = pattern;
if (mem_base[i] != pattern) {
printf("address bus lines test failed! address (%p)\n", &mem_base[i]);
_serial.println("address bus lines test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
__asm__ volatile ("BKPT");
}
}
Expand All @@ -105,7 +93,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
mem_base[0] = antipattern;
for (uint32_t i = 1; i < HW_SDRAM_SIZE; i <<= 1) {
if (mem_base[i] != pattern) {
printf("address bus overlap %p\n", &mem_base[i]);
_serial.println("address bus overlap! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
__asm__ volatile ("BKPT");
}
}
Expand All @@ -115,7 +103,7 @@ bool __attribute__((optimize("O0"))) SDRAMClass::test(bool fast) {
for (uint32_t i = 0; i < HW_SDRAM_SIZE; ++i) {
mem_base[i] = pattern;
if (mem_base[i] != pattern) {
printf("address bus test failed! address (%p)\n", &mem_base[i]);
_serial.println("address bus test failed! address ("+ String((uint32_t)&mem_base[i], HEX) + ")");
__asm__ volatile ("BKPT");
}
}
Expand Down
7 changes: 1 addition & 6 deletions libraries/Portenta_SDRAM/src/SDRAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@

#include "Arduino.h"

#if !defined(CORE_CM4)
#define SDRAM_END_ADDRESS (0x60800000)
#define SDRAM_START_ADDRESS (0x60000000)
#else
#define SDRAM_END_ADDRESS (0xC0800000)
#define SDRAM_START_ADDRESS (0xC0000000)
#endif

class SDRAMClass {
public:
SDRAMClass() {}
int begin(uint32_t start_address = SDRAM_START_ADDRESS);
void* malloc(size_t size);
void free(void* ptr);
bool test(bool fast = false);
bool test(bool fast = false, Stream& _serial = Serial);
private:
void mpu_config_start(void) {
__disable_irq();
Expand Down
2 changes: 1 addition & 1 deletion libraries/SocketWrapper/src/MbedUdp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ uint8_t arduino::MbedUDP::beginMulticast(IPAddress ip, uint16_t port) {
SocketAddress socketAddress = SocketHelpers::socketAddressFromIpAddress(ip, port);

if (_socket.join_multicast_group(socketAddress) != NSAPI_ERROR_OK) {
printf("Error joining the multicast group\n");
//printf("Error joining the multicast group\n");
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/USBHOST/src/USB251xB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void write_hub_configuration(struct usb251xb* hub) {
wbuf[0] = USB251XB_I2C_WRITE_SZ;
memcpy(&wbuf[1], &i2c_wb[offset], USB251XB_I2C_WRITE_SZ);

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

Wire.beginTransmission(0x2C);
Wire.write(offset);
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void* arduino::WiFiClass::handleAPEvents(whd_interface_t ifp, const whd_event_he
if (osSemaphoreGetCount(whd_driver->ap_info.whd_wifi_sleep_flag) < 1) {
osStatus_t result = osSemaphoreRelease(whd_driver->ap_info.whd_wifi_sleep_flag);
if (result != osOK) {
printf("Release whd_wifi_sleep_flag ERROR: %d", result);
//printf("Release whd_wifi_sleep_flag ERROR: %d", result);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/openamp_arduino/src/mailbox_hsem_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ void HAL_HSEM_FreeCallback(uint32_t SemMask)
UNUSED(SemMask);
msg_received = RX_NEW_MSG;

osSignalSet(eventHandlerThreadId, 0x1);

#ifdef CORE_CM7
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_1));
#endif
#ifdef CORE_CM4
HAL_HSEM_ActivateNotification(__HAL_HSEM_SEMID_TO_MASK(HSEM_ID_0));
#endif

osSignalSet(eventHandlerThreadId, 0x1);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/openamp_arduino/src/openamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int MX_OPENAMP_Init(int RPMsgRole, rpmsg_ns_bind_cb ns_bind_cb)
}

rpmsg_virtio_init_shm_pool(&shpool, (void *)VRING_BUFF_ADDRESS,
(size_t)SHM_SIZE);
(size_t)VRING_BUFF_SIZE);
rpmsg_init_vdev(&rvdev, vdev, ns_bind_cb, shm_io, &shpool);


Expand Down Expand Up @@ -175,7 +175,7 @@ int OPENAMP_Wait_EndPointready(struct rpmsg_endpoint *rp_ept, size_t deadline)
MAILBOX_Poll(rvdev.vdev);
}
if (millis() >= deadline) {
printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept);
//printf("OPENAMP_Wait_EndPointready %X timed out\n\r", (unsigned int)rp_ept);
return -1;
}
return 0;
Expand Down
7 changes: 4 additions & 3 deletions libraries/openamp_arduino/src/openamp_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ extern int __OPENAMP_region_end__[];
#endif

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

/* Fixed parameter */
Expand Down
Loading