Skip to content

Commit 4614509

Browse files
facchinmpennam
authored andcommitted
Force WHD firmware in external filesystem
1 parent 4d33db1 commit 4614509

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/port/cy_hal.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,53 @@
33
#include "cyhal_spi.h"
44
#include "cyhal_gpio.h"
55
#include <stdio.h>
6+
#include "sockets.h"
67

78
void Cy_SysLib_Delay(uint32_t milliseconds) {
89
thread_sleep_for(milliseconds);
910
}
1011

1112
void Cy_SysLib_DelayUs(uint16_t microseconds) {
1213
wait_us(microseconds);
14+
}
15+
16+
static bool filesystem_mounted = false;
17+
extern bool wiced_filesystem_mount();
18+
19+
int wiced_filesystem_file_open(int* fd, const char* filename) {
20+
if (!filesystem_mounted) {
21+
filesystem_mounted = wiced_filesystem_mount();
22+
}
23+
if (!filesystem_mounted) {
24+
return WHD_BADARG;
25+
}
26+
*fd = open(filename, O_RDONLY);
27+
if (*fd == -1) {
28+
return WHD_BADARG;
29+
}
30+
return WHD_SUCCESS;
31+
}
32+
33+
int wiced_filesystem_file_seek(int* fd, uint32_t offset) {
34+
if (*fd == -1) {
35+
return WHD_BADARG;
36+
}
37+
lseek(*fd, offset, SEEK_SET);
38+
return WHD_SUCCESS;
39+
}
40+
41+
int wiced_filesystem_file_read(int* fd, void *buffer, uint32_t maxsize, uint32_t* size) {
42+
if (*fd == -1) {
43+
return WHD_BADARG;
44+
}
45+
*size = read(*fd, buffer, maxsize);
46+
return WHD_SUCCESS;
47+
}
48+
49+
int wiced_filesystem_file_close(int* fd) {
50+
if (*fd == -1) {
51+
return WHD_BADARG;
52+
}
53+
close(*fd);
54+
return WHD_SUCCESS;
1355
}

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/resources/firmware/COMPONENT_4343W/4343WA1_bin.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25464,6 +25464,8 @@ const unsigned char wifi_firmware_image_data[420690] =
2546425464
49, 45, 102, 55, 49, 50, 56, 53, 49, 55, 0, 254, 0, 68, 86, 73, 68,
2546525465
32, 48, 49, 45, 53, 50, 100, 50, 48, 57, 102, 55
2546625466
};
25467-
const resource_hnd_t wifi_firmware_image =
25468-
{ RESOURCE_IN_MEMORY, 420690, {.mem = { (const char *)wifi_firmware_image_data }}};
25467+
//const resource_hnd_t wifi_firmware_image =
25468+
//{ RESOURCE_IN_MEMORY, 420690, {.mem = { (const char *)wifi_firmware_image_data }}};
2546925469

25470+
const resource_hnd_t wifi_firmware_image =
25471+
{ RESOURCE_IN_FILESYSTEM, 420690, {.fs = { 0, "/wlan/4343WA1.BIN" }}};

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/resources/resource_imp/whd_resources.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,22 @@ resource_result_t resource_read(const resource_hnd_t *resource, uint32_t offset,
104104
#ifdef USES_RESOURCE_GENERIC_FILESYSTEM
105105
else
106106
{
107-
wiced_file_t file_handle;
108-
uint64_t size64;
109-
uint64_t maxsize64 = maxsize;
110-
if (WICED_SUCCESS !=
111-
wiced_filesystem_file_open (&resource_fs_handle, &file_handle, resource->val.fs.filename,
112-
WICED_FILESYSTEM_OPEN_FOR_READ) )
107+
int file_handle = -1;
108+
if (WHD_SUCCESS !=
109+
wiced_filesystem_file_open (&file_handle, resource->val.fs.filename) )
113110
{
114-
return RESOURCE_FILE_OPEN_FAIL;
111+
return WHD_BADARG;
115112
}
116-
if (WICED_SUCCESS != wiced_filesystem_file_seek (&file_handle, (offset + resource->val.fs.offset), SEEK_SET) )
113+
if (WHD_SUCCESS != wiced_filesystem_file_seek (&file_handle, (offset + resource->val.fs.offset)) )
117114
{
118-
return RESOURCE_FILE_SEEK_FAIL;
115+
wiced_filesystem_file_close (&file_handle);
116+
return WHD_BADARG;
119117
}
120-
if (WICED_SUCCESS != wiced_filesystem_file_read (&file_handle, buffer, maxsize64, &size64) )
118+
if (WHD_SUCCESS != wiced_filesystem_file_read (&file_handle, buffer, *size, &size) )
121119
{
122120
wiced_filesystem_file_close (&file_handle);
123-
return RESOURCE_FILE_READ_FAIL;
121+
return WHD_BADARG;
124122
}
125-
*size = (uint32_t)size64;
126123
wiced_filesystem_file_close (&file_handle);
127124
}
128125
#else

targets/TARGET_STM/TARGET_STM32H7/TARGET_STM32H747xI/TARGET_PORTENTA_H7/COMPONENT_WHD/whd_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define WLAN_POWER_UP_DELAY_MS 250
2121
#define SDIO_ENUMERATION_TIMEOUT_MS 500
2222

23+
#define USES_RESOURCE_GENERIC_FILESYSTEM
2324

2425
#define BSP_LED1 {GPIOK,{.Pin= GPIO_PIN_5 , .Mode = GPIO_MODE_OUTPUT_PP , .Pull = GPIO_NOPULL , .Speed= GPIO_SPEED_FREQ_LOW}}
2526
#define BSP_LED2 {GPIOK,{.Pin= GPIO_PIN_6 , .Mode = GPIO_MODE_OUTPUT_PP , .Pull = GPIO_NOPULL , .Speed= GPIO_SPEED_FREQ_LOW}}

0 commit comments

Comments
 (0)