Re: What is the right way to add PM to esp32c6

2024-11-11 Thread Felipe Moura Oliveira
Hello everyone,

Tiago, actually I am able to compile and run light sleep using nsh
configuration, but it's failing when I am using wifi configuration. I tried
it by myself but I cannot solve it, can you give some help please?
I push a draft to you look it easely:
https://github.com/apache/nuttx/pull/14726

You can config a work example running the following cmd:
./tools/configure.sh esp32c6-devkitc:sleep_test

This config basically is nsh + CONFIG_ESP_AUTO_SLEEP=y and
CONFIG_EXAMPLES_HELLO=y. Auto_sleep is new config done by me,

Please, change hello_main.c with the code below:

/
* apps/examples/hello/hello_main.c
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 

/
* Definitions
/

#define NUM_THREADS 5

/
* Private Data
/

struct thread_info {
int thread_id;
unsigned int sleep_time;
};

/
* Private Functions
/

void *thread_func(void *arg)
{
struct thread_info *tinfo = (struct thread_info *)arg;
volatile uint32_t i = 0;
struct timespec ts_start, ts_end;
time_t elapsed;

// Get the start time
clock_gettime(CLOCK_MONOTONIC, &ts_start);

while (1)
{
i++;
clock_gettime(CLOCK_MONOTONIC, &ts_end);
elapsed = ts_end.tv_sec - ts_start.tv_sec;
printf("Hello, World!! [Thread %d] Iteration: %lu | Elapsed time: %ld
seconds\n",
tinfo->thread_id, i, (long)elapsed);
ts_start = ts_end;
sleep(tinfo->sleep_time);
}

return NULL;
}

/
* Public Functions
/

/
* main
/

int main(int argc, FAR char *argv[])
{
pthread_t threads[NUM_THREADS];
struct thread_info tinfo[NUM_THREADS];
int ret;

unsigned int sleep_times[NUM_THREADS] = {15, 11, 30, 70, 25};

for (int i = 0; i < NUM_THREADS; i++)
{
tinfo[i].thread_id = i + 1;
tinfo[i].sleep_time = sleep_times[i];

ret = pthread_create(&threads[i], NULL, thread_func, &tinfo[i]);
if (ret != 0)
{
printf("Error creating thread %d: %d\n", i + 1, ret);
exit(EXIT_FAILURE);
}
}
int app_ret = 0;
if (app_ret == -1) {
printf("Error executing command\n");
} else {
printf("Application finished with return code: %d\n", app_ret);
}

while (1)
{
printf("Hello, World!! [Main Thread]\n");
sleep(10);
}

return 0;
}



You will see output below:
nsh> hello
Aplicação finalizou com código de retorno: 0
Hello, World!! [Main Thread]
Hello, World!! [Thread 1] Iteração: 1 | Tempo decorrido: 0 segundos
Hello, World!! [Thread 2] It*pmu_*eração: 1 | Tempo decorrido: 0 segundos
Hello, World!! [Thread 3] Iteração: 1 | Tempo decorrido: 0 segundos
Hello, World!! [Thread 4] Iteração: 1 | Tempo decorrido: 0 segundos
Hello, World!! [Thread 5] Iteração: 1 | Tempo decorrido: 0 segundos
*pmu_*Hello, World!! [Main Thread]
Hello, World!! [Thread 2] Iteração: 2 | Tempo decorrido: 11 segundos
Hello, World!! [Thread 1] Iteração: 2 | Tempo decorrido: 16 segundos

I was able to power consumption below 1 mA when mcu is in idle mode, so it
is in light sleep.

Later, making a distclean, running wifi config and adding
CONFIG_ESP_AUTO_SLEEP=y and CONFIG_EXAMPLES_HELLO=y, you will see that the
mcu goes to sleep and not return.

Em seg., 4 de nov. de 2024 às 08:48, Tiago Medicci Serrano <
tiago.medi...@gmail.com> escreveu:

> Hi Felipe, good to hear about your progress here!
>
> These functions are ROM-defined functions. By checking the TRM, you can see
> a read-only flash partition that holds some functions (widely used
> functions, like malloc and internal functions).
>
> ets_get_cpu_frequency
> <
> https://github.com/espressif/esp-hal-3rdparty/blob/1a1545b6ffb54029259ba8691d9ee200bfda2471/components/esp_rom/esp32c6/ld/esp32c6.rom.ld#L32
> >
> is
> one of these internal functions. They are defined directly at the linker
> script.
>
> If I understood correctly, these functions are crashing when it's being
> called, right? If so, can you:
>
>1. Share the crash dump
>2. Use GDB and try to check where/why it fails: it may trying to access
>some prohibited memory region or even trying to call an unregistered
>callback.
>
> Thanks!
>
> Em sex., 1 de nov. de 2024 às 13:41, Felipe Moura Oliveira <
> moura@gmail.com> escreveu:
>
> > Hello everyone,
> >
> > Tiago, I am trying to work with light sleep for now, after it work will
> go
> > ahead with deep sleep. To run in light sleep

Re: [External Mail]RE: [EXT] Re: RPMsg FS on NuttX and Linux

2024-11-11 Thread 汪博文
Hi Andre,

The attachment is the rpmsg_release_tx_buffer patch file.

And thanks for sharing the solution to the rpmsgfs bug in linux 6.6, this is 
very helpful for us.

Kind regards,
Wang Bowen

 Replied Message 
FromAndre Heinemans
Date11/8/2024 21:30
To  汪博文,
dev@nuttx.apache.org
Subject [External Mail]RE: [EXT] Re: RPMsg FS on NuttX and Linux
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给mi...@xiaomi.com进行反馈

Hi Wang Bowen,

Thanks for sending me the updated files.

I think I found the problem with the move/rename. When porting to 6.6.23 I had 
to adapt the assignment of 'struct renamedata rd' since the struct got changed 
in commit abf0857.
Previously I only updated 'rd.old_mnt_userns = &init_user_ns;' to 
'rd.old_mnt_idmap = &nop_mnt_idmap;'. The error disappeared when I added 
'rd.new_mnt_idmap = &nop_mnt_idmap;' as well.
See below our rpmsgfs_rename_handler.

Do you also have the file that contain the rpmsg_release_tx_buffer() function? 
It could not be resolved. I guess rpmsg_core.c.

Kind regards,
Andre Heinemans

static int rpmsgfs_rename_handler(struct rpmsg_device *rpdev,
void *data, int len, void *priv, u32 src)
{
struct rpmsgfs_rename *msg = data;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
struct renamedata rd;
#endif
struct path oldpath, newpath;
struct dentry *newdentry;
char *oldname, *newname;
int ret, oldlen;
oldname = msg->pathname;
oldlen  = (strlen(msg->pathname) + 1 + 0x7) & ~0x7;
newname = msg->pathname + oldlen;
ret = kern_path(oldname, 0, &oldpath);
if (ret < 0)
goto fail;
if (!oldpath.dentry || !oldpath.dentry->d_parent) {
ret = -ENOENT;
goto fail1;
}
newdentry = kern_path_locked(newname, &newpath);
if (IS_ERR(newdentry)) {
ret = PTR_ERR(newdentry);
goto fail1;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
rd.old_mnt_idmap = &nop_mnt_idmap;
rd.new_mnt_idmap = &nop_mnt_idmap;
#else
rd.old_mnt_userns = &init_user_ns;
#endif
rd.old_dir = oldpath.dentry->d_parent->d_inode;
rd.old_dentry = oldpath.dentry;
rd.new_dir = d_inode(newpath.dentry);
rd.new_dentry = newdentry;
rd.delegated_inode = NULL;
rd.flags = 0;
ret = vfs_rename(&rd);
#else
ret = vfs_rename(oldpath.dentry->d_parent->d_inode, oldpath.dentry,
d_inode(newpath.dentry), newdentry, NULL, 0);
#endif
dput(newdentry);
inode_unlock(d_inode(newpath.dentry));
path_put(&newpath);
fail1:
path_put(&oldpath);
fail:
msg->header.result = ret;
return rpmsg_send(rpdev->ept, msg, sizeof(*msg));
}

-Original Message-
From: 汪博文 
Sent: Friday, 8 November 2024 10:11
To: dev@nuttx.apache.org; Andre Heinemans 
Subject: Re: [External Mail]RE: [EXT] Re: RPMsg FS on NuttX and Linux

Caution: This is an external email. Please take care when clicking links
or opening attachments. When in doubt, report the message using the 'Report
this email' button

Hi Andre,

Sorry for late reply.
‍
‍About your questions:
1. Your small fixes in Linux Rpmsg FS is right or not?

‍‍
Yes, your fix is right and we will update our internal version.
2. Any updates in our internal rpmsgfs and rpmsgtty?

Actually, only some minor updates:
‍
- We changed the rpmsg_fs and rpmsg_tty to kernel modules, and I have
attached the new rpmsg_fs.c and rpmsg_tty.c in this email, you can check
them;
-  We also add some kernel version checks in rpmsg_fs and rpmsg_tty to make
them can work with both kernel v5.10 and v5.15 And no other updates in
rpmsg_fs and rpmsg_tty But we are planing to implement the rpmsg_fs client
in linux (linux mount nuttx file system) and also port these rpmsg services to
the linux kernel v6.6.
3. The panic in linux caused by move or rename operation We haven't
encountered this problem before, but we can try this case in v6.6 when we
porting rpmsg services to the new kernel version.

Kind regards,
Wang Bowen

 Replied Message 
From   Andre Heinemans 

Date   11/8/2024 00:33
To dev@nuttx.apache.org,
 Xiang Xiao,
 Bowen
Wang 
Subject[External Mail]RE: [EXT] Re: RPMsg FS on NuttX and Linux
[外部邮件]
此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将
邮件转发给mi...@xiaomi.com进行反馈

Hi Wang Bowen, Xiang Xiao,

When I want to move a file through rpmsgfs from within nuttx on a filesystem
hosted on linux, then I get this linux kernel oops below.
I used the rpmsgfs linux implementation provided on this mail thread but
ported it to 6.6.23.

It looks like every move or rename gives the error. Do you know what could
cause the problem?

Are there maybe any updates of the linux rpmsgfs driver which I could try?

Kind regards,
Andre

[  121.160624] Unable to handle kernel paging request at virtual address
8003848c38dc [  121.168612] Mem abort info:
[  121.171464]   ESR = 0x9605
[  121.175216]   EC = 0x25: DABT (current EL), IL = 32 bits
[  121.180568]   SET = 0, FnV = 0
[  121.183660]   EA = 0, S1PT